def get_recipe_history(): # authenticate the user if 'mealplanner_auth_token' in request.cookies: email = decode_auth_token(request.cookies['mealplanner_auth_token'])['email'] else: return "must authenticate" return database.get_history(email)
def update_unseen(bot_id, chat_id): urls = db.get_urls(chat_id) history = list(map(lambda ad: ad['id'], db.get_history(chat_id))) if len(urls) == 0: # Not sending messages on purpose. # send_message(bot_id, chat_id, 'There are no registered urls') return process_unseen(bot_id, chat_id, urls, history)
def main(): parser = argparse.ArgumentParser(description="SmartWallet - script " "using database to manage " "your costs") parser.add_argument("-s", "--supply", metavar='N', type=int, help="a float number of sum") parser.add_argument("-b", "--balance", action="store_true", help="get balance from wallet") parser.add_argument("-H", "--history", type=int, nargs='?', const=0, help="get history") parser.add_argument("-d", "--discard", nargs=2, metavar="data", help="set purchase") args = parser.parse_args() if args.supply: db.supply(db.cursor, args.supply) print("Successful supplying!") elif args.balance: bal = db.get_balance(db.cursor) print("You have {0} UAN".format(bal)) elif args.history or args.history == 0: res = db.get_history(db.cursor, args.history) if res: for i in res: print("{1} := {2}".format(*i)) else: print("There is no info yet") elif args.discard: try: n = int(args.discard[0]) except ValueError: print("N is not a number") exit(1) db.discard(db.cursor, n, args.discard[1]) print("Successful discarding!") else: print("Print `--help` or `-h` to find out arguments")
def update_unseen(bot, update): chat_id = update.message.chat_id try: urls = db.get_urls(chat_id) history = list(map(lambda ad: ad['id'], db.get_history(chat_id))) if len(urls) == 0: send_message(bot, chat_id, 'There are no registered urls') return process_unseen(bot, chat_id, urls, history) except Exception as e: print('Error with chat_id: {}'.format(chat_id)) print(traceback.format_exc()) send_message(bot, chat_id, 'There was an error updating unseen')
def home(): city = request.args.get("city") if request.args.get('btn') == "查询": try: result = retrieve_data(city) return render_template('weather.html', result=result) except TypeError: try: location, weather, temper, day = fetchWeather(city) insert_data(location, weather, temper, day) result = ''' 地点: {}, 天气: {}, 温度: {}, 更新时间: {}/n'''.format(location, weather, temper, day) return render_template('weather.html', result=result) except KeyError: result = "Invalid command. Type 'help' to check the available commands." return render_template('404.html', result=result) elif request.args.get('btn') == "帮助": return render_template('help.html') elif request.args.get('btn') == "历史": history = get_history() return render_template('history.html', result=history) elif request.args.get('btn') == "更新": try: location, weather = city.split(' ') weather_list = ["晴", "小雨", "大雨", "阴天", "大雪", "中雪", "小雪"] if weather in weather_list: update(location, weather) return render_template('update.html') else: result = "请正确输入信息,例如:[北京 多云]" return render_template('404.html', result=result) except ValueError: result = "Invalid command. Type 'help' to check the available commands." return render_template('404.html', result=result) else: result = "Invalid command. Type 'help' to check the available commands." return render_template('404.html', result=result)
def create_graph(ip, item): """Bak een grafiek van een item en data.""" plt.clf() # Plot leegmaken, zodat we fris kunnen beginnen. Nodig als de functie al een keer eerder is aangeroepen, maar kan geen kwaad. # TODO RAM Graph fixen ding = agent_module.agent(ip) # Agent module aanroepen. history = database.get_history(ding.ip, item) # Geschiedenis opvragen. history_time = [] history_value = [] for history_item in history: history_time.append(datetime.datetime.fromtimestamp(history_item[0]).strftime("%d-%m %H:%M")) # Tijd mooi maken. history_value.append(history_item[1]) if len(history_value) == 0: # Als er geen geschiedenis is, hoeven we ook geen grafiek te maken. return '' plt.gcf().subplots_adjust(bottom=0.15) # Beetje meer ruimte aan de onderkant maken. plt.plot(history_value, linewidth=2.0) # Tekenen. plt.xticks(range(len(history_time)), history_time, rotation=45) # Dingetjes op de x-as zetten. plt.title(item) plt.ylim(0, plt.ylim()[0] + 5) # Y-as limieten instellen. # Aangezien sommige waardes speciale dingen nodig hebben in de grafiek, hier een lelijke zooi if-jes. if item == 'cpu_load': plt.ylim(0, 100) elif item == 'no_processes': plt.ylim(0, max(history_value) + 10) elif item == 'ram_free': plt.ylim(0, max(history_value) + 100) buf = io.BytesIO() # Met BytesIO kunnen we een variabele misbr... gebruiken als file. plt.savefig(buf, format="png", dpi=48, transparent=True) # Opslaan naar file. buf.seek(0) base64_img = base64.b64encode(buf.getvalue()) #buf.seek(0) #data = buf.read() buf.close() #f = open('copy.png', 'wb') #f.write(data) #f.close() return '<img class="graph" id="%s" src="data:image/png;base64, %s"/>' % (item, base64_img.decode('ASCII'))