rework
This commit is contained in:
parent
e3cce698a0
commit
8df6af5edf
@ -1,8 +1,9 @@
|
|||||||
[tool.bumpversion]
|
[bumpversion]
|
||||||
current_version = "1.2.7"
|
current_version = "0.1.0"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
tag_name = "{new_version}"
|
|
||||||
|
|
||||||
[[tool.bumpversion.files]]
|
[[bumpversion::file]]
|
||||||
filename = "VERSION"
|
filename = "VERSION"
|
||||||
|
search = "{current_version}"
|
||||||
|
replace = "{new_version}"
|
2
app.py
2
app.py
@ -4,7 +4,7 @@ from flask_caching import Cache
|
|||||||
import requests.auth
|
import requests.auth
|
||||||
import os
|
import os
|
||||||
from lib.datetime import filter_accounts_next_30_days, filter_accounts_expired
|
from lib.datetime import filter_accounts_next_30_days, filter_accounts_expired
|
||||||
from lib.reqs import get_urls, get_user_accounts, add_user_account, delete_user_account, get_user_accounts_count, get_stream_names
|
from lib.reqs import get_urls, get_user_accounts, add_user_account, delete_user_account, get_stream_names
|
||||||
from flask import send_from_directory
|
from flask import send_from_directory
|
||||||
import requests
|
import requests
|
||||||
import base64
|
import base64
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
from flask import Flask, jsonify
|
|
||||||
from config import DevelopmentConfig
|
|
||||||
from lib.mysql import execute_query
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
app.config.from_object(DevelopmentConfig)
|
|
||||||
|
|
||||||
@app.route('/getUserAccounts', methods=['GET'])
|
|
||||||
def get_user_accounts():
|
|
||||||
# Use the execute_query function to get user accounts
|
|
||||||
|
|
||||||
data = execute_query("SELECT COUNT(*) AS account_count FROM userAccounts WHERE userID = %s;", (1,))
|
|
||||||
if data is None:
|
|
||||||
return jsonify({"error": "Database query failed"}), 500
|
|
||||||
return jsonify(data), 200
|
|
||||||
|
|
||||||
# Run the app
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run(debug=app.config["DEBUG"], port=app.config["PORT"])
|
|
@ -1,37 +0,0 @@
|
|||||||
import mysql.connector
|
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
def execute_query(query, params=None, fetch_one=False):
|
|
||||||
"""Execute a SQL query and optionally fetch results."""
|
|
||||||
try:
|
|
||||||
# Get database configuration from the current app context
|
|
||||||
db_config = {
|
|
||||||
"host": current_app.config['DBHOST'],
|
|
||||||
"user": current_app.config['DBUSER'],
|
|
||||||
"password": current_app.config['DBPASS'],
|
|
||||||
"database": current_app.config['DATABASE'],
|
|
||||||
}
|
|
||||||
|
|
||||||
# Establish database connection
|
|
||||||
connection = mysql.connector.connect(**db_config)
|
|
||||||
cursor = connection.cursor(dictionary=True)
|
|
||||||
|
|
||||||
# Execute the query with optional parameters
|
|
||||||
cursor.execute(query, params)
|
|
||||||
|
|
||||||
# Fetch results if it's a SELECT query
|
|
||||||
if query.strip().upper().startswith("SELECT"):
|
|
||||||
result = cursor.fetchone() if fetch_one else cursor.fetchall()
|
|
||||||
else:
|
|
||||||
# Commit changes for INSERT, UPDATE, DELETE
|
|
||||||
connection.commit()
|
|
||||||
result = cursor.rowcount # Number of affected rows
|
|
||||||
|
|
||||||
# Close the database connection
|
|
||||||
cursor.close()
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
return result
|
|
||||||
except mysql.connector.Error as err:
|
|
||||||
print("Error: ", err)
|
|
||||||
return None
|
|
@ -3,6 +3,10 @@
|
|||||||
class Config:
|
class Config:
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
BASE_URL = '' # Set your base URL here
|
BASE_URL = '' # Set your base URL here
|
||||||
|
HOST = '0.0.0.0'
|
||||||
|
PORT = 5000
|
||||||
|
OCR_ENABLED = False
|
||||||
|
TEXT_INPUT_ENABLED = False
|
||||||
|
|
||||||
class DevelopmentConfig(Config):
|
class DevelopmentConfig(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
19
lib/reqs.py
19
lib/reqs.py
@ -88,25 +88,6 @@ def add_user_account(base_url: str, auth: str, username: str, password: str, str
|
|||||||
return response.status_code == 200
|
return response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def get_user_accounts_count(base_url: str, auth: str) -> int:
|
|
||||||
"""Get the count of user accounts from the specified base URL.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
base_url (str): The base URL of the API.
|
|
||||||
auth (str): The authorization token for accessing the API.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: The count of user accounts.
|
|
||||||
"""
|
|
||||||
url = f"{base_url}/getUserAccounts/count"
|
|
||||||
payload = {}
|
|
||||||
headers = {"Authorization": f"Basic {auth}"}
|
|
||||||
|
|
||||||
response = requests.request("GET", url, headers=headers, data=payload)
|
|
||||||
res_json = json.loads(response.text)
|
|
||||||
return res_json['count']
|
|
||||||
|
|
||||||
|
|
||||||
def get_stream_names(base_url: str, auth: str) -> List[str]:
|
def get_stream_names(base_url: str, auth: str) -> List[str]:
|
||||||
"""Get a list of stream names from the API.
|
"""Get a list of stream names from the API.
|
||||||
|
|
||||||
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user