def save_image(data, category, olid, author=None, ip=None, source_url=None): """Save the provided image data, creates thumbnails and adds an entry in the database. ValueError is raised if the provided data is not a valid image. """ prefix = make_path_prefix(olid) img = write_image(data, prefix) if img is None: raise ValueError("Bad Image") d = web.storage({ 'category': category, 'olid': olid, 'author': author, 'source_url': source_url, }) d['width'], d['height'] = img.size filename = prefix + '.jpg' d['ip'] = ip d['filename'] = filename d['filename_s'] = prefix + '-S.jpg' d['filename_m'] = prefix + '-M.jpg' d['filename_l'] = prefix + '-L.jpg' d.id = db.new(**d) return d
def POST(self, category): i = web.input('olid', author=None, file={}, source_url=None, success_url=None, failure_url=None) success_url = i.success_url or web.ctx.get('HTTP_REFERRER') or web.ctx.fullpath failure_url = i.failure_url or web.ctx.get('HTTP_REFERRER') or web.ctx.fullpath def error((code, msg)): url = changequery(failure_url, errcode=code, errmsg=msg) raise web.seeother(url) if i.source_url: try: data = download(i.source_url) except: error(ERROR_INVALID_URL) source_url = i.source_url elif i.file is not None and i.file != {}: data = i.file.value source_url = None else: error(ERROR_EMPTY) if not data: error(ERROR_EMPTY) try: img = load_image(data) except IOError: error(ERROR_BAD_IMAGE) d = { 'category': category, 'olid': i.olid, 'author': i.author, 'source_url': source_url, } d['width'], d['height'] = img.size filename = _disk.write(data, d) d['ip'] = web.ctx.ip d['filename'] = filename db.new(**d) raise web.seeother(success_url)
def new(username, password): if(db.new(username, password)): return True else: return False
bot_item_0 = db.new_item('bot',user_uid=user_uuid,bot_tgid='XXMETXWP') db.new_item('bot',user_uid=user_uuid,bot_tgid='WLNSRWBL') bot_item_list = db.get_item_list('bot',user_uid=user_uuid) assert(len(bot_item_list)==3) db.rm_item('bot',bot_item_0['UUIDD']) bot_item_list = db.get_item_list('bot',user_uid=user_uuid) assert(len(bot_item_list)==2) ######## # CHAT db.new('chat',user_tgid='1234',bot_tgid='DROPYXLW',chat_tgid='MEQWHMSC') chat_item = db.get('chat',user_tgid='1234',bot_tgid='DROPYXLW',chat_tgid='MEQWHMSC') assert(chat_item!=None) #print(f'chat_item = {chat_item}') #db_chat.new_chat('1234:DROPYXLW','FSSMUDAA') #db_chat.new_chat('1234:DROPYXLW','JDGARDNH') db.new('chat',user_tgid='1234',bot_tgid='DROPYXLW',chat_tgid='FSSMUDAA') db.new('chat',user_tgid='1234',bot_tgid='DROPYXLW',chat_tgid='JDGARDNH') chat_item_list = db_chat.get_chat_list_from_bot('1234:DROPYXLW') assert(len(chat_item_list)==3) db_chat.rm_chat('1234:DROPYXLW:FSSMUDAA')