offline home bethack cat gambling parsers py coding utf-8 from decimal

 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
[offline@home bethack]$ cat gambling/parsers.py
# -*- coding: utf-8
from decimal import Decimal
from project.logger import LogToFile
log = LogToFile("cronLog")
class WillHillParser(object):
def __init__(self, soup, events, bookie):
self.soup = soup
self.events = events
self.bookie = bookie
def get_result(self):
results = []
for event in self.events:
xmlevent = self.soup.find(text="%s V %s" % (event.home.title, event.away.title))
if xmlevent:
xmlevent = xmlevent.parent.parent
result = {'event': event,
'bookie': self.bookie,
'home': Decimal(xmlevent.homeprice.string),
'draw': Decimal(xmlevent.drawprice.string),
'away': Decimal(xmlevent.awayprice.string),
}
results.append(result)
else:
log.error(u"Error: Cant find odds in %s bookie for %s - %s event" % (self.bookie.title, event.home.title, event.away.title))
return results
[offline@home bethack]$ cat project/logger.py
# -*- coding: utf-8
import logging
import os.path
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class LogToFile(object):
def __init__(self, name):
self.log = logging.getLogger(name)
self.log.setLevel(logging.INFO)
self.handler = logging.FileHandler(os.path.join(path, 'log.txt'))
self.formater = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
self.handler.setFormatter(self.formater)
self.log.addHandler(self.handler)
def error(self, message):
self.log.error(message)
def info(self, message):
self.log.info(message)