-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
37 lines (33 loc) · 1.35 KB
/
index.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
import pandas as pd
from elasticsearch_dsl import connections, Index
from model import Talk
from datetime import datetime
if __name__== "__main__":
# Indexes Reset
connections.create_connection(hosts=['localhost'])
talks_index = Index(Talk.Index.name)
talks_index.delete(ignore=404)
talks_index.create()
talks_df = pd.read_csv('./data/talks.csv')
print("Number of talks in the report: {}".format(len(talks_df)))
for index, row in talks_df.iterrows():
next_talk = Talk()
next_talk.title = row['Title']
next_talk.speakers = row['Speakers'].split('/')
next_talk.day = row['Day']
next_talk.place = row['Place']
next_talk.type = row['Type']
next_talk.start = datetime.strptime(row['Start'], '%H:%M')
if next_talk.day.startswith("s"):
next_talk.start = next_talk.start.replace(year=2019, month=10, day=5)
else:
next_talk.start = next_talk.start.replace(year=2019, month=10, day=6)
next_talk.end = datetime.strptime(row['End'], '%H:%M')
if next_talk.day.startswith("s"):
next_talk.end = next_talk.end.replace(year=2019, month=10, day=5)
else:
next_talk.end = next_talk.end.replace(year=2019, month=10, day=6)
try:
next_talk.save()
except Exception as e:
print (e.message)