-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotify_artist.py
48 lines (44 loc) · 1.52 KB
/
spotify_artist.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 tweepy
import ignrtis
from collections import Counter, OrderedDict
from operator import itemgetter
auth = tweepy.OAuthHandler(ignrtis.con_key, ignrtis.con_key_srt)
auth.set_access_token(ignrtis.acc_tkn, ignrtis.acc_tkn_srt)
api = tweepy.API(auth,wait_on_rate_limit=True)
links=[]
def getrecent():
for tweet in tweepy.Cursor(api.search,q="open.spotify.com/artist",count=100,result_type="recent").items(1000):
urls= tweet.entities['urls']
spotify=[d['expanded_url'] for d in urls if 'expanded_url' in d]
links.extend(spotify)
#print(tweet.full_text)
# print(urls)
tosent=dict(Counter(links))
d = OrderedDict(sorted(tosent.items(), key=itemgetter(1),reverse=True))
count=0
outdict={}
for i,j in d.items():
if (i.find('spoti')!=-1):
outdict[i]=j
count+=1
if(count==6):
break
return (outdict)
def gethots():
for tweet in tweepy.Cursor(api.search,q="open.spotify.com/artist",count=100,result_type="mixed").items(1000):
urls= tweet.entities['urls']
spotify=[d['expanded_url'] for d in urls if 'expanded_url' in d]
links.extend(spotify)
#print(tweet.full_text)
# print(urls)
tosent=dict(Counter(links))
d = OrderedDict(sorted(tosent.items(), key=itemgetter(1),reverse=True))
count=0
outdict={}
for i,j in d.items():
if (i.find('spoti')!=-1):
outdict[i]=j
count+=1
if(count==6):
break
return (outdict)