X-Git-Url: https://projects.mako.cc/source/harrypotter-wikipedia-cdsw/blobdiff_plain/fcf662671099db62bdfd5607f9fe51c31747a999..c4b1a145625537c7ac8131b133e6d85c587ff203:/hpwp-trend.py diff --git a/hpwp-trend.py b/hpwp-trend.py new file mode 100644 index 0000000..939406e --- /dev/null +++ b/hpwp-trend.py @@ -0,0 +1,27 @@ +from csv import DictReader + +# read in the input file and count by day +input_file = open("hp_wiki.csv", 'r') + +edits_by_day = {} +for row in DictReader(input_file): + day_string = row['timestamp'][0:10] + + if day_string in edits_by_day: + edits_by_day[day_string] = edits_by_day[day_string] + 1 + else: + edits_by_day[day_string] = 1 + +input_file.close() + +# output the counts by day +output_file = open("hp_edits_by_day.csv", "w") + +# write a header +output_file.write("date,edits\n") + +# iterate through every day and print out data into the file +for day_string in edits_by_day: + output_file.write(",".join([day_string, str(edits_by_day[day_string])]) + "\n") + +output_file.close()