Python sort by date
9 Python code examples are found related to "
sort by date".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: ffi.py From eleanor with MIT License | 6 votes |
def sort_by_date(self): """Sorts FITS files by start date of observation.""" dates, time, index = [], [], [] for f in self.local_paths: hdu = fits.open(f) hdr = hdu[1].header dates.append(hdr['DATE-OBS']) if 'ffiindex' in hdu[0].header: index.append(hdu[0].header['ffiindex']) if len(index) == len(dates): dates, index, fns = np.sort(np.array([dates, index, self.local_paths])) self.ffiindex = index.astype(int) else: dates, fns = np.sort(np.array([dates, self.local_paths])) self.local_paths = fns self.dates = dates return
Example 2
Source File: roll_indexes.py From watchmen with Apache License 2.0 | 6 votes |
def sort_indices_by_creation_date(es_indices): ''' returns an ordered dictionary of index names ordered by their creation date with the oldest first ''' es_name_creation = dict() # put the index name and creation date into a dictionary for es_index in es_indices: idx_creation_date = es_indices[es_index]['settings']['index']['creation_date'] idx_provided_name = es_indices[es_index]['settings']['index']['provided_name'] es_name_creation[idx_provided_name] = idx_creation_date # convert the dictionary into an ordered dictionary (by creation date) es_sorted_indices = OrderedDict( sorted( es_name_creation.iteritems(), key=lambda (k, v): (v, k), reverse=True ) ) return es_sorted_indices
Example 3
Source File: auxil.py From pyroSAR with MIT License | 6 votes |
def sortByDate(self, files, datetype='start'): """ sort a list of OSV files by a specific date type Parameters ---------- files: list some OSV files datetype: {'publish', 'start', 'stop'} one of three possible date types contained in the OSV filename Returns ------- list the input OSV files sorted by the defined date """ return sorted(files, key=lambda x: self.date(x, datetype))
Example 4
Source File: utils.py From sncli with MIT License | 5 votes |
def sort_by_modify_date_pinned(a): if note_pinned(a.note): return 100.0 * float(a.note.get('modificationDate', 0)) else: return float(a.note.get('modificationDate', 0))
Example 5
Source File: dynamo_connection.py From aws-syndicate with Apache License 2.0 | 5 votes |
def put_with_sort_by_date(self, resources_to_put, table_name): """ Saves billing records by date in ascending order :type resources_to_put: list :param resources_to_put: list with billing records :type table_name: str :param table_name: DynamoDB table name """ for each in sorted(resources_to_put, key=itemgetter('d')): self.put_item(table_name, each)
Example 6
Source File: XMLExtract.py From ScraXBRL with MIT License | 5 votes |
def sort_by_date(self, date_list): """Sort dates in descending order.""" master = OrderedDict() s = date_list s.sort(key=lambda tup: tup[0], reverse=True) master['val_list'] = [] master['val_by_date'] = OrderedDict() for i in s: master['val_list'].append((i[1], i[4])) try: master['val_by_date'][i[0]] except KeyError: master['val_by_date'][i[0]] = [] master['val_by_date'][i[0]].append((i[1], i[2], i[3], i[4])) tmp_master = [] tmp_dates = [] for i in master['val_by_date'].keys(): if master['val_by_date'][i] not in tmp_master: tmp_master.append(master['val_by_date'][i]) tmp_dates.append(i) master['val_by_date'] = OrderedDict() for i in range(len(tmp_dates)): master['val_by_date'][tmp_dates[i]] = tmp_master[i] master['val_list'] = list(set(master['val_list'])) return master
Example 7
Source File: output.py From anki-search-inside-add-card with GNU Affero General Public License v3.0 | 5 votes |
def sortByDate(self, mode): """ Rerenders the last search results, but sorted by creation date. """ if self.lastResults is None: return stamp = utility.misc.get_milisec_stamp() self.latest = stamp sortedByDate = list(sorted(self.lastResults, key=lambda x: int(x.id))) if mode == "desc": sortedByDate = list(reversed(sortedByDate)) self.print_search_results(sortedByDate, stamp)
Example 8
Source File: xlsx_writer.py From Learning-Python-for-Forensics-Second-Edition with MIT License | 5 votes |
def sort_by_date(data): """ The sort_by_date function sorts the lists by their datetime object :param data: the list of lists containing parsed UA data :return: the sorted date list of lists """ # Supply the reverse option to sort by descending order return [x[0:6:4] for x in sorted(data, key=itemgetter(4), reverse=True)]
Example 9
Source File: googlemaps.py From googlemaps-scraper with GNU General Public License v3.0 | 5 votes |
def sort_by_date(self, url): self.driver.get(url) wait = WebDriverWait(self.driver, MAX_WAIT) # open dropdown menu clicked = False tries = 0 while not clicked and tries < MAX_RETRY: try: if not self.debug: menu_bt = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.cYrDcjyGO77__container'))) else: menu_bt = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@data-value=\'Sort\']'))) menu_bt.click() clicked = True time.sleep(3) except Exception as e: tries += 1 self.logger.warn('Failed to click recent button') # failed to open the dropdown if tries == MAX_RETRY: return -1 # second element of the list: most recent recent_rating_bt = self.driver.find_elements_by_xpath('//li[@role=\'menuitemradio\']')[1] recent_rating_bt.click() # wait to load review (ajax call) time.sleep(5) return 0