-
Notifications
You must be signed in to change notification settings - Fork 1
/
Etsy_Searcher.py
89 lines (46 loc) · 1.87 KB
/
Etsy_Searcher.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import random
import urllib2
import json
import webbrowser
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.top_frame = Frame(self)
self.my_button = Button(self.top_frame, text = 'Random Search', command = self.act)
self.my_button.pack()
self.top_frame.pack(side = 'top')
def act(self):
e = False
data = getListing()
while e == False:
try:
#print data['results'][0]['state']
print "Wait for it..."
while data['results'][0]['state'] == unicode('expired') or data['results'][0]['state'] == unicode('m_closed') or data['results'][0]['state'] == unicode('alchemy') or data['results'][0]['state'] == unicode('a_closed') or data['results'][0]['state'] == unicode('create') or data['results'][0]['state'] == unicode('edit') or data['results'][0]['state'] == unicode('removed') or data['results'][0]['state'] == unicode('sold_out') or data['results'][0]['state'] == unicode('unavailable') or data['results'][0]['state'] == unicode('draft'):
data = getListing()
except:
e = False
data = getListing()
else:
e = True
print data
x = data['params']['listing_id']
str(x)
webbrowser.open('http://www.etsy.com/listing/' + x)
def main():
app = Application()
app.master.title("Random Search")
app.mainloop()
def getListing():
itemID = random.randint(1, 86600611)
itemStr = str(itemID)
data = urllib2.urlopen('http://openapi.etsy.com/v2/listings/' + itemStr + '?api_key=XXXXXXXXXXXXXXXXXXX')
return json.load(data)
try:
main()
except:
main()