Last active
January 4, 2016 21:29
-
-
Save scturtle/8680970 to your computer and use it in GitHub Desktop.
get doubanFM starred songs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import os | |
data = { | |
'email': '[email protected]', | |
'password': '', | |
'app_name': 'radio_android', | |
'version': '606', | |
} | |
params = { | |
'count': 200, | |
'app_name': 'radio_android', | |
'version': '606', | |
} | |
def login(): | |
if os.path.exists('key.json'): | |
key = json.load(open('key.json')) | |
else: | |
key = requests.post('https://www.douban.com/j/app/login', | |
data=data).json() | |
json.dump(key, open('key.json', 'w')) | |
return type('key', (), key) | |
def main(): | |
''' method from http://lisie.hdu.edu.cn/passionke/?p=4105 ''' | |
global params | |
key = login() | |
assert key.err == 'ok', 'Login error: {}'.format(key.err) | |
params.update({'token': key.token, | |
'user_id': key.user_id, | |
'expire': key.expire}) | |
data = {} | |
while 1: | |
params['exclude'] = '|'.join(data.keys()) | |
new_data = requests.get( | |
'http://www.douban.com/j/app/radio/liked_songs', | |
params=params).json()['songs'] | |
if len(new_data) == 0: | |
break | |
data.update({t['sid']: t for t in new_data}) | |
print 'new:{} total:{}'.format(len(new_data), len(data)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment