date_render.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:time_extract 作者: blackbirdco 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号