diff --git a/config.ini.sample b/config.ini.sample
index e1518bb..2484887 100644
--- a/config.ini.sample
+++ b/config.ini.sample
@@ -4,4 +4,8 @@ pass=PASSWORD
server=irc.freenode.net
port=6667
channels=foo,bar
-db=html/ptg.json
+
+[db]
+filename=html/ptg.json
+ethercalc=https://ethercalc.openstack.org/_/MyDocumentName/cells
+cells=E9 E10
diff --git a/html/ptg.html b/html/ptg.html
index 80415d5..f8f29b2 100644
--- a/html/ptg.html
+++ b/html/ptg.html
@@ -47,6 +47,18 @@
{{/each}}
+
+
Planned for today in reservable rooms
+
+ {{#each ethercalc}}
+
+ {{this}} |
+
+ {{else}}
+ Nothing yet | |
+ {{/each}}
+
+
diff --git a/ptgbot/bot.py b/ptgbot/bot.py
index a981418..a4ebbba 100644
--- a/ptgbot/bot.py
+++ b/ptgbot/bot.py
@@ -42,7 +42,7 @@ ANTI_FLOOD_SLEEP = 2
class PTGBot(irc.bot.SingleServerIRCBot):
log = logging.getLogger("ptgbot.bot")
- def __init__(self, nickname, password, server, port, channels, dbfile):
+ def __init__(self, nickname, password, server, port, channels, db):
if port == 6697:
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
irc.bot.SingleServerIRCBot.__init__(self,
@@ -57,7 +57,7 @@ class PTGBot(irc.bot.SingleServerIRCBot):
self.password = password
self.channel_list = channels
self.identify_msg_cap = False
- self.data = ptgbot.db.PTGDataBase(dbfile)
+ self.data = db
def on_nicknameinuse(self, c, e):
self.log.debug("Nickname in use, releasing")
@@ -158,12 +158,17 @@ def start(configpath):
channels = ['#' + name.strip() for name in
config.get('ircbot', 'channels').split(',')]
+ db = ptgbot.db.PTGDataBase(
+ config.get('db', 'filename'),
+ config.get('db', 'ethercalc'),
+ config.get('db', 'cells'))
+
bot = PTGBot(config.get('ircbot', 'nick'),
config.get('ircbot', 'pass'),
config.get('ircbot', 'server'),
config.getint('ircbot', 'port'),
channels,
- config.get('ircbot', 'db'))
+ db)
bot.start()
diff --git a/ptgbot/db.py b/ptgbot/db.py
index 7ff1921..f860485 100644
--- a/ptgbot/db.py
+++ b/ptgbot/db.py
@@ -16,17 +16,20 @@
import json
import os
+import requests
class PTGDataBase():
- def __init__(self, filename):
+ def __init__(self, filename, ethercalc_url, ethercalc_cells):
self.filename = filename
+ self.ethercalc_url = ethercalc_url
+ self.ethercalc_cells = ethercalc_cells.split(' ')
if os.path.isfile(filename):
with open(filename, 'r') as fp:
self.data = json.load(fp)
else:
- self.data = {'now': {}, 'next': {}}
+ self.data = {'ethercalc': [], 'now': {}, 'next': {}}
def add_now(self, room, session):
self.data['now'][room] = session
@@ -41,14 +44,19 @@ class PTGDataBase():
self.save()
def from_ethercalc(self):
- # TODO: Load from ethercalc
- pass
+ ethercalc = requests.get(self.ethercalc_url).json()
+ self.data['ethercalc'] = []
+ for cell in self.ethercalc_cells:
+ if 'comment' in ethercalc[cell] and 'datavalue' in ethercalc[cell]:
+ msg = '%s: %s' % (ethercalc[cell]['comment'],
+ ethercalc[cell]['datavalue'])
+ self.data['ethercalc'].append(msg)
def wipe(self):
self.data = {'now': {}, 'next': {}}
self.save()
def save(self):
- # self.from_ethercalc()
+ self.from_ethercalc()
with open(self.filename, 'w') as fp:
json.dump(self.data, fp)