-
Notifications
You must be signed in to change notification settings - Fork 0
/
monthly_downloads.py
105 lines (82 loc) · 4.67 KB
/
monthly_downloads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# coding=utf-8
# This reads downloads from openDataPortal.siteAnalytics.totalMonthlyUsage.bilingual.csv
import csv
def to_html():
en_to_html()
fr_to_html()
def en_to_html():
final_result = open("monthly_downloads_en.txt", "w")
create_intro_en(final_result)
format_dates_en(final_result)
get_downloads_en(final_result)
def fr_to_html():
final_result = open("monthly_downloads_fr.txt", "w")
create_intro_fr(final_result)
format_dates_fr(final_result)
get_downloads_fr(final_result)
def get_downloads_en(final_result):
final_result_string = []
with open("openDataPortal.siteAnalytics.totalMonthlyUsage.bilingual.csv", 'rb') as f:
monthly_usage = csv.reader(f)
next(monthly_usage, None)
final_result_string = []
final_result.write("</tr></thead><tbody><tr>\n")
final_result.write("<th scope=\"row\" data-flot='{\"color\":\"#2572B4\"}'>Downloads</th>\n")
for row in monthly_usage:
final_result_string.append("<td class=\"text-left\">" + '{:,}'.format(int(row[3])) + "</td>\n")
final_result_string.reverse()
del final_result_string[0:len(final_result_string) - 12]
for line in final_result_string:
final_result.write(line)
final_result.write("</tr></tbody></table><div class=\"clearfix\"> </div></section>\n")
def get_downloads_fr(final_result):
final_result_string = []
with open("openDataPortal.siteAnalytics.totalMonthlyUsage.bilingual.csv", 'rb') as f:
monthly_usage = csv.reader(f)
next(monthly_usage, None)
final_result_string = []
final_result.write("</tr></thead><tbody><tr>\n")
final_result.write("<th scope=\"row\" data-flot='{\"color\":\"#2572B4\"}'>Téléchargements</th>\n")
for row in monthly_usage:
final_result_string.append("<td class=\"text-left\">" + '{:,}'.format(int(row[3])).replace(',', ' ') + "</td>\n")
final_result_string.reverse()
del final_result_string[0:len(final_result_string) - 12]
for line in final_result_string:
final_result.write(line)
final_result.write("</tr></tbody></table><div class=\"clearfix\"> </div></section>\n")
def create_intro_en(final_result):
intro = """<section><h2 class="mrgn-tp-xl" id="downloads">Number of Downloads</h2>
<p>These numbers summarize the number of downloads on the Open Government Portal. A download represents the number of times a user has clicked to download a resource for a particular dataset.</p>
<table class="wb-charts table" data-flot='{"legend": {"show":true} }'><caption>Number of Downloads</caption>
<thead><tr><th> </th>\n"""
final_result.write(intro)
def create_intro_fr(final_result):
intro = """<section><h2 class="mrgn-tp-xl" id="downloads">Nombre de téléchargements</h2>
<p>Voici un graphique représentant le nombre de téléchargements à partir du portail du gouvernement ouvert. Un téléchargement représente le nombre de fois qu'un utilisateur a cliqué pour télécharger une ressource à partir d'un jeu de données en particulier.</p>
<table class="wb-charts table" data-flot='{"legend": {"show":true} }'><caption>Nombre de téléchargements</caption>
<thead><tr><th> </th>\n"""
final_result.write(intro)
def format_dates_en(final_result):
MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
final_result_string = []
with open("openDataPortal.siteAnalytics.totalMonthlyUsage.bilingual.csv", 'rb') as f:
monthly_usage = csv.reader(f)
next(monthly_usage, None)
for row in monthly_usage:
final_result_string.append("<th scope=\"col\"><time datetime=" + row[0] + "-" + row[1] + ">" + str(MONTHS[int(row[1])-1]) + "-" + row[0] + "</time></th>\n")
final_result_string.reverse()
del final_result_string[0:len(final_result_string) - 12]
for line in final_result_string:
final_result.write(line)
def format_dates_fr(final_result):
MONTHS = ["janv.", "févr.", "mars", "avril", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."]
final_result_string = []
with open("openDataPortal.siteAnalytics.totalMonthlyUsage.bilingual.csv", 'rb') as f:
monthly_usage = csv.reader(f)
next(monthly_usage, None)
for row in monthly_usage:
final_result_string.append("<th scope=\"col\"><time datetime=" + row[0] + "-" + row[1] + ">" + str(MONTHS[int(row[1])-1]) + " -" + row[0] + "</time></th>\n")
final_result_string.reverse()
del final_result_string[0:len(final_result_string) - 12]
for line in final_result_string:
final_result.write(line)