-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
57 lines (45 loc) · 1.48 KB
/
runner.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
import time
import ConfigParser
import _mysql
from datetime import datetime
from grooveuser import GrooveUser
from lastfm import LastFm
class Runner(object):
TABLE = 'luvluvluv'
def __init__(self, config_file):
cp = ConfigParser.ConfigParser()
cp.read(config_file)
self.api = { 'key' : cp.get('application', 'api_key'),
'secret' : cp.get('application', 'secret') }
self.db = { 'host' : cp.get('client', 'host'),
'database' : cp.get('client', 'database'),
'user' : cp.get('client', 'user'),
'password' : cp.get('client', 'password') }
self.__parse()
def __parse(self):
inst = _mysql.connect(host=self.db['host'],
db=self.db['database'],
user=self.db['user'],
passwd=self.db['password'])
inst.query("SELECT * FROM `%s` LIMIT 0, 1000" % (self.TABLE))
r = inst.store_result()
for row in r.fetch_row(maxrows=0, how=1):
gu = GrooveUser(row['grooveshark'], row['sync'])
lu = LastFm(row['lastfm'], row['session'], self.api)
for track in gu.tracks:
lu.luv_track(track['artist'], track['title'])
del gu, lu
# update last sync time
last_sync = time.strftime("%a, %d %b %Y %H:%M:%S +0000",
time.gmtime())
update_query = "UPDATE `%s` SET sync='%s' \
WHERE lastfm='%s' AND grooveshark='%s'" % \
(self.TABLE,
last_sync,
row['lastfm'],
row['grooveshark'])
inst.query(update_query)
def main():
run = Runner('./config.ini')
if __name__ == "__main__":
main()