-
Notifications
You must be signed in to change notification settings - Fork 0
/
dep_or_agency.py
75 lines (61 loc) · 3.96 KB
/
dep_or_agency.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
# coding=utf-8
# This reads visits from openDataPortal.siteAnalytics.datasetsByOrg.bilingual.csv
import csv, datetime, yaml
def to_html():
en_to_html()
fr_to_html()
def en_to_html():
final_result = open("dep_or_agency_en.txt", "w")
create_intro_en(final_result)
get_rows_en(final_result)
def fr_to_html():
final_result = open("dep_or_agency_fr.txt", "w")
create_intro_fr(final_result)
get_rows_fr(final_result)
def create_intro_en(final_result):
dt = datetime.datetime.today()
today = dt.today()
first = today.replace(day=1)
lastMonth = first - datetime.timedelta(days=1)
intro = """<section><h2 class="mrgn-tp-xl" id="department">Datasets by Department or Agency</h2>
<p>These numbers represent the breakdown of raw datasets on the Open Government Portal by department or agency. These numbers were captured on <time datetime=\"""" + lastMonth.strftime("%Y-%m-%d") +"\">" + lastMonth.strftime("%B %d, %Y") + """.</time>
<a href="#monthly">See how much we have grown since <time datetime="2013-06-18">June 18, 2013</time></a>.</p>
<div class="table-responsive"><table class="table">
<thead><tr><th scope="col">Government of Canada Department or Agency</th>
<th scope="col">Number of datasets</th></tr></thead>\n<tbody>"""
final_result.write(intro)
def create_intro_fr(final_result):
dt = datetime.datetime.today()
today = dt.today()
first = today.replace(day=1)
lastMonth = first - datetime.timedelta(days=1)
months = yaml.load(open('months.yml', 'r'))
french_month = months.get('long_form').get(lastMonth.strftime("%B"))
french_date = lastMonth.strftime("%d ") + french_month + lastMonth.strftime(", %Y")
intro = """<section><h2 class="mrgn-tp-xl" id="department">Jeux de données par ministère ou organisme</h2>
<p>Le tableau ci-dessous présente des jeux de données brutes tirés du portail du gouvernement ouvert en fonction des ministères et organismes. Ces données ont été recueillies le <span class="nowrap"><time datetime=\"""" + lastMonth.strftime("%Y-%m-%d") +"\">" + french_date.encode('utf8') + """.</time></span>
Vous pourrez <a href="#monthly">constater la croissance que nous avons connue depuis le <time datetime="2013-06-18">18 juin 2013</time></a>.</p>
<div class="table-responsive"><table class="table">
<thead><tr><th scope="col">Ministère ou organisme du gouvernement du Canada</th>
<th scope="col">Nombre total de jeux de données</th></tr></thead>\n"""
final_result.write(intro)
def get_rows_en(final_result):
with open("openDataPortal.siteAnalytics.datasetsByOrg.bilingual.csv", 'rb') as f:
monthly_usage = csv.reader(f)
next(monthly_usage, None)
total = 0
for row in monthly_usage:
final_result.write("<tr><th scope=\"row\"><a href=\"" + row[2] + "\">" + row[0] + "</a></th><td class=\"text-center\">" + '{:,}'.format(int(row[4])) + "</td></tr>\n")
total += int(row[4])
final_result.write("<tfoot><tr><th class=\"text-left\" scope=\"row\">Total</th><td class=\"text-center\">" + '{:,}'.format(int(total)) + "</td></tr></tfoot>")
final_result.write("</tbody></table></div><div class=\"clearfix\"> </div></section>")
def get_rows_fr(final_result):
with open("openDataPortal.siteAnalytics.datasetsByOrg.bilingual.csv", 'rb') as f:
monthly_usage = csv.reader(f)
next(monthly_usage, None)
total = 0
for row in monthly_usage:
final_result.write("<tr><th scope=\"row\"><a href=\"" + row[3] + "\">" + row[1] + "</a></th><td class=\"text-center\">" + '{:,}'.format(int(row[4])).replace(',', ' ') + "</td></tr>\n")
total += int(row[4])
final_result.write("<tfoot><tr><th class=\"text-left\" scope=\"row\">Total</th><td class=\"text-center\">" + '{:,}'.format(total).replace(',', ' ') + "</td></tr></tfoot>")
final_result.write("</tbody></table></div><div class=\"clearfix\"> </div></section>")