mirror of
https://codeberg.org/langfingaz/bbb-status
synced 2025-04-01 14:56:00 +02:00
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import hashlib
|
|
import requests
|
|
from xml.etree import ElementTree
|
|
|
|
import langfingaz.util.fileUtil as fileUtil
|
|
|
|
|
|
def requestMeetingData() -> str:
|
|
response = requests.get(getRequestUrl())
|
|
if not response.ok:
|
|
raise ValueError("error during request, got status code {}".format(response.status_code))
|
|
|
|
tree = ElementTree.fromstring(response.content)
|
|
if tree.find('returncode').text != 'SUCCESS':
|
|
raise ValueError('error getting API data')
|
|
|
|
return str(response.content, encoding=response.encoding)
|
|
|
|
|
|
def getRequestUrl(api_method: str = 'getMeetings', query_string: str = '') -> str:
|
|
url = getUrl()
|
|
api_url = url + "api/"
|
|
secret = getSecret()
|
|
h = hashlib.sha1((api_method + query_string + secret).encode('utf-8'))
|
|
checksum = h.hexdigest()
|
|
|
|
if len(query_string) > 0:
|
|
query_string += '&'
|
|
|
|
return api_url + api_method + '?' + query_string + 'checksum=' + checksum
|
|
|
|
|
|
def getUrl() -> str:
|
|
filepath = fileUtil.getProjectBaseDir().joinpath("secret").joinpath("url.txt")
|
|
url = fileUtil.readFirstLine(filepath).strip()
|
|
if not url.endswith("/"):
|
|
raise ValueError("url should end with '/'")
|
|
return url
|
|
|
|
|
|
def getSecret() -> str:
|
|
filepath = fileUtil.getProjectBaseDir().joinpath("secret").joinpath("secret.txt")
|
|
secret = fileUtil.readFirstLine(filepath).strip()
|
|
min_length = 12
|
|
if len(secret) <= min_length:
|
|
raise ValueError("secret should be longer than {} characters!".format(min_length))
|
|
return secret
|
|
|