-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule_2_json.py
38 lines (29 loc) · 983 Bytes
/
schedule_2_json.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
# encoding: utf-8
#!/usr/bin/env python3
from datetime import datetime
import csv
import pandas as pd
def schedule_2_json():
df = pd.read_csv("input.csv", encoding="utf-8")
df = df.loc[df["Aprovada"].isin(["ok"])]
selected_headers = [
"Data e Hora",
"Título da Palestra:",
"Duração (minutos)",
"Link",
]
df = df[selected_headers]
df.columns = ["datetime", "title", "duration", "link"]
df["datetime"] = df["datetime"].apply(lambda x: convert_date(x))
df["embed_link"] = df["link"].apply(lambda x: convert_to_embed(x))
df.to_json("output.json", orient="records", force_ascii=False)
def convert_date(date_str):
try:
date = datetime.strptime(date_str, "%d/%m/%Y %H:%M")
return date.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-4]
except Exception:
return date_str
def convert_to_embed(url):
return url.replace("watch?v=", "embed/")
if __name__ == "__main__":
schedule_2_json()