Browse Source

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).
changes/56/473756/1
Thierry Carrez 4 years ago
parent
commit
173c3ba5c4
4 changed files with 38 additions and 9 deletions
  1. +5
    -1
      config.ini.sample
  2. +12
    -0
      html/ptg.html
  3. +8
    -3
      ptgbot/bot.py
  4. +13
    -5
      ptgbot/db.py

+ 5
- 1
config.ini.sample View File

@ -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

+ 12
- 0
html/ptg.html View File

@ -47,6 +47,18 @@
{{/each}}
</table>
</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>


+ 8
- 3
ptgbot/bot.py View File

@ -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()


+ 13
- 5
ptgbot/db.py View File

@ -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)

Loading…
Cancel
Save