-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwordsy.py
More file actions
37 lines (31 loc) · 1.12 KB
/
wordsy.py
File metadata and controls
37 lines (31 loc) · 1.12 KB
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
import requests
import json
class Etsy:
def gettrendingresponse(self):
r = requests.get('https://openapi.etsy.com/v2/listings/trending?api_key=<APIKEY_HERE>&limit=250')
iterkeywords = []
keywords = json.loads(r.text)
for item in keywords['results']:
if 'tags' in item:
for mytags in item['tags']:
iterkeywords.append(mytags.lower())
return iterkeywords
class Words:
def killunicode(self, iw):
wordlist = []
wordlist = [str(unicodes.encode("ascii", "ignore")) for unicodes in iw]
return wordlist
def printdict(self, wl):
wordfreq = [wl.count(p) for p in wl]
mydict = dict(zip(wl,wordfreq))
for key, value in sorted(mydict.iteritems(), key=lambda (k,v): (v,k), reverse=True):
if value <= 1:
pass
else:
print key, "Freq", value
if __name__ == '__main__':
keywords = Etsy()
ourwords = Words()
ourkeywords = keywords.gettrendingresponse()
cleanwords = ourwords.killunicode(ourkeywords)
ourwords.printdict(cleanwords)