Add basic support for loading up ethercalc data
Add base code to load up content from ethercalc (to show what's going on in reservable rooms as well).
This commit is contained in:
parent
048dfc01e2
commit
173c3ba5c4
|
@ -4,4 +4,8 @@ pass=PASSWORD
|
||||||
server=irc.freenode.net
|
server=irc.freenode.net
|
||||||
port=6667
|
port=6667
|
||||||
channels=foo,bar
|
channels=foo,bar
|
||||||
db=html/ptg.json
|
|
||||||
|
[db]
|
||||||
|
filename=html/ptg.json
|
||||||
|
ethercalc=https://ethercalc.openstack.org/_/MyDocumentName/cells
|
||||||
|
cells=E9 E10
|
||||||
|
|
|
@ -47,6 +47,18 @@
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading"><h3 class="panel-title">Planned for today in reservable rooms</h3></div>
|
||||||
|
<table class="table">
|
||||||
|
{{#each ethercalc}}
|
||||||
|
<tr>
|
||||||
|
<td>{{this}}</td>
|
||||||
|
</tr>
|
||||||
|
{{else}}
|
||||||
|
<tr><td><small><i>Nothing yet</i></small><td></tr>
|
||||||
|
{{/each}}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ ANTI_FLOOD_SLEEP = 2
|
||||||
class PTGBot(irc.bot.SingleServerIRCBot):
|
class PTGBot(irc.bot.SingleServerIRCBot):
|
||||||
log = logging.getLogger("ptgbot.bot")
|
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:
|
if port == 6697:
|
||||||
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
||||||
irc.bot.SingleServerIRCBot.__init__(self,
|
irc.bot.SingleServerIRCBot.__init__(self,
|
||||||
|
@ -57,7 +57,7 @@ class PTGBot(irc.bot.SingleServerIRCBot):
|
||||||
self.password = password
|
self.password = password
|
||||||
self.channel_list = channels
|
self.channel_list = channels
|
||||||
self.identify_msg_cap = False
|
self.identify_msg_cap = False
|
||||||
self.data = ptgbot.db.PTGDataBase(dbfile)
|
self.data = db
|
||||||
|
|
||||||
def on_nicknameinuse(self, c, e):
|
def on_nicknameinuse(self, c, e):
|
||||||
self.log.debug("Nickname in use, releasing")
|
self.log.debug("Nickname in use, releasing")
|
||||||
|
@ -158,12 +158,17 @@ def start(configpath):
|
||||||
channels = ['#' + name.strip() for name in
|
channels = ['#' + name.strip() for name in
|
||||||
config.get('ircbot', 'channels').split(',')]
|
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'),
|
bot = PTGBot(config.get('ircbot', 'nick'),
|
||||||
config.get('ircbot', 'pass'),
|
config.get('ircbot', 'pass'),
|
||||||
config.get('ircbot', 'server'),
|
config.get('ircbot', 'server'),
|
||||||
config.getint('ircbot', 'port'),
|
config.getint('ircbot', 'port'),
|
||||||
channels,
|
channels,
|
||||||
config.get('ircbot', 'db'))
|
db)
|
||||||
bot.start()
|
bot.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
18
ptgbot/db.py
18
ptgbot/db.py
|
@ -16,17 +16,20 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class PTGDataBase():
|
class PTGDataBase():
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename, ethercalc_url, ethercalc_cells):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.ethercalc_url = ethercalc_url
|
||||||
|
self.ethercalc_cells = ethercalc_cells.split(' ')
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
with open(filename, 'r') as fp:
|
with open(filename, 'r') as fp:
|
||||||
self.data = json.load(fp)
|
self.data = json.load(fp)
|
||||||
else:
|
else:
|
||||||
self.data = {'now': {}, 'next': {}}
|
self.data = {'ethercalc': [], 'now': {}, 'next': {}}
|
||||||
|
|
||||||
def add_now(self, room, session):
|
def add_now(self, room, session):
|
||||||
self.data['now'][room] = session
|
self.data['now'][room] = session
|
||||||
|
@ -41,14 +44,19 @@ class PTGDataBase():
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def from_ethercalc(self):
|
def from_ethercalc(self):
|
||||||
# TODO: Load from ethercalc
|
ethercalc = requests.get(self.ethercalc_url).json()
|
||||||
pass
|
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):
|
def wipe(self):
|
||||||
self.data = {'now': {}, 'next': {}}
|
self.data = {'now': {}, 'next': {}}
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
# self.from_ethercalc()
|
self.from_ethercalc()
|
||||||
with open(self.filename, 'w') as fp:
|
with open(self.filename, 'w') as fp:
|
||||||
json.dump(self.data, fp)
|
json.dump(self.data, fp)
|
||||||
|
|
Loading…
Reference in New Issue