Skip to content

Instantly share code, notes, and snippets.

@toomore
Created February 13, 2021 14:22
Show Gist options
  • Save toomore/84852c358d9cec033a447f41ab0aa9fa to your computer and use it in GitHub Desktop.
Save toomore/84852c358d9cec033a447f41ab0aa9fa to your computer and use it in GitHub Desktop.
render the weeks of year
import csv
import arrow
def range_week(year):
fmt = 'YYYY-MM-DD'
span = arrow.Arrow.span_range('week', arrow.get(
'%s-01-01' % year), arrow.get('%s-12-31' % year))
with open('./weeks.csv', 'w+') as files:
csv_writer = csv.writer(files)
csv_writer.writerow(('week', 'start', 'end'))
for start, end in span:
week_no = start.format('W '+fmt).split(' ')[0][:-2]
datas = week_no.split('-')[1:]
datas.append(start.format(fmt))
datas.append(end.format(fmt))
csv_writer.writerow(datas)
if __name__ == '__main__':
range_week(year=2021)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment