Make ethercalc support optional

Do not require ethercalc URL and cells.
This commit is contained in:
Thierry Carrez 2017-05-29 17:21:43 +02:00
parent b8ca0c43ff
commit b9790b685f
2 changed files with 14 additions and 8 deletions

View File

@ -46,7 +46,11 @@ Edit config.ini contents, for example::
server=irc.freenode.net server=irc.freenode.net
port=6667 port=6667
channels=testptg channels=testptg
db=html/ptg.json
[db]
filename=html/ptg.json
ethercalc=
cells=
In one terminal, run the bot:: In one terminal, run the bot::

View File

@ -44,13 +44,15 @@ class PTGDataBase():
self.save() self.save()
def from_ethercalc(self): def from_ethercalc(self):
ethercalc = requests.get(self.ethercalc_url).json() if self.ethercalc_url:
self.data['ethercalc'] = [] ethercalc = requests.get(self.ethercalc_url).json()
for cell in self.ethercalc_cells: self.data['ethercalc'] = []
if 'comment' in ethercalc[cell] and 'datavalue' in ethercalc[cell]: for cell in self.ethercalc_cells:
msg = '%s: %s' % (ethercalc[cell]['comment'], if ('comment' in ethercalc[cell] and
ethercalc[cell]['datavalue']) 'datavalue' in ethercalc[cell]):
self.data['ethercalc'].append(msg) msg = '%s: %s' % (ethercalc[cell]['comment'],
ethercalc[cell]['datavalue'])
self.data['ethercalc'].append(msg)
def wipe(self): def wipe(self):
self.data = {'now': {}, 'next': {}} self.data = {'now': {}, 'next': {}}