-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc.py
57 lines (47 loc) · 1.68 KB
/
sc.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
__author__ = 'jpatdalton'
import soundcloud
import requests
import columns
YOUR_CLIENT_ID = ''
YOUR_CLIENT_SECRET = ''
def get_followers(artists, worksheet, end):
client = soundcloud.Client(client_id=YOUR_CLIENT_ID,client_secret=YOUR_CLIENT_SECRET)
col = columns.soundcloud
cell_list_likes = worksheet.range(col+'2:'+col+end)
for n in xrange(len(artists)):
name = artists[n]
req = 'https://api.soundcloud.com/users.json?q='+name+'&client_id='+YOUR_CLIENT_ID
try:
users = requests.get(req).json()
followers = users[0]["followers_count"]
cell_list_likes[n].value = followers
except Exception, e:
print e, 'Soundcloud couldnt get user ['+name+']'
worksheet.update_cells(cell_list_likes)
def get_num_followers(id):
count = 0
try:
req = 'https://api.soundcloud.com/users/'+str(id)+'.json?client_id='+YOUR_CLIENT_ID
user = requests.get(req).json()
count = user["followers_count"]
except Exception, e:
print e, 'soundcloud followers error ', id
return count
def get_id(name):
the_id = 'None'
try:
req = 'https://api.soundcloud.com/users.json?q='+name+'&client_id='+YOUR_CLIENT_ID
users = requests.get(req).json()
the_id = users[0]["id"]
except Exception, e:
print e, 'Cant get Soundcloud id for artist: ' + name
return the_id
def get_page(id):
url = ''
try:
req = 'https://api.soundcloud.com/users/'+str(id)+'.json?client_id='+YOUR_CLIENT_ID
user = requests.get(req).json()
url = user["permalink_url"]
except Exception, e:
print e, 'soundcloud url error ', id
return url