improvements based on a run-through in COM597G
[harrypotter-wikipedia-cdsw] / hpwp-trend.py
index 939406e..aaa2b70 100644 (file)
@@ -1,10 +1,10 @@
 from csv import DictReader
 
 # read in the input file and count by day
-input_file = open("hp_wiki.csv", 'r')
+input_file = open("hp_wiki.tsv", 'r', encoding="utf-8")
 
 edits_by_day = {}
-for row in DictReader(input_file):
+for row in DictReader(input_file, delimiter="\t"):
     day_string = row['timestamp'][0:10]
 
     if day_string in edits_by_day:
@@ -15,13 +15,13 @@ for row in DictReader(input_file):
 input_file.close()
 
 # output the counts by day
-output_file = open("hp_edits_by_day.csv", "w")
+output_file = open("hp_edits_by_day.tsv", "w", encoding='utf-8')
 
 # write a header
-output_file.write("date,edits\n")
+output_file.write("date\tedits\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")
+for day_string in edits_by_day.keys():
+    output_file.write("\t".join([day_string, str(edits_by_day[day_string])]) + "\n")
 
 output_file.close()

Benjamin Mako Hill || Want to submit a patch?