-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv2json.py
More file actions
executable file
·182 lines (146 loc) · 7.64 KB
/
csv2json.py
File metadata and controls
executable file
·182 lines (146 loc) · 7.64 KB
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
#!/usr/bin/env python3.9
import json
from collections import defaultdict
from pathlib import Path
from pprint import pprint
from typing import Optional
from bs4 import BeautifulSoup
import pandas as pd
from paper import Paper, PaperEncoder
if __name__ == "__main__":
short_file: str = "short_papers.csv"
long_file: str = "long_papers.csv"
pmlr_file: str = "midl2021_pmlr_map_openreview.csv"
youtube_file: str = "youtube.json"
cloudflare_file: str = "cloudflare_stream.json"
program_file: str = "program.html"
output_file: str = "papers.json"
program_dict: dict[str, tuple[str, str]] = {} # openreview key: [conf_id, Schedule]
chairs_dict: dict[str, str] = {} # openreview key: [conf_id, chairs]
# Parse the schedule
current_time: Optional[str] = None
current_day: Optional[str] = None
current_chairs: Optional[str] = None
conf_id: str
openreview_id: str
with open(program_file, 'r') as f:
for line in f:
if "<h2>" in line:
current_day = BeautifulSoup(line, 'html.parser').h2.text
elif "<h3>" in line:
current_time = BeautifulSoup(line, 'html.parser').h3.text
elif "Chairs:" in line:
current_chairs = line.removeprefix("Chairs: ").removesuffix(" <br>\n")
# print(current_time, current_chairs)
elif 'target="_blank">' in line:
conf_id = line.split(':')[0]
openreview_url = BeautifulSoup(line, 'html.parser').a['href']
openreview_id = openreview_url.split("id=")[1]
assert current_time is not None
assert current_chairs is not None
program_dict[openreview_id] = (conf_id, f"{current_day}\n{current_time}")
chairs_dict[openreview_id] = current_chairs
# pprint(program_dict)
# Parse the proceedings IDs
df_pmlr_id: pd.DataFrame
df_pmlr_id = pd.read_csv(pmlr_file,
sep=',',
dtype={"number": int,
"Last Name": str,
"pmlr": str,
"forum": str})
pmlr_dict: dict[int, str] = {}
for _, csv_line in df_pmlr_id.iterrows():
pmlr_dict[csv_line["number"]] = csv_line["pmlr"]
# Fetch the video IDS
with open(youtube_file, 'r') as fp:
youtube_dict: dict[str, str] = json.load(fp)
with open(cloudflare_file, 'r') as cf:
cloudflare_dict: defaultdict[str, str] = defaultdict(str)
for k, v in json.load(cf).items():
cloudflare_dict[k] = v
# Parse the long papers
df_long_papers: pd.DataFrame
df_long_papers = pd.read_csv(long_file,
sep=',',
dtype={"number": int,
"forum": str,
"title:": str,
"abstract": str,
"authors": str,
"decision": str})
# print(df_long_papers)
orals: list[str] = ["A1", "A2", "A3",
"D1", "D2", "D3",
"E1", "E2", "E3",
"H1", "H2", "H3",
"L1", "L2", "L3"]
slides: str
papers: list[Paper] = []
for _, csv_line in df_long_papers.iterrows():
if csv_line['decision'] == "Reject":
continue
authors: list[str] = csv_line['authors'].split('|')
or_id: str = csv_line['forum'].split("?id=")[1]
id_: str
schedule: str
id_, schedule = program_dict[or_id]
oral: bool = id_ in orals
number: int = csv_line['number']
video_name: str = f"full_{number}_video.mp4"
current_paper: Paper = Paper(id=id_,
title=csv_line['title'],
authors=', '.join(authors),
url=f"papers/{id_}.html",
or_id=or_id,
oral=str(oral),
short="False",
abstract=csv_line['abstract'],
schedule=schedule,
slides=f"/slides/full_{number}_poster.pdf",
video=f"/videos/full_{number}_video.mp4",
pdf=f"/proceedings/{pmlr_dict[number]}",
youtube_video_id=youtube_dict[id_],
cloudflare_video_id=cloudflare_dict[video_name],
chairs=chairs_dict[or_id])
# print(f"{{{{{current_paper.id}}}}}")
papers.append(current_paper)
# parse the short papers
df_short_papers: pd.DataFrame
df_short_papers = pd.read_csv(short_file,
sep=',',
dtype={"number": int,
"forum": str,
"title:": str,
"abstract": str,
"authors": str,
"decision": str})
for _, csv_line in df_short_papers.iterrows():
if csv_line['decision'] == "Reject":
continue
authors = csv_line['authors'].split('|')
or_id = csv_line['forum'].split("?id=")[1]
id_
schedule
id_, schedule = program_dict[or_id]
number = csv_line['number']
video_name = f"short_{number}_video.mp4"
current_paper = Paper(id=id_,
title=csv_line['title'],
authors=', '.join(authors),
url=f"papers/{id_}.html",
or_id=or_id,
oral="False",
short="True",
abstract=csv_line['abstract'],
schedule=schedule,
slides=f"/slides/short_{number}_poster.pdf",
video=f"/videos/short_{number}_video.mp4",
youtube_video_id=youtube_dict[id_],
cloudflare_video_id=cloudflare_dict[video_name],
chairs=chairs_dict[or_id])
# print(f"{{{{{current_paper.id}}}}}")
papers.append(current_paper)
with open(output_file, 'w') as sink:
json.dump({p.id: p for p in papers}, sink,
cls=PaperEncoder, indent=4, sort_keys=True)