def __init__(self):
self.load()
- def update(self, *args, **kwargs):
- a = dict.update(self, *args, **kwargs)
+ def __setitem__(self, *args, **kwargs):
+ s = dict.__setitem__(self, *args, **kwargs)
self.save()
- return a
+ return s
def save(self):
with open(defaults.cache_lines, 'w') as fp:
lines = Lines()
-
class Stations(dict):
stations = None
# FIXME maybe cause problems in the future, race conditions
Stations.stations[line] = self
- def update(self, *args, **kwargs):
- u = dict.update(self, *args, **kwargs)
- if args[0]:
- Stations.save()
+ def __setitem__(self, *args, **kwargs):
+ u = dict.__setitem__(self, *args, **kwargs)
+ Stations.save()
return u
@classmethod
import re
import collections
from errors import LineNotFoundError, StationNotFoundError
+import cache
+from cache import Stations
from gotovienna import defaults
class ITipParser:
def __init__(self):
- self._stations = {}
- self._lines = {}
+ self._lines = cache.lines
def get_stations(self, name):
""" Get station by direction
{'Directionname': [('Station name', 'url')]}
"""
- if not self._stations.has_key(name):
- st = {}
+ if not name in self.lines:
+ return {}
- if not self.lines.has_key(name):
- return None
+ st = Stations(name)
+ if not st:
bs = BeautifulSoup(urlopen(self.lines[name]))
tables = bs.findAll('table', {'class': 'text_10pix'})
for i in range(2):
sta.append((tr.text.strip(' '), None))
st[dir] = sta
- self._stations[name] = st
- return self._stations[name]
+ return st
@property
def lines(self):