forked from paperswithcode/ai-deadlines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_google_sheet.py
175 lines (141 loc) · 4.83 KB
/
parse_google_sheet.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
import argparse
from datetime import datetime
import logging
import math
import numbers
import os
import pandas
import requests
import sys
import yaml
def parse_args() -> dict:
"""Function to parse script arguments"""
parser = argparse.ArgumentParser(description="")
parser.add_argument("-vv", "--debug", action="store_true", help="debug output")
parser.add_argument(
"-sid",
"--sheetid",
type=str,
default="1guvefLTrWjY3B1BQNK_NWsy-MceHCnrjjZjT46-jqmw",
help="Google Spreadsheet ID",
)
parser.add_argument(
"-sname",
"--sheetname",
type=str,
required=True,
help="Google Spreadsheet Name",
)
args = parser.parse_args()
return args
def getGoogleSeet(spreadsheet_id, sheet_name, outDir, outFile):
url = f"https://docs.google.com/spreadsheets/d/{spreadsheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
response = requests.get(url)
print(response)
if response.status_code == 200:
filepath = os.path.join(outDir, outFile)
with open(filepath, "wb") as f:
f.write(response.content)
print("CSV file saved to: {}".format(filepath))
else:
print(f"Error downloading Google Sheet: {response.status_code}")
sys.exit(1)
return filepath
def is_nan(entry):
if isinstance(entry, numbers.Number) and math.isnan(entry):
return True
else:
return False
def export_to_yml(filepath):
conferences_csv = pandas.read_csv(filepath)
with open("_data/conferences.yml") as stream:
try:
conferences_yml = yaml.safe_load(stream)
except yaml.YAMLError as e:
logging.error(e)
conferences = set()
if not conferences_yml:
conferences_yml = []
for entry in conferences_yml:
conferences.add(entry["id"])
logging.debug(conferences_yml)
logging.debug(conferences_csv.iloc[:, 1:16])
for _, row in conferences_csv.iterrows():
for i, entry in enumerate(conferences_yml):
if entry["id"] == row["id"]:
logging.warning(f"Deleting entry {entry['id']}")
del conferences_yml[i]
break
# Check validity of entries
for entry in row.keys():
if is_nan(row[entry]):
row[entry] = None
# Check if deadline date(s) are estimated
if "EST" in row:
estimated = row["EST"]
if "Timezone" not in row:
estimated = True
# TODO add more criteria?
# Validate dates
dates = {}
for datekey in ["DL", "DL Abstract", "Conf start", "Conf end"]:
if not isinstance(row[datekey], str):
date = "01.01.1900" # invalid data set to Jan 1, 1900
else:
date = row[datekey]
dates[datekey] = datetime.strptime(date, "%d.%m.%Y")
# create tags
subs = []
if row["Main topic"]:
subs.append(row["Main topic"])
if row["Other topics"]:
subs.extend(row["Other topics"].split(", "))
track = f" [{row['Track']}]" if row["Track"] else ""
# Write info
conferences_yml.append(
{
"title": row["Conference"] + track,
"year": None,
"id": row["id"],
"full_name": row["Conference"] + track,
"link": row["Call"],
"deadline": dates["DL"].strftime("%Y-%m-%d"),
"abstract_deadline": dates["DL Abstract"].strftime("%Y-%m-%d"),
"timezone": "UTC-12",
"estimated": estimated,
"place": row["Location"],
"date": f"{dates['Conf start'].strftime("%d %B")} - {dates['Conf end'].strftime(
"%d %B, %Y"
)}",
"start": dates["Conf start"].strftime("%Y-%m-%d"),
"end": dates["Conf end"].strftime("%Y-%m-%d"),
"paperslink": None,
"pwclink": None,
"hindex": None,
"core": row["CORE23"],
"sub": subs,
"note": None,
}
)
return conferences_yml
def main() -> int:
"""main function"""
# load arguments
args = parse_args()
# define logging level and format
level = logging.INFO
if args.debug:
level = logging.DEBUG
logging.basicConfig(
format="%(asctime)s %(levelname)s:%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=level,
)
os.makedirs("_temp", exist_ok=True)
filepath = getGoogleSeet(args.sheetid, args.sheetname, "_temp", "conferences.csv")
conferences_yml = export_to_yml(filepath)
with open("_data/conferences.yml", "w") as file:
yaml.dump(conferences_yml, file)
return 0
if __name__ == "__main__":
sys.exit(main())