-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb_handle_file.py
More file actions
92 lines (87 loc) · 4.74 KB
/
b_handle_file.py
File metadata and controls
92 lines (87 loc) · 4.74 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from important_variables import BASE_DIR, BUFFET_EXTENSIONS_PATH, THEME_PATH, DATABASE_PATH, ALGORITHM_PATH, LANGUAGE_PATH, BUFFET_EXTENSIONS_PATH
from os import mkdir, listdir
from urllib.request import urlretrieve
from shutil import rmtree
import sqlite3
from os.path import exists
def create_files_and_folders() -> None:
'''Creates required files and folders.'''
try:
try:
mkdir(BASE_DIR)
except FileExistsError:
pass
mkdir(BASE_DIR+'/data')
mkdir(BASE_DIR+"/data/text")
mkdir(BASE_DIR+"/data/trainer")
if not exists(THEME_PATH):
with open(THEME_PATH, "w") as file:
file.write("Light,Blue,False")
if not exists(LANGUAGE_PATH):
with open(LANGUAGE_PATH, "w") as file:
file.write("eng")
db = sqlite3.connect(DATABASE_PATH)
try:
db.execute('CREATE TABLE buyers (name text, id int, school text, class text, charge int)')
except:
pass
try:
db.execute('CREATE TABLE users (name text, password text, email text, type text, is_current text)')
except:
pass
try:
db.execute('CREATE TABLE logs (name text, operation text, price int, date datetime, products text, user_name text)')
except:
pass
try:
db.execute('CREATE TABLE schools_classes (school text, classes text)')
except:
pass
try:
db.execute('CREATE TABLE products (name text, code int, price int, count int)')
except:
pass
try:
mkdir(BUFFET_EXTENSIONS_PATH)
except FileExistsError:
pass
except FileExistsError:
pass
def download_files() -> bool:
'''Downloads extensions from internet. returns False when internet error.'''
files = set(listdir(BUFFET_EXTENSIONS_PATH))
if not len(files) == 11:
rmtree(BUFFET_EXTENSIONS_PATH)
mkdir(BUFFET_EXTENSIONS_PATH)
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/haarcascade_frontalface_alt.xml',
ALGORITHM_PATH)
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/iransans.ttf',
BUFFET_EXTENSIONS_PATH+'/iransans.ttf')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/icon.ico',
BUFFET_EXTENSIONS_PATH+'/icon.ico')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/notice_for_login_with_account_eng.html',
BUFFET_EXTENSIONS_PATH+'/notice_for_login_with_account_eng.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/notice_for_login_with_account_per.html',
BUFFET_EXTENSIONS_PATH+'/notice_for_login_with_account_per.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/notify_creator_about_new_user_eng.html',
BUFFET_EXTENSIONS_PATH+'/notify_creator_about_new_user_eng.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/notify_creator_about_new_user_per.html',
BUFFET_EXTENSIONS_PATH+'/notify_creator_about_new_user_per.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/say_welcome_to_new_user_eng.html',
BUFFET_EXTENSIONS_PATH+'/say_welcome_to_new_user_eng.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/say_welcome_to_new_user_per.html',
BUFFET_EXTENSIONS_PATH+'/say_welcome_to_new_user_per.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/send_code_for_verification_eng.html',
BUFFET_EXTENSIONS_PATH+'/send_code_for_verification_eng.html')
urlretrieve('https://raw.githubusercontent.com/BuffetProgram/Extensions/refs/heads/master/email_pages/send_code_for_verification_per.html',
BUFFET_EXTENSIONS_PATH+'/send_code_for_verification_per.html')
else:
pass
return True
def delete_all_data() -> None:
"""Deletes all data."""
try:
rmtree(BASE_DIR+'/data')
create_files_and_folders()
except FileNotFoundError:
pass