-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
60 lines (48 loc) · 1.99 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from sqlalchemy import text, create_engine
from email_validator import validate_email, EmailNotValidError
import pandas as pd
class Service():
def sr_year_profit(self, db, tiker_name): # доходность по месяцам одного тикера
db[tiker_name] = db['close'].pct_change()
return db
def registed(self, email, password):
engine = create_engine("postgresql://fgvqsuuw:fziWIx4G-xu3bPvFa4zVSo1TIPZf7Vyc@mel.db.elephantsql.com/fgvqsuuw")
try:
validate_email(email)
data = pd.read_sql_query(sql=text(f"SELECT * FROM user_auth WHERE email = '{email}'"), con=engine.connect())
if len(data) != 0:
return False
data = pd.DataFrame(data={'email': [email], 'password': [password]})
data = data.set_index('email')
data.to_sql(f'user_auth', engine, if_exists='append')
return True
except EmailNotValidError as Err:
return False
def login(self, email, password):
engine = create_engine("postgresql://fgvqsuuw:fziWIx4G-xu3bPvFa4zVSo1TIPZf7Vyc@mel.db.elephantsql.com/fgvqsuuw")
try:
validate_email(email)
data = pd.read_sql_query(sql=text(f"SELECT * FROM user_auth WHERE email = '{email}'"), con=engine.connect())
if len(data) == 0:
return False
if data['password'][0] != password:
return False
return True
except EmailNotValidError as Err:
return False
def sendUserData(self, login, password, type):
res = ''
if type == 'login':
res = self.login(login, password)
else:
res = self.registed(login, password)
if res:
with open('session.txt', 'w') as f:
f.write('auth')
return res
def checkUserSession(save):
try:
session = open("session.txt")
return True
except:
return False