Skip to content

Commit 8e9e15f

Browse files
authored
Add files via upload
1 parent 90dae4f commit 8e9e15f

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def check():
2+
with open("firsttime.txt","r") as a:
3+
if a.read()=="True":
4+
return True
5+
else:
6+
return False
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
True
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import setup
2+
3+
connection=setup.setup()
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import check
2+
3+
import pickle
4+
import mysql.connector
5+
6+
7+
query=""
8+
Password=""
9+
Database=""
10+
def sqlpwd():
11+
global Password
12+
cred = open("cred.dat","rb")
13+
dat=pickle.load(cred)
14+
cred.close()
15+
Password=dat[0]
16+
return Password
17+
18+
def sqldb():
19+
global Database
20+
cred = open("cred.dat","rb")
21+
dat=pickle.load(cred)
22+
cred.close()
23+
Database=dat[1]
24+
return Database
25+
26+
def connectionquery():
27+
try:
28+
Databa=sqldb()
29+
Passwo=sqlpwd()
30+
query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
31+
except:
32+
import traceback
33+
traceback.print_exc()
34+
query=""
35+
return query
36+
37+
def querycheck():
38+
conn=connectionquery()
39+
ans=False
40+
if conn!="":
41+
if conn.is_connected:
42+
print("Connection established successfully.")
43+
with open("firsttime.txt","w") as f:
44+
f.write("False")
45+
ans=True
46+
47+
if not ans:
48+
print("There was a problem in connection")
49+
print("Maybe this is because you entered wrong credentials(password and database name)")
50+
return ans
51+
52+
def mysqlsetup():
53+
print("\n-----------------MYSQL Setup-------------------\n")
54+
print("Remember that you can't change the database afterwards\n")
55+
print("Create a database in your MYSQL Workbench.\n")
56+
Database=input("Enter database name: ")
57+
Password=input("Enter sql password (enter '' if nothing):")
58+
cred2= open("cred.dat","wb")
59+
data=[Password,Database]
60+
pickle.dump(data,cred2)
61+
cred2.close()
62+
querycheck()
63+
64+
def setup():
65+
while check.check():
66+
print("\n\n-----------------Welcome to the Project!!!-------------------")
67+
print("This is the setup process which runs when the user uses the program for the first time.")
68+
print("\n----------------------Database Setup------------------------\n")
69+
print("1.Mysql 8.0 (Dependency MYSQL)")
70+
print("2.Standalone (Data files)")
71+
print("0.Cancel operation\n")
72+
ans2=input("How do you want to store the data? (1/2): ")
73+
if ans2 == "0":
74+
break
75+
if ans2=="1":
76+
mysqlsetup()
77+
if ans2=="2":
78+
print("\nThis is under development :). Please use mysql till then...")
79+
elif ans2 != "1" or ans2 != "2":
80+
print("\nWrong input, (1/2).........")
81+
else:
82+
if querycheck():
83+
connectionquery()
84+
setup()

0 commit comments

Comments
 (0)