def to_i(self, arg):
for subtree in self.tree.subtrees():
if subtree.label() == 'metadata':
self.metadata_text(subtree)
if subtree.label()[:-4] == self.metadata_name:
self.dictionary['metadata'] = self.metadata_name
if subtree.label() == 'todayItem':
self.today(subtree)
if subtree.label() == 'tomorrowItem':
self.tommorow(subtree)
if subtree.label() == 'yesterdayItem':
self.yesterday(subtree)
if subtree.label() == 'middayItem':
self.noon(subtree)
if subtree.label() == 'midnightItem':
self.midnight(subtree)
if 'DayOfWeekItem' in subtree.label():
self.nth_day_of_week(subtree)
if subtree.label() == 'dayValueItem':
self.dictionary['day'] = ' '.join(subtree.leaves())
if subtree.label() == 'monthValueItem':
self.dictionary['month'] = ' '.join(subtree.leaves())
if (('day' in self.dictionary) or ('month' in self.dictionary)):
dateStr = ''
if ('day' in self.dictionary):
dateStr += self.dictionary['day'] + ' '
if ('month' in self.dictionary):
dateStr += self.dictionary['month'] + ' '
dateParser = dateparser.parse(dateStr)
dateTimestamp = mktime(dateParser.timetuple())
self.dictionary['timestamp'] = dateTimestamp
if ('hours' in self.dictionary):
self.dictionary['timestamp'] += int(self.dictionary['hours']) * 3600
return self.dictionary
python类today()的实例源码
def __init__(self, experiment_names, *items, append_date_to_name=True,
root_directory=FOLDER_NAMINGS['EXP_ROOT'],
timer=None, do_print=True, collect_data=True, default_overwrite=False):
"""
Initialize a saver to collect data. (Intended to be used together with OnlinePlotStream.)
:param experiment_names: string or list of strings which represent the name of the folder (and sub-folders)
experiment oand
:param items: a list of (from pairs to at most) 5-tuples that represent the things you want to save.
The first arg of each tuple should be a string that will be the key of the save_dict.
Then there can be either a callable with signature (step) -> None
Should pass the various args in ths order:
fetches: tensor or list of tensors to compute;
feeds (optional): to be passed to tf.Session.run. Can be a
callable with signature (step) -> feed_dict
options (optional): to be passed to tf.Session.run
run_metadata (optional): to be passed to tf.Session.run
:param timer: optional timer object. If None creates a new one. If false does not register time.
If None or Timer it adds to the save_dict an entry time that record elapsed_time.
The time required to perform data collection and saving are not counted, since typically
the aim is to record the true algorithm execution time!
:param root_directory: string, name of root directory (default ~HOME/Experiments)
:param do_print: (optional, default True) will print by default `save_dict` each time method `save` is executed
:param collect_data: (optional, default True) will save by default `save_dict` each time
method `save` is executed
"""
experiment_names = as_list(experiment_names)
if append_date_to_name:
from datetime import datetime
experiment_names += [datetime.today().strftime('%d-%m-%y__%Hh%Mm')]
self.experiment_names = list(experiment_names)
if not os.path.isabs(experiment_names[0]):
self.directory = join_paths(root_directory) # otherwise assume no use of root_directory
if collect_data:
check_or_create_dir(root_directory, notebook_mode=False)
else: self.directory = ''
for name in self.experiment_names:
self.directory = join_paths(self.directory, name)
check_or_create_dir(self.directory, notebook_mode=False, create=collect_data)
self.do_print = do_print
self.collect_data = collect_data
self.default_overwrite = default_overwrite
assert isinstance(timer, Timer) or timer is None or timer is False, 'timer param not good...'
if timer is None:
timer = Timer()
self.timer = timer
self.clear_items()
self.add_items(*items)
# noinspection PyAttributeOutsideInit
def date_search(self, start, end=None, compfilter="VEVENT"):
"""
Search events by date in the calendar. Recurring events are
expanded if they are occuring during the specified time frame
and if an end timestamp is given.
Parameters:
* start = datetime.today().
* end = same as above.
* compfilter = defaults to events only. Set to None to fetch all
calendar components.
Returns:
* [CalendarObjectResource(), ...]
"""
matches = []
# build the request
# Some servers will raise an error if we send the expand flag
# but don't set any end-date - expand doesn't make much sense
# if we have one recurring event describing an indefinite
# series of events. Hence, if the end date is not set, we
# skip asking for expanded events.
if end:
data = cdav.CalendarData() + cdav.Expand(start, end)
else:
data = cdav.CalendarData()
prop = dav.Prop() + data
query = cdav.TimeRange(start, end)
if compfilter:
query = cdav.CompFilter(compfilter) + query
vcalendar = cdav.CompFilter("VCALENDAR") + query
filter = cdav.Filter() + vcalendar
root = cdav.CalendarQuery() + [prop, filter]
response = self._query(root, 1, 'report')
results = self._handle_prop_response(
response=response, props=[cdav.CalendarData()])
for r in results:
matches.append(
Event(self.client, url=self.url.join(r),
data=results[r][cdav.CalendarData.tag], parent=self))
return matches