-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneralists.py
290 lines (259 loc) · 8.77 KB
/
generalists.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
"""
Build different lektor files with lists of contributions.
The different files account for lists of posters, talks and other oral
contributions. Each list is composed of different theme blocks, so
contributions are grouped into the different themes. Each item in
the list is a link to its own record in the ADASS program.
"""
import argparse
import logging
import os
import psycopg2
from pathlib import Path
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
DEF_BASE = "/Users/jer/git/adassweb/website/content"
program_url = "https://schedule.adass2020.es/adass2020/talk"
folders = ["posters", "talks", "invited-talks", "bofs", "demos", "tutorials"]
themes = {
"1": "Science Platforms and Data Lakes",
"2": "Cloud Computing at Different Scales",
"3": "Cross-Discipline Projects",
"4": "Multi-Messenger Astronomy",
"5": "Machine Learning, Statistics, and Algorithms",
"6": "Time-Domain Ecosystem",
"7": "Citizen Science Projects in Astronomy",
"8": "Data Processing Pipelines and Science-Ready Data",
"9": "Data Interoperability",
"10": "Open Source Software and Community Development in Astronomy",
"11": "Other",
}
template = """
_model: page
---
title:
---
description:
---
_template: page-md.html
---
body:
"""
def add_icons(pdf, video):
icons = "- "
if pdf:
icons += f"<a href='{pdf}'>📑</a>"
if video:
icons += f"<a href='{video}'>🎦</a>"
return icons
def make_folder_structure(base):
for item in folders:
fold = Path(item)
content = template
item = item.replace("-", " ")
content = content.replace("title:", f"title: {item.capitalize()}")
content = content.replace("description:", f"description: {item.capitalize()}")
if item == "bofs":
content = content.replace("Bofs", "BOFs")
Path.mkdir(base / fold, parents=True, exist_ok=True)
fn = open(base / fold / "contents.lr", "w")
fn.write(content)
fn.close()
log.info(" making folders successful")
def fill_posters(base):
fold = Path(folders[0])
contents = ""
contents += """
#### NOTE
**There are no specific posters sessions scheduled.**
Instead conference participants will be allowed to download the PDF poster files from this list.
They could also download optional complementary self-recorded lightning talks as MP4 video files.
Access authentication info will be delivered in Discord, where participants could also interact
with posters authors individually or within the #posters channel.
"""
for number, label in themes.items():
bag = listings[number]["posters"]
contents += f"\n**{label.upper()}**\n\n"
for pack in bag:
title, abstract, code, author, pdf, video = pack
contents += f"{add_icons(pdf, video)} <a href='{program_url}/{code}' target='_schedule'>{title}</a>, {author}\n"
fn = open(base / fold / "contents.lr", "a")
fn.write(contents)
fn.close()
def fill_talks(base):
fold = Path(folders[1])
contents = ""
for number, label in themes.items():
bag = listings[number]["talks"]["contributed"]
contents += f"\n**{label.upper()}**\n\n"
for pack in bag:
title, abstract, code, author, pdf, video = pack
contents += f"{add_icons(pdf, video)} <a href='{program_url}/{code}' target='_schedule'>{title}</a>, {author}\n"
fn = open(base / fold / "contents.lr", "a")
fn.write(contents)
fn.close()
def fill_invited(base):
fold = Path(folders[2])
contents = ""
for number, label in themes.items():
bag = listings[number]["talks"]["invited"]
if len(bag):
contents += f"\n**{label.upper()}**\n\n"
for pack in bag:
title, abstract, code, author, pdf, video = pack
contents += f"{add_icons(pdf, video)} <a href='{program_url}/{code}' target='_schedule'>{title}</a>, {author}\n"
fn = open(base / fold / "contents.lr", "a")
fn.write(contents)
fn.close()
def fill_bofs(base):
fold = Path(folders[3])
contents = ""
for pack in bofs:
title, abstract, code, author, pdf, video = pack
contents += (
f"<b><a href='{program_url}/{code}' "
+ f"target='_schedule'>{title}</a></b>\n\n<b>{author}</b>\n\n"
)
contents += f"{abstract}\n\n"
fn = open(base / fold / "contents.lr", "a")
fn.write(contents)
fn.close()
def fill_demos(base):
fold = Path(folders[4])
contents = ""
for pack in demos:
title, abstract, code, author, pdf, video = pack
contents += (
f"<b><a href='{program_url}/{code}' "
+ f"target='_schedule'>{title}</a></b>\n\n<b>{author}</b>\n\n"
)
contents += f"{abstract}\n\n"
fn = open(base / fold / "contents.lr", "a")
fn.write(contents)
fn.close()
def fill_tutos():
fold = Path(folders[5])
contents = ""
for pack in tutos:
title, abstract, code, author, pdf, video = pack
contents += (
f"<b><a href='{program_url}/{code}' "
+ f"target='_schedule'>{title}</a></b>\n\n<b>{author}</b>\n\n"
)
contents += f"{abstract}\n\n"
fn = open(base / fold / "contents.lr", "a")
fn.write(contents)
fn.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"base",
metavar="ROOTDIR",
type=str,
nargs=1,
default=DEF_BASE,
help="root of the lektor site (website/content)",
)
args = parser.parse_args()
base = args.base[0]
if not os.path.isdir(base):
parser.error(f"{base}: no such file or directory")
listings = {}
demos = []
tutos = []
bofs = []
# connect to posgre pretalx
with psycopg2.connect(
database="pretalx",
user="pretalx",
password="",
host="pretalx.adass2020.es",
port="5432",
) as conn:
# build listings data structure
sql = """
SELECT
title, abstract, submission_submission.code, name, pdf_path, video_path
FROM
submission_submission,
person_user
WHERE
submission_submission.main_author_id=person_user.id
AND submission_submission.state='confirmed'
"""
for number, label in themes.items():
listings[number] = {
"posters": [],
"talks": {"invited": [], "contributed": [],},
}
# add poster for each theme
sql_posters = sql
sql_posters += f"""
AND submission_submission.submission_type_id in (13, 18)
AND submission_submission.paper_id LIKE 'P{number}-%'
ORDER BY title
"""
cur = conn.cursor()
cur.execute(sql_posters)
for row in cur:
listings[number]["posters"].append(row)
# add invited talks for each theme
sql_invited_talks = sql
sql_invited_talks += f"""
AND submission_submission.submission_type_id=1
AND submission_submission.paper_id LIKE 'I{number}-%'
ORDER BY title
"""
cur = conn.cursor()
cur.execute(sql_invited_talks)
for row in cur:
listings[number]["talks"]["invited"].append(row)
# add contributed talks for each theme
sql_talks = sql
sql_talks += f"""
AND submission_submission.submission_type_id=3
AND submission_submission.paper_id LIKE 'O{number}-%'
ORDER BY title
"""
cur = conn.cursor()
cur.execute(sql_talks)
for row in cur:
listings[number]["talks"]["contributed"].append(row)
# fill bofs
sql_bofs = sql
sql_bofs += """
AND submission_submission.submission_type_id=4
ORDER BY title
"""
cur = conn.cursor()
cur.execute(sql_bofs)
for row in cur:
bofs.append(row)
# fill demos
sql_demos = sql
sql_demos += """
AND submission_submission.submission_type_id=15
ORDER BY title
"""
cur = conn.cursor()
cur.execute(sql_demos)
for row in cur:
demos.append(row)
# fill tutos
sql_tutos = sql
sql_tutos += """
AND submission_submission.submission_type_id=14
ORDER BY title
"""
cur = conn.cursor()
cur.execute(sql_tutos)
for row in cur:
tutos.append(row)
# start filling files
make_folder_structure()
fill_posters()
fill_talks()
fill_invited()
fill_bofs()
fill_demos()
fill_tutos()