-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockChecker.py
More file actions
62 lines (51 loc) · 1.76 KB
/
StockChecker.py
File metadata and controls
62 lines (51 loc) · 1.76 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
import urllib.request
import time
from twilio.rest import TwilioRestClient
__author__ = 'James'
class StockChecker():
def setup(self):
f = open('data.txt', 'r')
self.url = f.readline().strip('\n')
self.webController = f.readline().strip('\n')
self.sid = f.readline().strip('\n')
self.auth = f.readline().strip('\n')
self.clientNumber = f.readline().strip('\n')
self.serverNumber = f.readline().strip('\n')
self.client = TwilioRestClient(self.sid, self.auth)
#print(self.url)
#getting the website
def getWebPage(self, url):
page = urllib.request.urlopen(url)
source = page.read()
strSource = str(source)
return strSource.lower()
def text(self, msg):
message = self.client.messages.create(
body="|" + msg,
to=self.clientNumber,
from_=self.serverNumber)
#print (message.sid)
print ('texting', msg)
#print (msg)
while True:
sc = StockChecker()
sc.setup()
strSource = sc.getWebPage(sc.url)
if strSource.find('out of stock') == -1:
#gets the title of the product (nintendo website)
#have to custimize these for every website type
begin = strSource.find('results-header')
begin += len("results-header") + 2
end = strSource.find("</h2>", begin)
#print(strSource[begin:end])
productName = strSource[begin:end]
sc.text(productName + " || is in stock")
#i can change webpage remotely to stop the program
if sc.getWebPage(sc.webController).find("offline") != -1:
sc.text("Ending program")
print("ENDING")
break
print('cycle')
#runs program every hour
time.sleep(3600)
print ('eof')