def put(self): # /admin/rechnungslauf data = request.get_json() settings = SystemSetting.get_settings() connection = pika.BlockingConnection( pika.ConnectionParameters(host="localhost")) channel = connection.channel() channel.queue_declare(queue="email") for each in data: settings = SystemSetting.get_settings() logging.warning(f"Using: {each}") logging.warning( f"username: {each['username']}, coffee_count: {each['coffee_count']}" ) obj = { "username": "", "email": "", "coffee_count": "", "betrag": "" } logging.warning("Rechne new_coffee_count aus") new_coffee_count = RechnungsApi.count(each['coffee_count']) if new_coffee_count is None: new_coffee_count = int(0) logging.warning(f"New coffee count: {new_coffee_count}") logging.warning("Getting user") user = User.find_by_username(each['username']) logging.warning(f"Found user: {user.username}") logging.warning(f"User coffee count: {user.coffee_count}") temp_var = user.coffee_count - new_coffee_count logging.warning(f"Temporary coffee_count: {temp_var}") user.coffee_count = temp_var user.save() obj["username"] = user.username obj["email"] = user.email obj["coffee_count"] = new_coffee_count obj["betrag"] = new_coffee_count * settings.kaffee_preis logging.warning(f"obj: {obj}") user = User.find_by_username(each['username']) logging.warning(f"Neuer User coffee counter: {user.coffee_count}") channel.basic_publish(exchange="", routing_key="email", body=json.dumps(obj)) connection.close() return { "message": "Die Daten wurden gespeichert und Emails werden versendet." }, 201
def systemSettings(): if not SystemSetting.get_settings(): print("System Email") system_email = input(prompt) print("Email Password") email_password = input(prompt) print("SMTP HOST") smtp_host = input(prompt) print("SMTP PORT") smtp_port = input(prompt) port = int(smtp_port) print("TLS?") email_tls = input("yes/no?") if email_tls.lower() == "yes": email_tls = True else: email_tls = False settings = SystemSetting(system_email, email_password, smtp_host, port, email_tls) settings.save() print("System Einstellungen angelegt.") else: print("System Einstellungen existieren bereits.")
def get(self): response = {} settings = SystemSetting.get_settings() schema = SystemSettingSchema() response['status'] = "OK" response['system_settings'] = schema.dump(settings).data return response, 200
def put(self): response = {} schema = SystemSettingSchema() settings = SystemSetting.query.filter_by(id=1) settings.update(request.json) db.session.commit() response["status"] = "OK" settings = SystemSetting.get_settings() response["system_settings"] = schema.dump(settings).data return response, 200
def post(self): tracks = {} "Record the passed list" data = request.get_json() tracks['recordList'] = data['recordList'] settings = SystemSetting.get_settings() schema = SystemSettingSchema() connection = pika.BlockingConnection( pika.ConnectionParameters(host="rabbit")) channel = connection.channel() channel.queue_declare(queue="recorder") tracks['settings'] = schema.dump(settings).data for record in tracks['recordList']: obj = { "trackname": record['name'], "id": record['id'], "duration_ms": record['duration_ms'], "settings": { "framesize": tracks['settings']['framesize'], "driver_path": tracks['settings']['driver_path'], "profile_path": tracks['settings']['profile_path'] } } for t in record['album']['artists']: obj['artist'] = t['name'] json_data = json.dumps(obj) channel.basic_publish(exchange="", routing_key="recorder", body=json_data) connection.close() return { "message": "Jobs wurden erstellt. Nachricht wird verstand wenn fertig." }, 201