本文整理汇总了Python中calendar.Calendar.yeardatescalendar方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.yeardatescalendar方法的具体用法?Python Calendar.yeardatescalendar怎么用?Python Calendar.yeardatescalendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.yeardatescalendar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import yeardatescalendar [as 别名]
import os.path
import csv
if not os.path.exists('data'):
os.mkdir('data')
generationDemandWriter = csv.DictWriter(open('generation_demand_full.csv', 'w'), ['timestamp', 'demand', 'forecast', 'programmed', 'nuclear', 'coal', 'fuel_gas', 'combined_cycle', 'hydroelectric', 'solar', 'eolic', 'autoproduction', 'balearic_link', 'international_exchange'])
generationDemandWriter.writeheader()
all_data = {}
now = datetime.now()
calendar = Calendar()
for year in range(2007, now.year + 1):
for date in filter(lambda x: x.year == year, chain(*chain(*calendar.yeardatescalendar(year, 12)[0]))):
if datetime(date.year, date.month, date.day) > now:
break
d = date.strftime('%Y-%m-%d')
filename = 'data/generation_demand_%s.json' % d
if not os.path.exists(filename):
data = r.generation_demand(d)
json.dump(data, open(filename, 'w'))
else:
data = json.load(open(filename, 'r'))
for datum in data:
if datum['timestamp'] not in all_data:
all_data[datum['timestamp']] = datum
filename = 'data/forecast_programmed_%s.json' % d