split out requests to owncast_requests.py
This commit is contained in:
@@ -1,37 +1,7 @@
|
||||
from flask import current_app
|
||||
import requests
|
||||
from sqlite3 import Error
|
||||
from re import sub
|
||||
|
||||
# # # requests stuff # # #
|
||||
def is_stream_live():
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/status'
|
||||
try:
|
||||
r = requests.get(url)
|
||||
except requests.exceptions.RequestException as e:
|
||||
current_app.logger.error(f"Error occured checking if stream is live: {e.args[0]}")
|
||||
return False
|
||||
return r.json()["online"]
|
||||
|
||||
|
||||
def give_points_to_chat(db):
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/clients'
|
||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||
r = requests.get(url, headers=headers)
|
||||
unique_users = set(map(lambda user_object: user_object["user"]["id"], r.json()))
|
||||
for user_id in unique_users:
|
||||
give_points_to_user(db,
|
||||
user_id,
|
||||
current_app.config['POINTS_AMOUNT_GIVEN'])
|
||||
|
||||
|
||||
def send_chat(message):
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/chat/send'
|
||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||
r = requests.post(url, headers=headers, json={"body": message})
|
||||
return r.json()
|
||||
|
||||
|
||||
# # # db stuff # # #
|
||||
def read_users_points(db, user_id):
|
||||
"""Errors out if user doesn't exist."""
|
||||
|
||||
Reference in New Issue
Block a user