def to_YNoteMarkdown(self): # 转化为有道云笔记Markdown格式. begin_date = datetime_utils.from_iso8601(self._begin) end_date = datetime_utils.from_iso8601(self._end) begin_time = begin_date.strftime("%H:%M") end_time = end_date.strftime("%H:%M") time_str = u'<font color=gray>%s - %s</font><br>' % (begin_time, end_time) activity_str_format_1 = u'%s<br>' activity_str_format_2 = u'[%s](%s)<br>' activity_str = activity_str_format_1 % (self._description) matched = False for key in trello_dict.keys(): if self._description.find(key) >= 0: activity_str = activity_str_format_2 % (self._description, trello_dict[key]) matched = True break if not matched: print ' u"%s": "",' % (self._description) return (u'%s\n%s\n' % (time_str, activity_str)).encode("utf-8")
def to_text(self): # to text as YouNote spec. begin_date = datetime_utils.from_iso8601(self._begin) end_date = datetime_utils.from_iso8601(self._end) begin_time = begin_date.strftime("%H:%M") end_time = end_date.strftime("%H:%M") return (u'%s - %s\n%s\n' % (begin_time, end_time, self._description)).encode("utf-8")
def __str__(self): begin_date = datetime_utils.from_iso8601(self._begin) end_date = datetime_utils.from_iso8601(self._end) cur_date = begin_date.strftime("%Y/%m/%d") begin_time = begin_date.strftime("%H:%M") end_time = end_date.strftime("%H:%M") return u'%s [%s - %s]\n%s' % (cur_date, begin_time, end_time, self._description)
def to_markdown(self): begin_date = datetime_utils.from_iso8601(self._begin) end_date = datetime_utils.from_iso8601(self._end) cur_date = begin_date.strftime("%Y/%m/%d") begin_time = begin_date.strftime("%H:%M") end_time = end_date.strftime("%H:%M") return (u'%s [%s - %s]\n**\\%s**\n---\n' % (cur_date, begin_time, end_time, self._description)).encode("utf-8")
def to_trello(self): begin_date = datetime_utils.from_iso8601(self._begin) end_date = datetime_utils.from_iso8601(self._end) cur_date = begin_date.strftime("%Y/%m/%d") begin_time = begin_date.strftime("%H:%M") end_time = end_date.strftime("%H:%M") url = None for key in trello_dict.keys(): if self._description.find(key) >= 0: url = trello_dict[key] break return (u'%s [%s - %s]\n%s\n' % (cur_date, begin_time, end_time, self.trans_url(url))).encode("utf-8")
def test_datetime(self): dt_str = "2020-03-30T11:59:20.254Z" dt = datetime_utils.from_iso8601(dt_str) print dt from dateutil import tz tz_local = tz.tzlocal() dt2 = dt.astimezone(tz_local) print dt2 pass
def test_parser(self): day = "2020-03-31T00:00:00+08:00" local_dt = datetime_utils.from_iso8601(day) print local_dt.__class__ print "1-local datetime: " + local_dt.isoformat() utc_dt = datetime_utils.to_utc(local_dt) print "2-utc datetime: " + utc_dt.isoformat() print utc_dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ") dt = datetime_utils.to_local(utc_dt) print "3-new datetime: " + dt.isoformat() pass
def from_json(e): uuid = e[u'uuid'] created_at = e[u'created_at'] updated_at = e[u'updated_at'] description = e[u'description'] started_at = e[u'started_at'] ended_at = e[u'ended_at'] local_started_at = e[u'local_started_at'] local_ended_at = e[u'local_ended_at'] length = e[u'length'] abandoned = e[u'abandoned'] manual = e[u'manual'] return Pomo(uuid, datetime_utils.from_iso8601(created_at), datetime_utils.from_iso8601(updated_at), description, datetime_utils.from_iso8601(started_at), datetime_utils.from_iso8601(ended_at), datetime_utils.from_iso8601(local_started_at), datetime_utils.from_iso8601(local_ended_at), length, abandoned, manual) pass
def started_time_key(self): return datetime_utils.from_iso8601(self._begin)