-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderindex.py
141 lines (112 loc) · 4.21 KB
/
renderindex.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import pandas as pd
def extractor(filename):
source = pd.read_csv(filename)
sort_source = source.sort_values("Date", ascending=False)
num_rows, _ = sort_source.shape
data = []
for index, row in sort_source.iterrows():
data.append([row['Link'], row['Title'], row['Date'], row['Author'], row['Description']])
return data
def html_generator(data):
HTML = '''<!DOCTYPE HTML>
<!--
Binary by TEMPLATED
templated.co @templatedco
Released for free under the Creative Commons Attribution 3.0 license (templated.co/license)
-->
<html>
<head>
<title>Opening Data</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="assets/css/main.css" />
<!-- <link rel="icon" href="./assets/images/icon.png" /> favicon goes here -->
</head>
<body>
<!-- Header -->
<header id="header" style="background-color: rgb(252,252,252);">
<a href="index.html" class="logo" style="color: #1c1c1c;"><strong>Opening Data</strong> - Making Open Data Accessible</a>
</header>
<!-- Banner -->
<section id="banner" style="background-color: rgb(252,252,252);">
<div class="inner">
<h1 style="color: #1c1c1c;">Opening Data</h1>
<ul class="actions" style="color: #1c1c1c;">
<li><a href="about.html" class="button alt scrolly big" style="color: #1c1c1c;text-decoration:underline">About</a></li>
<li><a href="https://openingdata.github.io/single-issuer-districts/" class="button alt scrolly big" style="color: #1c1c1c;text-decoration:underline">Most Recent Blog</a></li>
<li><a href="community_guidelines.html" class="button alt scrolly big" style="color: #1c1c1c;text-decoration:underline">Community Guidelines</a></li>
</ul>
</div>
</section>
'''
template_1 = '''
<div class="content" style="background-color: #1c1c1c; color: #fcfcfc;">
<div class="inner">
<header>
<h2><a href="{}" style="color: #fcfcfc;">{}</a></h2>
<p class="info" style="border-color: rgba(255, 255, 255, 0.5); color: rgba(255, 255, 255, 0.5);">{}<a href="#" style="color:#fff"> {}</a></p>
</header>
<p style="color: #fcfcfc;">{}</p>
</div>
</div>
'''
template_2 = '''
<div class="content" style="background-color: #fcfcfc; color=rgba(255, 255, 255, 0.75);">
<div class="inner">
<header>
<h2><a href="{}" style="color: #1c1c1c;">{}</a></h2>
<p class="info" style="border-color: #1c1c1c; color: #1c1c1c;">{}<a href="#" style="color: #1c1c1c;"> {}</a></p>
</header>
<p style="color:#1c1c1c;">{}</p>
</div>
</div>
'''
switch = False
for i in range(0, len(data), 2):
if i + 1 < len(data):
HTML += '<article id="one" class="post style1">'
d1 = data[i]
d2 = data[i+1]
odate1 = str(d1[2])
odate2 = str(d2[2])
d1date = odate1[4:6]+'/'+odate1[6:]+'/'+odate1[:4]
d2date = odate2[4:6]+'/'+odate2[6:]+'/'+odate2[:4]
side_1 = template_1.format(d1[0], d1[1], d1date, d1[3], d1[4] )
side_2 = template_2.format(d2[0], d2[1], d2date, d2[3], d2[4] )
if switch:
HTML += side_2
HTML+= side_1
else:
HTML+= side_1
HTML += side_2
HTML += '</article>'
else:
HTML += '<article id="one" class="post style1">'
d1 = data[i]
odate1 = str(d1[2])
d1date = odate1[4:6]+'/'+odate1[6:]+'/'+odate1[:4]
side_1 = template_1.format(d1[0], d1[1], d1date, d1[3], d1[4] )
side_2 = template_2.format('#', 'At the end', 'NA/Na/Na', 'NA', 'Please contribute a story!')
if switch:
HTML += side_2
HTML+= side_1
else:
HTML+= side_1
HTML += side_2
HTML += '</article>'
switch = not switch
HTML += '''
<footer id="footer">
<div class="copyright">
Original Design: <a href="https://templated.co">TEMPLATED</a>, modified by OpeningData
</div>
</footer>
</body>
</html>'''
return HTML
def main():
data = extractor("stories.csv")
html = html_generator(data)
with open('index.html', 'w') as fh:
fh.write(html)
main()