Repository navigation
Expand file tree
/
Copy pathcheckCountBuy.py
More file actions
143 lines (120 loc) · 3.16 KB
/
Copy pathcheckCountBuy.py
File metadata and controls
143 lines (120 loc) · 3.16 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import urllib
import urllib2
import json
import requests
import time
currentBuyCycle = 7
buyCycle = 2
on = True
# count()
countIOPlusUrl = ""
countIOMinusUrl = ""
r1 = ""
rf =""
count = ""
firstSplit=""
secoundSplit=""
strCount=""
intCount= 0
#check count.io
def count():
countIOPlusUrl = "http://count.io/vb/smartthingsLaundry/rforgeon1+"
countIOMinusUrl = "http://count.io/vb/smartthingsLaundry/rforgeon1-"
#open and add to count
r1 = requests.post(countIOPlusUrl)
#open and subtract from count
rf = requests.post(countIOMinusUrl)
#print rf.text
#convert to string
count = str(rf.text);
#parse out count
firstSplit = count.split('"count":')
secondSplit = firstSplit[1].split("}")
strCount = secondSplit[0]
#convert to int
intCount = int(strCount)
print "Current Count: "
print intCount
return intCount
#buy values
url = 'https://api.zinc.io/v0/order'
values = {
"client_token": "XXXXXXXXXXXXXXXXXXX",
"retailer": "amazon",
"products": [{"product_id": "B00LN23HHM", "quantity": 1}],
"max_price": 0,
"shipping_address": {
"first_name": "Bob",
"last_name": "Builder",
"address_line1": "2222 Mulberry Ln.",
"address_line2": "",
"zip_code": "95128",
"city": "San Jose",
"state": "CA",
"country": "US",
"phone_number": "2087390043"
},
"is_gift": False,
"gift_message": "Here's your package, Tim! Enjoy!",
"shipping_method": "cheapest",
"payment_method": {
"name_on_card": "Bob Builder",
"number": "1111111111111111",
"security_code": "111",
"expiration_month": 11,
"expiration_year": 2021,
"use_gift": False
},
"billing_address": {
"first_name": "Bob",
"last_name": "Builder",
"address_line1": "2222 Mulberry Ln.",
"address_line2": "",
"zip_code": "95128",
"city": "San Jose",
"state": "CA",
"country": "US",
"phone_number": "2087390043"
},
"retailer_credentials": {
"email": "bobBuilder7320@gmail.com",
"password": "ilovemuffins"
},
"webhooks": {
"order_placed": "http://mywebsite.com/zinc/order_placed",
"order_failed": "http://mywebsite.com/zinc/order_failed",
"tracking_obtained": "http://mywebsite.com/zinc/tracking_obtained"
},
"client_notes": {
"our_internal_order_id": "abc123"
}
}
data = ""
req = ""
response = ""
the_page = ""
#execute buy order
def buy():
#place order with Zinc
data = json.dumps(values)
req = urllib2.Request(url, data, {'content-type': 'application/json'})
response = urllib2.urlopen(req)
the_page = response.read()
#create new buy cycle
global buyCycle
global currentBuyCycle
currentBuyCycle += buyCycle
print the_page
#main
def main():
while on:
time.sleep(3)
global buyCycle
global currentBuyCycle
print "currentBuyCycle: "
print currentBuyCycle
if count() == currentBuyCycle:
buy()
print "Order executed"
#Run Main
main()