-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_website.py
89 lines (75 loc) · 2.32 KB
/
generate_website.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
import os.path
from datetime import datetime
import pandas as pd
import jinja2
import comsoc
import spsoc
import itsoc
import vtsoc
from constants import COL_DEADLINE, COL_TOPIC, COL_JOURNAL, COL_PUB_DATE
FORMATTER_DATE = lambda x: datetime.strftime(x, "%B %d, %Y")
FORMATTER_UNESCAPE = lambda x: x.replace(">", ">").replace("<", "<")
SOCIETIES = [
{
"name": "Communications Society",
"id": "comsoc",
"url": "https://www.comsoc.org/",
"module": comsoc,
},
{
"name": "Signal Processing Society",
"id": "spsoc",
"url": "https://signalprocessingsociety.org/",
"module": spsoc,
},
{
"name": "Information Theory Society",
"id": "itsoc",
"url": "https://www.itsoc.org/",
"module": itsoc,
},
{
"name": "Vehicular Technology Society",
"id": "vtsoc",
"url": "https://vtsociety.org/",
"module": vtsoc,
},
]
def clean_dataframe(data):
deadlines = pd.to_datetime(data[COL_DEADLINE], format="mixed", errors="coerce")
data[COL_DEADLINE] = deadlines
data = data.dropna()
data = data[data[COL_DEADLINE] >= datetime.today()]
return data
def generate_society_table(module, **kwargs):
data = module.get_all_cfp()
print(len(data))
data = clean_dataframe(data)
print(len(data))
data = data.sort_values(COL_DEADLINE)
data = data[[COL_TOPIC, COL_DEADLINE, COL_JOURNAL, COL_PUB_DATE]]
if data.empty:
return "No open call for papers"
html_table = data.to_html(
index=False,
border=False,
justify="unset",
escape=False,
formatters={COL_DEADLINE: FORMATTER_DATE},
)
return html_table
def main():
for soc_info in SOCIETIES:
print("Working on society: {name}".format(**soc_info))
_table = generate_society_table(**soc_info)
soc_info["table"] = _table
env = jinja2.Environment(loader=jinja2.FileSystemLoader("templates"))
template = env.get_template("index.html")
timestamp = datetime.now().strftime("%B %d, %Y")
content = template.render(societies=SOCIETIES, timestamp=timestamp)
out_path = os.path.join("public", "index.html")
with open(out_path, "w") as html_file:
html_file.write(content)
# return data
if __name__ == "__main__":
data = main()