Created
February 13, 2021 14:22
-
-
Save toomore/84852c358d9cec033a447f41ab0aa9fa to your computer and use it in GitHub Desktop.
render the weeks of year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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