-
Notifications
You must be signed in to change notification settings - Fork 1
/
spelunker.py
49 lines (40 loc) · 1.12 KB
/
spelunker.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
import scraper
import scrubber
import dataset
import sys
sys.path.append('./scrobble-streamgraph/')
import processor
if __name__ == '__main__':
try:
user = sys.argv[1]
except IndexError:
print("[ERROR] No last.fm username specified.")
quit()
try:
stream_limit = sys.argv[2]
except IndexError:
print("[ERROR] No scrobble minimum specified.")
quit()
try:
int(stream_limit)
except ValueError:
print("[ERROR] Scrobble minimum must be an integer.")
quit()
scr = scraper.Scraper(user)
with dataset.connect('sqlite:///last-fm.db') as db:
sql = 'SELECT COUNT(name) as count FROM sqlite_master WHERE type=\'table\' AND name=\'%s\'' % user
exists = int(db.query(sql).next()['count'])
if exists:
scr.update_scrobbles()
else:
scr.get_all_scrobbles()
print("Processing scrobble history...")
scrubber.rename_variants(user)
scrubber.apply_SQL_script('scrubscript.sql')
sys.stdout.flush()
print("Processed scrobble history.")
sys.stdout.write("\rGenerating streamgraph data...")
sys.stdout.flush()
metric = 'artist'
processor.process(user, metric, stream_limit)
print("\rGenerated streamgraph data. ")