def topic(self, room_name, topic): data = {'request': {'room': {'topic': topic}}} self._get_data('room/%(room_id)i.json', self._locate_room(room_name), 'set topic', method='PUT', headers={'Content-Type': 'application/json'}, postdata=json.dumps(data))
def say(self, room_name, message, type='TextMessage'): data = { 'message': { 'body': message, 'type': type, } } self._get_data('room/%(room_id)i/speak.json', self._locate_room(room_name), 'speak', method='POST', headers={'Content-Type': 'application/json'}, postdata=json.dumps(data))
def write_minutes(self, event): if not event.public: event.addresponse(u'Sorry, must be done in public') return if (event.source, event.channel) not in meetings: event.addresponse(u'Sorry, no meeting in progress.') return meeting = meetings[(event.source, event.channel)] meeting['attendees'].update((e['nick'], None) for e in meeting['log'] if e['nick'] not in meeting['attendees'] and e['nick'] != ibid.config['botname']) render_to = set() if self.logurl is None: render_to.add('txt') render_to.update(self.formats) minutes = {} for format in render_to: if format == 'json': class DTJSONEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, datetime): return o.strftime('%Y-%m-%dT%H:%M:%SZ') return json.JSONEncoder.default(self, o) minutes[format] = json.dumps(meeting, cls=DTJSONEncoder, indent=2) else: template = templates.get_template('meetings/minutes.' + format) minutes[format] = template.render(meeting=meeting) \ .encode('utf-8') filename = self.logfile % { 'source': event.source.replace('/', '-'), 'channel': meeting['channel'].replace('/', '-'), 'date': meeting['starttime'].strftime(self.date_format), 'format': format, } filename = join(ibid.options['base'], expanduser(filename)) try: makedirs(dirname(filename), int(self.dir_mode, 8)) except OSError, e: if e.errno != EEXIST: raise e f = open(filename, 'w+') chmod(filename, int(self.file_mode, 8)) f.write(minutes[format]) f.close()
def obj_log(self): self.obj_file.write( '%s %s\n' % (datetime.utcnow().isoformat(), json.dumps(objgraph.typestats()))) self.obj_file.flush()
kwargs = {} for key, value in request.args.items(): try: value = json.loads(value[0]) except ValueError, e: value = value[0] kwargs[key] = value function = self.get_function(request) if not function: return "Not found" try: result = function(*args, **kwargs) return json.dumps(result) except Exception, e: return json.dumps({'exception': True, 'message': unicode(e)}) def render_GET(self, request): function = self.get_function(request) if not function: functions = [] for name, method in getmembers(self, ismethod): if name.startswith('remote_'): functions.append(name.replace('remote_', '', 1)) return self.list.render(object=self.features[0], functions=functions) \ .encode('utf-8') args, varargs, varkw, defaults = getargspec(function)
def obj_log(self): self.obj_file.write('%s %s\n' % ( datetime.utcnow().isoformat(), json.dumps(objgraph.typestats()) )) self.obj_file.flush()