Full completed project
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
android-client/modules/session/__pycache__/time.cpython-310.pyc
Normal file
BIN
android-client/modules/session/__pycache__/time.cpython-310.pyc
Normal file
Binary file not shown.
BIN
android-client/modules/session/__pycache__/time.cpython-311.pyc
Normal file
BIN
android-client/modules/session/__pycache__/time.cpython-311.pyc
Normal file
Binary file not shown.
143
android-client/modules/session/session.py
Normal file
143
android-client/modules/session/session.py
Normal file
@@ -0,0 +1,143 @@
|
||||
import time
|
||||
import sqlite3
|
||||
from android.storage import app_storage_path
|
||||
root_path = app_storage_path()
|
||||
|
||||
class session_info():
|
||||
def __init__(self):
|
||||
self._logged_in = False
|
||||
self.username = None
|
||||
self.server_code = None
|
||||
self.cycle_count = 0
|
||||
self.auth_tokens = []
|
||||
self.transfer = None
|
||||
self.status = None
|
||||
|
||||
@property
|
||||
def logged_in(self):
|
||||
return self._logged_in
|
||||
@logged_in.setter
|
||||
def logged_in(self, value):
|
||||
self._logged_in = value
|
||||
self.cycle_count += 1
|
||||
|
||||
@property
|
||||
def transfer(self):
|
||||
return self._transfer
|
||||
@transfer.setter
|
||||
def transfer(self, value):
|
||||
self._transfer = value
|
||||
self.cycle_count += 1
|
||||
|
||||
def clear(self):
|
||||
db().execute("DELETE FROM tokens WHERE username = ?", (self.username,))
|
||||
self.__init__()
|
||||
|
||||
class wait():
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
self.last = self.session.cycle_count
|
||||
self.current = self.session.cycle_count
|
||||
|
||||
def current_update(self):
|
||||
self.current = self.session.cycle_count
|
||||
|
||||
def wait(self, status=None):
|
||||
while self.last == self.current:
|
||||
time.sleep(0.05)
|
||||
self.current_update()
|
||||
return
|
||||
|
||||
def wait_username(self):
|
||||
while not self.session.username:
|
||||
time.sleep(0.05)
|
||||
return
|
||||
|
||||
class db():
|
||||
def __init__(self):
|
||||
self.path = root_path + "/data/database.db"
|
||||
self._create()
|
||||
|
||||
def _create(self):
|
||||
con, cur = self._connect()
|
||||
|
||||
cur.execute("""CREATE TABLE IF NOT EXISTS tokens (
|
||||
token TEXT NOT NULL PRIMARY KEY,
|
||||
username TEXT NOT NULL,
|
||||
expire TEXT NOT NULL
|
||||
)""")
|
||||
|
||||
cur.execute("""CREATE TABLE IF NOT EXISTS settings (
|
||||
title TEXT NOT NULL PRIMARY KEY,
|
||||
description TEXT,
|
||||
state BOOL,
|
||||
value TEXT,
|
||||
icon TEXT
|
||||
)""")
|
||||
|
||||
self._close(con)
|
||||
|
||||
def _connect(self):
|
||||
con = sqlite3.connect(self.path)
|
||||
cur = con.cursor()
|
||||
return con, cur
|
||||
|
||||
def execute(self, command, values=None):
|
||||
# we use this method so that closing and connecting to the datbase is abstracted away
|
||||
rez = None
|
||||
con, cur = self._connect()
|
||||
|
||||
if values:
|
||||
cur.execute(command, values)
|
||||
else:
|
||||
cur.execute(command)
|
||||
|
||||
if "SELECT" in command:
|
||||
rez = cur.fetchall()
|
||||
|
||||
self._close(con)
|
||||
if rez:
|
||||
return rez
|
||||
|
||||
def _commit(self, con):
|
||||
con.commit()
|
||||
|
||||
def _close(self, con):
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
class setting():
|
||||
def __init__(self, title):
|
||||
self.title = title
|
||||
self.db = db()
|
||||
self.__fetch()
|
||||
|
||||
def __fetch(self):
|
||||
setting_data = self.db.execute("SELECT * FROM settings WHERE title = ?", (self.title,))
|
||||
if setting_data:
|
||||
self.title = setting_data[0][0]
|
||||
self.description = setting_data[0][1]
|
||||
if not self.description:
|
||||
self.description = ""
|
||||
|
||||
if setting_data[0][3] != None:
|
||||
self.value = setting_data[0][3]
|
||||
self.type = "text_field"
|
||||
else:
|
||||
self.value = setting_data[0][2]
|
||||
self.type = "swtich"
|
||||
|
||||
if setting_data[0][4] != None:
|
||||
self.icon = setting_data[0][4]
|
||||
else:
|
||||
self.icon = "cog"
|
||||
|
||||
def change_value(self, new_value):
|
||||
if self.type == "swtich" and isinstance(new_value, bool):
|
||||
self.db.execute("UPDATE settings SET state = ?", (new_value,))
|
||||
elif self.type == "text_field" and isinstance(new_value, str):
|
||||
self.db.execute("UPDATE settings SET value = ?", (new_value,))
|
||||
|
||||
63
android-client/modules/session/time.py
Normal file
63
android-client/modules/session/time.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from datetime import date, timedelta, datetime
|
||||
|
||||
class timestamp():
|
||||
@property
|
||||
def start(self):
|
||||
value = self.get_date_timestamp()
|
||||
self._start = value
|
||||
return self._start
|
||||
@start.setter
|
||||
def start(self, value):
|
||||
value = self.get_date_timestamp()
|
||||
self._start = value
|
||||
|
||||
@property
|
||||
def end(self):
|
||||
value = self.get_date_timestamp(day_mod=1) - 1
|
||||
self._end = value
|
||||
return self._end
|
||||
@end.setter
|
||||
def end(self, value):
|
||||
value = self.get_date_timestamp(day_mod=1) - 1
|
||||
self._end = value
|
||||
|
||||
@property
|
||||
def now(self):
|
||||
value = self.get_timestamp()
|
||||
self._now = value
|
||||
return value
|
||||
@now.setter
|
||||
def now(self, value):
|
||||
value = self.get_timestamp()
|
||||
self._now = value
|
||||
|
||||
@property
|
||||
def date(self):
|
||||
date = str(datetime.now().date())
|
||||
self._date = date
|
||||
return self._date
|
||||
@date.setter
|
||||
def date(self, value):
|
||||
self._date = value
|
||||
|
||||
def get_date_timestamp(self, year_mod=0, month_mod=0, day_mod=0, *args, **kwargs):
|
||||
modifier = [year_mod, month_mod, day_mod]
|
||||
|
||||
now_mod = (datetime.now()+timedelta(days=day_mod))
|
||||
date = (str(now_mod.date()).replace("-0", "-")).split("-")
|
||||
date = [int(string) for string in date]
|
||||
|
||||
timestamp = datetime(date[0], date[1], date[2]).timestamp()
|
||||
|
||||
return timestamp
|
||||
|
||||
def get_timestamp(self):
|
||||
now = (float(datetime.now().timestamp()))
|
||||
return now
|
||||
|
||||
def get_date(self, timestamp):
|
||||
date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
|
||||
return date
|
||||
|
||||
def get_days_month(self, month, year):
|
||||
pass
|
||||
Reference in New Issue
Block a user