-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhats_on_get_bad_tracks.py
executable file
·58 lines (39 loc) · 1.34 KB
/
whats_on_get_bad_tracks.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
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
"""Queries the databases for songs where the LFID is NULL
This indicates a track that wasn't found in last.fm."""
from __future__ import print_function
import boto
import datetime
import yaml
import sys
def main():
"""Finds any entries that have a NULL LFID"""
print(datetime.datetime.now())
try:
stations_yaml = open('stations.yaml')
except IOError:
print("Failed to load station list", file=sys.stderr)
sys.exit(-1)
stations = yaml.load(stations_yaml)
sdb = boto.connect_sdb()
null_lfid = []
for station_id in stations.keys():
find_null_lfid( station_id, sdb, null_lfid )
results = yaml.safe_dump(sorted(null_lfid), default_flow_style=False)
print(results)
print(datetime.datetime.now())
def find_null_lfid( station, sdb, null_lfid ):
"""Appends any NULL LFIDs albums to the list"""
try:
domain = sdb.get_domain("%s-whatson" % station )
except boto.exception.SDBResponseError:
return
query = 'select * from `%s` where `LFID` is NULL' % domain.name
result_set = domain.select(query)
for item in result_set:
null_track = {item['Artist']: item['Title']}
if null_track not in null_lfid:
null_lfid.append(null_track)
if __name__ == "__main__":
main()