Facilitate Ethercalc cells specification
Rather than have to list every Ethercalc cell (and add comments to every such cell to indicate room/time), describe the shape of the ethercalc and automate retrieval of information. Change-Id: I6939a1a7c5706d6f67b03b07ed11d9daf8c297c9
This commit is contained in:
parent
f5906ccfe5
commit
a6fde630ba
|
@ -1,10 +1,40 @@
|
|||
{
|
||||
"irc_nick": "NICK",
|
||||
"irc_pass": "PASS",
|
||||
"irc_server": "irc.freenode.net",
|
||||
"irc_port": 6667,
|
||||
"irc_channel": "#mychannel",
|
||||
"db_filename": "html/ptg.json",
|
||||
"ethercalc_url": "https://ethercalc.openstack.org/_/YOURDOC/cells",
|
||||
"ethercalc_cells": ["E9", "E10", "E11"]
|
||||
"irc_nick": "NICK",
|
||||
"irc_pass": "",
|
||||
"irc_server": "irc.freenode.net",
|
||||
"irc_port": 6667,
|
||||
"irc_channel": "#CHANNEL",
|
||||
"db_filename": "html/ptg.json",
|
||||
"ethercalc_url": "https://ethercalc.openstack.org/_/MYDOC/cells",
|
||||
"ethercalc_cells": {
|
||||
"room_line": "8",
|
||||
"time_column": "A",
|
||||
"time_range": [ 9, 24 ],
|
||||
"days": [
|
||||
{
|
||||
"B": ["14", "15", "16"],
|
||||
"C": [],
|
||||
"D": []
|
||||
},
|
||||
{
|
||||
"E": ["14", "15", "16"],
|
||||
"F": [],
|
||||
"G": []
|
||||
},
|
||||
{
|
||||
"H": ["14", "15", "16"],
|
||||
"I": [],
|
||||
"J": []
|
||||
},
|
||||
{
|
||||
"K": ["14", "15", "16"],
|
||||
"L": [],
|
||||
"M": []
|
||||
},
|
||||
{
|
||||
"N": [],
|
||||
"O": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
import requests
|
||||
|
||||
|
||||
|
@ -21,15 +22,30 @@ class Ethercalc():
|
|||
|
||||
def __init__(self, url, cells_spec):
|
||||
self.url = url
|
||||
self.cells = cells_spec
|
||||
self.room_line = cells_spec['room_line']
|
||||
self.time_column = cells_spec['time_column']
|
||||
time_range = range(cells_spec['time_range'][0],
|
||||
cells_spec['time_range'][1])
|
||||
self.times = [str(i) for i in time_range]
|
||||
self.days = cells_spec['days']
|
||||
|
||||
def load(self):
|
||||
doc = requests.get(self.url).json()
|
||||
ret = []
|
||||
for cell in self.cells:
|
||||
if ('comment' in doc[cell] and
|
||||
'datavalue' in doc[cell]):
|
||||
msg = '%s: %s' % (doc[cell]['comment'],
|
||||
doc[cell]['datavalue'])
|
||||
ret.append(msg)
|
||||
today = datetime.datetime.today().weekday()
|
||||
if len(self.days) <= today:
|
||||
return ret
|
||||
for time in self.times:
|
||||
for room, exclusions in self.days[today].items():
|
||||
if time not in exclusions:
|
||||
datacell = room + time
|
||||
roomcell = room + self.room_line
|
||||
timecell = self.time_column + time
|
||||
if doc[datacell]['datavalue']:
|
||||
msg = '%s, %s: %s' % (
|
||||
doc[timecell]['datavalue'],
|
||||
doc[roomcell]['datavalue'],
|
||||
doc[datacell]['datavalue'],
|
||||
)
|
||||
ret.append(msg)
|
||||
return ret
|
||||
|
|
Loading…
Reference in New Issue