-
Notifications
You must be signed in to change notification settings - Fork 0
/
jrad2.py
67 lines (49 loc) · 2.35 KB
/
jrad2.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
import setlist_fm_client
import re
import sqlite3
setlists = setlist_fm_client.get_artist_setlists("84a69823-3d4f-4ede-b43f-17f85513181a", p=9, api_key=xxxxxxx, serialize=True)
#Collecting the direct url link to setlist page for each show. Then will use beautiful soup to parse each setlist page to collect and store in database: date, city, venue, songs.
conn = sqlite3.connect('jrad.sqlite')
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS Setlists
(url TEXT UNIQUE)''')
#The API and setlist_fm_client function only allow us to call one page of results.
#Until I find a more elegant workaround, I am adding code to collect from each page by updating the parameter--p--in the function call.
#In earlier iterations of this code I retrieved the urls from the first 8 pages of setlist data.
lst = list()
x = "https://www.setlist.fm/setlist/"
data = str(setlists)
lines = data.split()
for item in lines:
if x in item:
lst.append(item[13:])
for show in lst:
if len(show) > 1:
cur.execute('INSERT OR IGNORE INTO Setlists (url) VALUES ( ? )', ( show, ) )
conn.commit()
#The API and setlist_fm_client function only allow us to call one page of results.
#Until I find a more elegant workaround, I am adding code to collect from each page by updating the parameter--p--in the function call.
#In earlier iterations of this code I retrieved the urls from the first 8 pages of setlist data.
setlists = setlist_fm_client.get_artist_setlists("84a69823-3d4f-4ede-b43f-17f85513181a", p=10, api_key=xxxxxxx, serialize=True)
lst2 = list()
data = str(setlists)
lines = data.split()
for item in lines:
if x in item:
lst2.append(item[13:])
for show in lst2:
if len(show) > 1:
cur.execute('INSERT OR IGNORE INTO Setlists (url) VALUES ( ? )', ( show, ) )
conn.commit()
setlists = setlist_fm_client.get_artist_setlists("84a69823-3d4f-4ede-b43f-17f85513181a", p=11, api_key=xxxxxxx, serialize=True)
lst3 = list()
data = str(setlists)
lines = data.split()
for item in lines:
if x in item:
lst3.append(item[13:])
for show in lst3:
if len(show) > 1:
cur.execute('INSERT OR IGNORE INTO Setlists (url) VALUES ( ? )', ( show, ) )
conn.commit()
print('done')