-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsnipe.py
executable file
·58 lines (48 loc) · 1.17 KB
/
snipe.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
#!/usr/bin/env python
import signal, sys, os, traceback, pickle
from ebay import EBayClient
from web import WebServer
from updater import ItemUpdater
from watcher import ItemWatcher
from config import Config
cli = EBayClient()
itemUpdater = ItemUpdater(cli)
itemWatcher = ItemWatcher(cli)
webServer = WebServer(cli, itemUpdater)
def signalHandler(signum, frame):
if (signum == signal.SIGINT):
print 'Caught SIGINT, shutting down...'
exit(1)
def exit(code):
webServer.stop()
sys.exit(code)
def main(filename):
signal.signal(signal.SIGINT, signalHandler)
if os.path.exists(filename):
fileObj = open(filename, "rb")
try:
Config.items = pickle.load(fileObj)
finally:
fileObj.close()
else:
Config.items = { }
def _saveData():
fileObj = open(filename, "wb")
try:
pickle.dump(Config.items, fileObj)
finally:
fileObj.close()
try:
webServer.subscribe(_saveData)
webServer.start()
itemUpdater.start()
itemWatcher.start()
raw_input("Press Ctrl+C key to exit\n")
print "Shutting down..."
exit(0)
except Exception, e:
print "Caught error: %s" % e
traceback.print_exc(file=sys.stdout)
exit(2)
if __name__ == "__main__":
main("snipe.db")