-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstitch.py
41 lines (37 loc) · 1.11 KB
/
stitch.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
import json
import os
import csv
path=os.path.abspath(os.path.dirname(__file__)) + '/allData/'
dates=[]
with open('Datasets/dates_all.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=' ')
for row in reader:
dates.append(row)
#declare the dictionary
data={}
params=['position','track','artist','streams','url']
for row in range(len(dates)):
c_date=str(dates[row][0])
day_file=path+c_date+'.csv'
titles={}
with open(day_file,newline='', encoding="utf8") as csvfile:
reader=csv.reader(csvfile,delimiter=',')
line1=next(reader)
line1_item=str(line1[0])
if(line1_item=='<!doctype html>'):
print('true')
continue
next(reader)
for row2 in reader:
song={}
song['position']=row2[0]
song['track']=row2[1]
song['artist']=row2[2]
song['streams']=row2[3]
song['url']=row2[4]
titles[row2[0]]=song
data[c_date]=titles
titles={}
#save dictionary to json
with open('Datasets/dict.json', 'w') as outfile:
json.dump(data, outfile)