import requests import xml.etree.ElementTree as ET from models import XRate, peewee_datetime from config import logging, LOGGER_CONFIG log = logging.getLogger('CBRApi') fh = logging.FileHandler(LOGGER_CONFIG['file']) fh.setLevel(LOGGER_CONFIG['level']) fh.setFormatter(LOGGER_CONFIG['formatter']) log.addHandler(fh) log.setLevel(LOGGER_CONFIG['level']) def update_xrates(from_currency, to_currency): log.info(f'Started update for: {from_currency} => {to_currency}') # получение курса из БД xrate = XRate.select().where(XRate.from_currency == from_currency, XRate.to_currency == to_currency).first() log.debug(f'rate before: {xrate}') # получение нового значения от Привата и сохранение его в объект xrate xrate.rate = get_cbr_rate(from_currency) # обновление поля updated xrate.updated = peewee_datetime.datetime.now() xrate.save() log.debug(f'rate after: {xrate}') log.info(f'Finished update for: {from_currency} => {to_currency}')
from models import XRate, peewee_datetime from config import logging, LOGGER_CONFIG log = logging.getLogger("TestApi") fh = logging.FileHandler(LOGGER_CONFIG["file"]) fh.setLevel(LOGGER_CONFIG["level"]) fh.setFormatter(LOGGER_CONFIG["formatter"]) log.addHandler(fh) log.setLevel(LOGGER_CONFIG["level"]) def update_xrates(from_currency, to_currency): log.info("Started update for: %s=>%s" % (from_currency, to_currency)) xrate = XRate.select().where(XRate.from_currency == from_currency, XRate.to_currency == to_currency).first() log.debug("rate before: %s", xrate) xrate.rate += 0.01 xrate.updated = peewee_datetime.datetime.now() xrate.save() log.debug("rate after: %s", xrate) log.info("Finished update for: %s=>%s" % (from_currency, to_currency)) if __name__ == '__main__': update_xrates(840, 980)
break else: if any((drinks_amount == [], ingredients_amount == [])): log.error(f'client has ordered non-existent drink \u2013 {choice_drink=}, {choice_ingredient=}') client_socket.sendall('Sorry, I cannot make it'.encode()) break else: if all((drinks_amount[0][0], ingredients_amount[0][0])): transfer_data(update_menu, choice_drink, choice_ingredient) event.set() log.info(f'client has ordered {choice_drink} with {choice_ingredient}') client_socket.sendall(f'Take your {choice_drink} with {choice_ingredient}'.encode()) break else: log.warning(f'coffe machine has no {choice_drink} or {choice_ingredient}') client_socket.sendall(f'coffe machine has no {choice_drink} or {choice_ingredient}'.encode()) break log.info('client has disconnected') client_socket.close() if __name__ == '__main__': log = logging.getLogger('Coffee machine') log.setLevel(LOGGER_CONFIG['level']) fh = logging.FileHandler(LOGGER_CONFIG['file'], 'w', 'utf-8') fh.setFormatter(LOGGER_CONFIG['formatter']) log.addHandler(fh) initialize_menu() accept_connection(server_socket, lock, event)