本文整理匯總了Python中source.Source.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Source.get方法的具體用法?Python Source.get怎麽用?Python Source.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類source.Source
的用法示例。
在下文中一共展示了Source.get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from source import Source [as 別名]
# 或者: from source.Source import get [as 別名]
def run(config_path, days = 1):
logging.info('Started')
with open(config_path, 'r') as config_file:
import json
from datetime import datetime, timedelta
from notifier import Notifier
from source import Source
from seminarparser import Parser
config = json.load(config_file)
source = Source.get(config['source']['type'], config['source'])
parser = Parser.get(config['parser']['type'], config['parser'])
notifier = Notifier.get(config['notifier']['type'], config['notifier'])
now = datetime.now().date()
tomorrow = now + timedelta(days = days)
logging.info('Initialized')
src = source.get(tomorrow)
logging.info('Getting source is complete')
headers = parser.find_headers(src)
logging.info('%d headers found' % len(headers))
defaults = config['defaults']
seminars = [parser.parse_seminar(header, defaults) for header in headers]
logging.info('%d seminars found' % len(headers))
for seminar in [(seminar.title, datetime.combine(seminar.date, seminar.time).isoformat(' '), seminar.place, '/'.join(seminar.contents)) for seminar in seminars]:
logging.debug('Seminar found: %s, %s, %s, %s' % seminar)
tomorrow_seminars = [seminar for seminar in seminars if seminar.date == tomorrow]
logging.info('%d seminars found on %s' % (len(tomorrow_seminars), tomorrow))
for seminar in tomorrow_seminars:
notifier.notify(seminar)
logging.info('Notify sent: %s, %s, %s' % (seminar.title, seminar.date, seminar.time))
logging.info('Done')