make function for making accounts
probably worst code yet Signed-off-by: n <n@noreply.localhost>
This commit is contained in:
parent
e9d2361a2a
commit
7775248c03
1 changed files with 27 additions and 0 deletions
|
@ -2,7 +2,9 @@ import sqlalchemy
|
||||||
import sqlalchemy.orm
|
import sqlalchemy.orm
|
||||||
from sqlalchemy import Table, Column, Integer, String, MetaData
|
from sqlalchemy import Table, Column, Integer, String, MetaData
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from sqlalchemy.sql import text
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
with open('config.json', 'r') as file:
|
with open('config.json', 'r') as file:
|
||||||
config = json.load(file)
|
config = json.load(file)
|
||||||
|
@ -25,6 +27,31 @@ users = Table(
|
||||||
Column('id', Integer, primary_key = True),
|
Column('id', Integer, primary_key = True),
|
||||||
Column('name', String),
|
Column('name', String),
|
||||||
Column('password', String),
|
Column('password', String),
|
||||||
|
Column('email', String)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class User(Base):
|
||||||
|
__tablename__ = 'users'
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
name = Column(String)
|
||||||
|
password = Column(String)
|
||||||
|
email = Column(String)
|
||||||
|
|
||||||
metadata.create_all(engine)
|
metadata.create_all(engine)
|
||||||
|
|
||||||
|
def next_id():
|
||||||
|
id = session.execute(text('SELECT MAX(id) FROM users'))
|
||||||
|
ok = str(id.fetchall())
|
||||||
|
id_parsed = ''.join(char for char in ok if char.isdigit())
|
||||||
|
id_parsed = int(id_parsed)
|
||||||
|
id_parsed = id_parsed + 1
|
||||||
|
return str(id_parsed)
|
||||||
|
|
||||||
|
print(next_id())
|
||||||
|
|
||||||
|
def create_user(name, password):
|
||||||
|
new_user = User(id=next_id(), name=name, password=password)
|
||||||
|
session.add(new_user)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
# create_user("test3", "test3")
|
||||||
|
|
Loading…
Add table
Reference in a new issue