version 1.0.0a2: change prints to logger

errors are warning, debug is for spam.
This commit is contained in:
Lili (Tlapka) 2022-11-24 16:06:01 +01:00
parent 528ffa05d8
commit 444601dab8
4 changed files with 29 additions and 27 deletions

View File

@ -2,7 +2,7 @@ from setuptools import find_packages, setup
setup( setup(
name='tlapbot', name='tlapbot',
version='1.0.0a1', version='1.0.0a2',
packages=find_packages(), packages=find_packages(),
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[

View File

@ -40,7 +40,10 @@ def create_app(test_config=None):
def proxy_job(): def proxy_job():
with app.app_context(): with app.app_context():
if is_stream_live(): if is_stream_live():
app.logger.info("Stream is LIVE. Giving points to chat.")
give_points_to_chat(get_db()) give_points_to_chat(get_db())
else:
app.logger.info("Stream is NOT LIVE. (Not giving points to chat.)")
# start scheduler that will give points to users # start scheduler that will give points to users
points_giver = BackgroundScheduler() points_giver = BackgroundScheduler()

View File

@ -7,7 +7,6 @@ from sqlite3 import Error
def is_stream_live(): def is_stream_live():
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/status' url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/status'
r = requests.post(url) r = requests.post(url)
print(r.json()["online"])
return r.json()["online"] return r.json()["online"]
@ -39,8 +38,8 @@ def read_users_points(db, user_id):
) )
return cursor.fetchone()[0] return cursor.fetchone()[0]
except Error as e: except Error as e:
print("Error occured reading points:", e.args[0]) current_app.logger.warning("Error occured reading points:", e.args[0])
print("To user:", user_id) current_app.logger.warning("To user:", user_id)
def read_all_users_with_username(db, username): def read_all_users_with_username(db, username):
@ -52,8 +51,8 @@ def read_all_users_with_username(db, username):
users = cursor.fetchall() users = cursor.fetchall()
return users return users
except Error as e: except Error as e:
print("Error occured reading points from username:", e.args[0]) current_app.logger.warning("Error occured reading points from username:", e.args[0])
print("To user:", username) current_app.logger.warning("To user:", username)
def give_points_to_user(db, user_id, points): def give_points_to_user(db, user_id, points):
@ -64,8 +63,8 @@ def give_points_to_user(db, user_id, points):
) )
db.commit() db.commit()
except Error as e: except Error as e:
print("Error occured giving points:", e.args[0]) current_app.logger.warning("Error occured giving points:", e.args[0])
print("To user:", user_id, " amount of points:", points) current_app.logger.warning("To user:", user_id, " amount of points:", points)
def use_points(db, user_id, points): def use_points(db, user_id, points):
@ -77,8 +76,8 @@ def use_points(db, user_id, points):
db.commit() db.commit()
return True return True
except Error as e: except Error as e:
print("Error occured using points:", e.args[0]) current_app.logger.warning("Error occured using points:", e.args[0])
print("From user:", user_id, " amount of points:", points) current_app.logger.warning("From user:", user_id, " amount of points:", points)
return False return False
@ -92,8 +91,8 @@ def user_exists(db, user_id):
return False return False
return True return True
except Error as e: except Error as e:
print("Error occured checking if user exists:", e.args[0]) current_app.logger.warning("Error occured checking if user exists:", e.args[0])
print("To user:", user_id) current_app.logger.warning("To user:", user_id)
def add_user_to_database(db, user_id, display_name): def add_user_to_database(db, user_id, display_name):
@ -118,8 +117,8 @@ def add_user_to_database(db, user_id, display_name):
) )
db.commit() db.commit()
except Error as e: except Error as e:
print("Error occured adding user to db:", e.args[0]) current_app.logger.warning("Error occured adding user to db:", e.args[0])
print("To user:", user_id, display_name) current_app.logger.warning("To user:", user_id, display_name)
def change_display_name(db, user_id, new_name): def change_display_name(db, user_id, new_name):
@ -130,8 +129,8 @@ def change_display_name(db, user_id, new_name):
) )
db.commit() db.commit()
except Error as e: except Error as e:
print("Error occured changing display name:", e.args[0]) current_app.logger.warning("Error occured changing display name:", e.args[0])
print("To user:", user_id, new_name) current_app.logger.warning("To user:", user_id, new_name)
def add_to_counter(db, counter_name): def add_to_counter(db, counter_name):
@ -142,8 +141,8 @@ def add_to_counter(db, counter_name):
) )
db.commit() db.commit()
except Error as e: except Error as e:
print("Error occured adding to counter:", e.args[0]) current_app.logger.warning("Error occured adding to counter:", e.args[0])
print("To counter:", counter_name) current_app.logger.warning("To counter:", counter_name)
def add_to_redeem_queue(db, user_id, redeem_name, note=None): def add_to_redeem_queue(db, user_id, redeem_name, note=None):
@ -154,8 +153,8 @@ def add_to_redeem_queue(db, user_id, redeem_name, note=None):
) )
db.commit() db.commit()
except Error as e: except Error as e:
print("Error occured adding to redeem queue:", e.args[0]) current_app.logger.warning("Error occured adding to redeem queue:", e.args[0])
print("To user:", user_id, " with redeem:", redeem_name, "with note:", note) current_app.logger.warning("To user:", user_id, " with redeem:", redeem_name, "with note:", note)
def all_counters(db): def all_counters(db):
@ -165,7 +164,7 @@ def all_counters(db):
) )
return cursor.fetchall() return cursor.fetchall()
except Error as e: except Error as e:
print("Error occured selecting all counters:", e.args[0]) current_app.logger.warning("Error occured selecting all counters:", e.args[0])
def pretty_redeem_queue(db): def pretty_redeem_queue(db):
@ -178,7 +177,7 @@ def pretty_redeem_queue(db):
) )
return cursor.fetchall() return cursor.fetchall()
except Error as e: except Error as e:
print("Error occured selecting pretty redeem queue:", e.args[0]) current_app.logger.warning("Error occured selecting pretty redeem queue:", e.args[0])
def whole_redeem_queue(db): def whole_redeem_queue(db):
@ -188,7 +187,7 @@ def whole_redeem_queue(db):
) )
return cursor.fetchall() return cursor.fetchall()
except Error as e: except Error as e:
print("Error occured selecting redeem queue:", e.args[0]) current_app.logger.warning("Error occured selecting redeem queue:", e.args[0])
def remove_duplicate_usernames(db, user_id, username): def remove_duplicate_usernames(db, user_id, username):
@ -201,4 +200,4 @@ def remove_duplicate_usernames(db, user_id, username):
) )
db.commit() db.commit()
except Error as e: except Error as e:
print("Error occured removing duplicate usernames:", e.args[0]) current_app.logger.warning("Error occured removing duplicate usernames:", e.args[0])

View File

@ -1,4 +1,4 @@
from flask import Flask, request, json, Blueprint from flask import Flask, request, json, Blueprint, current_app
from tlapbot.db import get_db from tlapbot.db import get_db
from tlapbot.owncast_helpers import (add_user_to_database, change_display_name, from tlapbot.owncast_helpers import (add_user_to_database, change_display_name,
user_exists, send_chat, read_users_points, remove_duplicate_usernames) user_exists, send_chat, read_users_points, remove_duplicate_usernames)
@ -29,8 +29,8 @@ def owncast_webhook():
elif data["type"] == "CHAT": elif data["type"] == "CHAT":
user_id = data["eventData"]["user"]["id"] user_id = data["eventData"]["user"]["id"]
display_name = data["eventData"]["user"]["displayName"] display_name = data["eventData"]["user"]["displayName"]
print(f'New chat message from {display_name}:') current_app.logger.debug(f'New chat message from {display_name}:')
print(f'{data["eventData"]["body"]}') current_app.logger.debug(f'{data["eventData"]["body"]}')
if "!help" in data["eventData"]["body"]: if "!help" in data["eventData"]["body"]:
send_help() send_help()
elif "!points" in data["eventData"]["body"]: elif "!points" in data["eventData"]["body"]: