def add_liquor_type_recv(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liquor = results['liquor'][0] typ = results['typ'][0] db.add_bottle_type(mfg, liquor, typ) db.save_db('bin/sample_database') taste_of_success = db._check_bottle_type_exists(mfg, liquor) if taste_of_success == True: data = generate_html.generate_liquor_types_html() else: content_type = 'text/html' data = """ <html> <head> <title>Failure to Add Liquor!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """Failed to add Liquor type, please try again!""" data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]
def save_buy_timestamp(qq): db = load_db() if key_buy_time not in db: db[key_buy_time] = {} db[key_buy_time][str(qq)] = format_time(datetime.now()) save_db(db)
def save_database(filename): try: #Try to save database f_name = os.path.dirname(__file__) + filename db.save_db(f_name) print "Saved database" except: print "Unable to save database"
def delete(no=None): if not no: try: no = int(raw_input("输入学员编号:")) except TypeError: print '编号类型错误' delete() db = get_db() try: student = db.pop(no) print '删除[%s]成功' % student.name except KeyError: print '编号不存在' delete() save_db(db)
def add(): info = raw_input('请输入学员信息(姓名,性别,年龄,所在地,qq号)各项信息之间用逗号分隔:') if ',' in info: columns = info.split(',') elif ',' in info: columns = info.split(',') db = get_db() if db: no = max(db.keys()) + 1 # 编号递增 else: no = 1 columns.insert(0, no) student = Student(*columns) db[no] = student save_db(db)
def download_playlist(bid: str, artist: str=None) -> None: """ Downloads a playlist. """ if args.playlist_cache and bid in cache: print(f"Playlist {bid} is cached.") return try: album = ytmusic.get_album(bid) rd = album["releaseDate"] date = f"{rd['year']}-{rd['month']}-{rd['day']}" # assumes playlist is album, this is for an actual playlist except KeyError: album = ytmusic.get_playlist(bid) artist = album["author"] # date is arbitrary because precise playlist creation dates are unknown date = f"{album['year']}-07-10" artists = ", ".join(a["name"] for a in album["artist"]) \ if artist is None else artist title = album["title"] path = artists.replace("/", "-") if len(path) > 0: if not os.path.exists(path): os.mkdir(path) path += "/" path += title.replace("/", "-") if not os.path.exists(path): os.mkdir(path) path += "/" print(f"Downloading playlist {title} with id {bid}") for i, song in enumerate(album["tracks"]): # last element in thumbnails is highest resolution download_song(song["videoId"], parse_artists(song["artists"]), artists, song["title"], title, int(song.get("index", i + 1)), date, path, bid, song["thumbnails"][-1]["url"]) cache.add(bid) db.save_db(cache)
def download_song(sid: str, artist: str=None, album_artist: str=None, title: str="song", album_title: str="", track: int=1, date: str=None, path: str="", pid: str="", thumbnail_url: str=None) -> None: """ Downloads a song. """ if args.cache and f"{pid}|{sid}" in cache: print("Song is cached.") return if sid is None: print("Cannot download song.") return print(f"Downloading song {title} with id {sid}") path = f"{path}{track}_{title.replace('/', '-')}.mp3" if not args.dry: subprocess.run(["youtube-dl", "--add-metadata", "--extract-audio", "--audio-format", "mp3", "--output", "%(id)s.%(ext)s", f"https://www.youtube.com/watch?v={sid}"]) os.rename(f"{sid}.mp3", path) if not args.dry or args.write_tag: f = eyed3.load(path) f.tag.artist = artist f.tag.album = album_title f.tag.album_artist = album_artist f.tag.title = title f.tag.track_num = track # yyyy-mm-dd format for date f.tag.release_date = date # image types documented here: https://eyed3.readthedocs.io/en/latest/eyed3.id3.html#eyed3.id3.frames.ImageFrame r = requests.get(thumbnail_url) imagedata = r.content f.tag.images.set(1, imagedata, "image/jpeg", "icon image", None) f.tag.save() cache.add(f"{pid}|{sid}") db.save_db(cache)
def add_a_new_recipe_recv(self, environ, start_response): print "in add_a_new_recipe_recv" formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) name = results['name'][0] ings = results['ings'][0] indv_ings = ings.split(',') ind_list =[] for item in indv_ings: myTup = tuple(item.split(':')) ind_list.append(myTup) recipe = recipes.Recipe(name,ind_list) db.add_recipe(recipe) db.save_db('bin/sample_database') taste_of_success = db.get_recipe(name) if taste_of_success == recipe: data = generate_html.generate_recipes_html() else: content_type = 'text/html' data = """ <html> <head> <title>Failure to add recipe!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """Failed to add Recipe, please try again!""" data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]
def add_to_inventory_recv(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liquor = results['liquor'][0] amount = results['amount'][0] myBool = db.check_inventory(mfg,liquor) if myBool == True: intial_amt = db.get_liquor_amount(mfg,liquor) else: intial_amt = 0 db.add_to_inventory(mfg, liquor, amount) db.save_db('bin/sample_database') taste_of_success = db.check_inventory(mfg, liquor) amt_success = db.get_liquor_amount(mfg,liquor) if taste_of_success == True and amt_success > intial_amt: data = generate_html.generate_liquor_types_html() else: content_type = 'text/html' data = """ <html> <head> <title>Failure to Add Liquor!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """Failed to add Liquor type, please try again!""" data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]
def update(no=None): if not no: try: no = int(raw_input("输入学员编号:")) except TypeError: print '编号类型错误' update() info = raw_input('请输入学员信息(姓名,性别,年龄,所在地,qq号)各项信息之间用逗号分隔:') if ',' in info: columns = info.split(',') elif ',' in info: columns = info.split(',') columns = map(str.strip, columns) db = get_db() columns.insert(0, no) student = Student(*columns) db[no] = student save_db(db)
ra_s = tk.Entry(c_ra, width=5, validate='key') ra_s['validatecommand'] = (ra_s.register(validate), '%P', 5) dec_h = tk.Entry(c_dec, width=3, validate='key') dec_h['validatecommand'] = (dec_h.register(validate), '%P', 3) dec_m = tk.Entry(c_dec, width=2, validate='key') dec_m['validatecommand'] = (dec_m.register(validate), '%P', 2) dec_s = tk.Entry(c_dec, width=5, validate='key') dec_s['validatecommand'] = (dec_s.register(validate), '%P', 5) ra_t = ra_h, ra_m, ra_s dec_t = dec_h, dec_m, dec_s c_use = tk.Button(c, text='Use', command=lambda: use(c_name.get(), ra_t, dec_t)) c_save = tk.Button(c, text='Save...', command=lambda: save_db(root, c_name.get(), ra_t, dec_t)) # Align Section Widgets o_name = tk.StringVar(c, 'No Object Selected') o_ra = tk.StringVar(c, '---') o_dec = tk.StringVar(c, '---') o_ha = tk.StringVar(c, '---') o_track = tk.IntVar() o_target = tk.Checkbutton(o, text=' Track Object', var=o_track) o_target.bind('<ButtonRelease-1>', lambda event: track_s(o_name)) o_align = tk.Button(o, text='Align on Object', command=confirm_align) o_log = tk.Listbox(o, width=40, bg='dark gray', height=12) # Information Section Widgets s_target = tk.StringVar(s, '---') s_time = tk.StringVar(s, '---')