forked from wownero/YellWOWPages
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
from icecream import install, ic
|
|
|
|
from classes.constraints import Constraints
|
|
|
|
app = Flask(__name__)
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = Constraints.uri
|
|
db = SQLAlchemy(app, session_options={'autocommit': False})
|
|
|
|
|
|
class Users(db.Model):
|
|
__tablename__ = 'wowusers'
|
|
username = db.Column(db.VARCHAR(32), primary_key=True)
|
|
address = db.Column(db.CHAR(97), nullable=False)
|
|
|
|
@staticmethod
|
|
def get_address(username):
|
|
user_data = {}
|
|
try:
|
|
user_data.update({Users.query.filter_by(username=username).first().username:
|
|
Users.query.filter_by(username=username).first().address})
|
|
except AttributeError:
|
|
return user_data
|
|
return user_data
|
|
|
|
@staticmethod
|
|
def get_all():
|
|
users_data = {}
|
|
for user in Users.query.all():
|
|
users_data.update({user.username: user.address})
|
|
return users_data
|
|
|
|
@staticmethod
|
|
def get_matches(username):
|
|
user_data = {}
|
|
try:
|
|
for i in range(3):
|
|
user = Users.query.filter(Database.Users.username.like(f'%{username}%'))[i]
|
|
user_data.update({user.username: user.address})
|
|
except IndexError:
|
|
return user_data
|
|
return user_data
|
|
|
|
|
|
class Database:
|
|
Users = Users
|
|
sqla = db
|
|
|
|
|
|
db.create_all()
|
|
ic('db done')
|