-
Notifications
You must be signed in to change notification settings - Fork 11
/
watcher.py
57 lines (46 loc) · 1.45 KB
/
watcher.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
import threading
import time
from dateutil.tz import tzlocal
from datetime import datetime, timedelta
from config import Config
from ebay import EBayClient
class ItemWatcher(threading.Thread):
def __init__(self, cli):
threading.Thread.__init__(self)
self.cli = EBayClient()
self.logged_in = False
def timeLeft(self, item):
if item.info == None:
return None
return item.info['endtime'] - datetime.now(tzlocal())
def watchItem(self, item):
if item.info == None:
return
time_left = self.timeLeft(item)
if (time_left == timedelta()):
return
if time_left < timedelta(0, Config.bidtime, 0) and not item.ignore:
try:
if item.maxbid >= item.info['minbid']:
print "Sniping item %d (our bid %d)" % (item.id, item.maxbid)
self.cli.bid(item.id, item.maxbid)
print "Successful bid at %s! Hope you win!" % (self.timeLeft(item))
else:
print "Skipping item %d as our max bid is lower than current minimum" % (item.maxbid)
except Exception, e:
print "BID FAILED: %s" % e
finally:
self.logged_in = False
item.ignore = True
elif time_left < timedelta(0, 300, 0) and not self.logged_in:
try:
print "Logging in to eBay as %s..." % Config.username
self.cli.login(Config.username, Config.password)
self.logged_in = True
except Exception, e:
print "FATAL: Login failed: %s" % e
def run(self):
while True:
time.sleep(1)
for item in Config.items.values():
self.watchItem(item)