Skip to content

Commit

Permalink
merging with remote
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadKhGh99 committed Oct 23, 2024
1 parent 48b8806 commit 61386b5
Show file tree
Hide file tree
Showing 1,749 changed files with 318 additions and 132,595 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
.idea
__pycache__/
__pycache__
client_secrets.json
venv
.venv

output
credentials.txt
المعالجة الشرعية.html
نسخ_إحتياطي.xlsx
نسخ_إحتياطي.*
Patient.db
*.jpg
*.png
*.webp
*.avif
*.avif
*.spec
43 changes: 29 additions & 14 deletions GDriveConnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,44 @@
from pydrive.drive import GoogleDrive
from pydrive.auth import GoogleAuth
import sqlite3
import pandas as pd
# import pandas as pd
import csv
from flask import flash

gauth = None
root_folder = None
drive = None
db_path = r"Patient.db"
excel_path = r"نسخ_إحتياطي.csv"


def do_backup_xlsx():
try:
with sqlite3.connect("Patient.db") as connection:
df = pd.read_sql("SELECT * from Patient", connection)
with sqlite3.connect(db_path) as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM Patient")
rows = cursor.fetchall()
column_names = [description[0] for description in cursor.description]

# Check if the file exists
if os.path.exists("نسخ_إحتياطي.xlsx"):
if os.path.exists(excel_path):
# Remove the file
os.remove("نسخ_إحتياطي.xlsx")
df.to_excel("نسخ_إحتياطي.xlsx")
os.remove(excel_path)

# Write data to CSV file
with open(excel_path, mode='w', newline='', encoding='utf-8-sig') as file:
writer = csv.writer(file)
writer.writerow(column_names) # Write column headers
writer.writerows(rows) # Write data rows



# df = pd.read_sql("SELECT * from Patient", connection)
# # Check if the file exists
# if os.path.exists("نسخ_إحتياطي.xlsx"):
# # Remove the file
# os.remove("نسخ_إحتياطي.xlsx")
# df.to_excel("نسخ_إحتياطي.xlsx")
flash("تم التحويل بنجاح!", "success")
return 0
except Exception as e:
Expand Down Expand Up @@ -64,12 +85,6 @@ def authentication_func():
root_folder.Upload()


# replace the value of this variable
# with the absolute path of the directory
db_path = r"Patient.db"
xlsx_path = r"نسخ_إحتياطي.xlsx"


def save_func():
do_backup_xlsx()
global root_folder
Expand All @@ -79,14 +94,14 @@ def save_func():

root_list = drive.ListFile({'q': f"'{root_folder['id']}' in parents and trashed=false"}).GetList() # type: ignore
for file in root_list:
if file['title'] == xlsx_path:
if file['title'] == excel_path:
file.Delete()
if file['title'] == db_path:
file.Delete()
# iterating thought all the files/folder
# of the desired directory

for x in [db_path, xlsx_path]:
for x in [db_path, excel_path]:
f = drive.CreateFile({'parents': [{'id': f"{root_folder['id']}"}]}) # type: ignore
f.SetContentFile(x)
f.Upload()
Expand Down
Binary file modified Patient.db
Binary file not shown.
16 changes: 0 additions & 16 deletions Pipfile

This file was deleted.

872 changes: 0 additions & 872 deletions Pipfile.lock

This file was deleted.

Binary file modified __pycache__/GDriveConnect.cpython-310.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask import render_template, Flask, request, redirect, url_for, flash
import webbrowser


app = Flask(__name__)
app.secret_key = 'nglknfkgm;mf;gmn03h4w3t8409t'

Expand Down Expand Up @@ -294,4 +295,4 @@ def create_table():
if __name__ == "__main__":
create_table()
webbrowser.open("http://127.0.0.1:5000")
app.run(debug=True)
app.run()
Binary file removed backup/Patient.db
Binary file not shown.
1 change: 0 additions & 1 deletion client_secrets.json

This file was deleted.

Binary file removed output/app.zip
Binary file not shown.
74 changes: 54 additions & 20 deletions output/app/GDriveConnect.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,74 @@
import os
from pydrive.drive import GoogleDrive
from pydrive.auth import GoogleAuth
import sqlite3
import pandas as pd
# import pandas as pd
import csv
from flask import flash

gauth = None
root_folder = None
drive = None
db_path = r"Patient.db"
excel_path = r"نسخ_إحتياطي.csv"


def do_backup_xlsx():
try:
with sqlite3.connect("patientsdata/Patient.db") as connection:
df = pd.read_sql("SELECT * from Patient", connection)
df.to_excel("نسخ_إحتياطي.xlsx")
with sqlite3.connect(db_path) as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM Patient")
rows = cursor.fetchall()
column_names = [description[0] for description in cursor.description]

# Check if the file exists
if os.path.exists(excel_path):
# Remove the file
os.remove(excel_path)

# Write data to CSV file
with open(excel_path, mode='w', newline='', encoding='utf-8-sig') as file:
writer = csv.writer(file)
writer.writerow(column_names) # Write column headers
writer.writerows(rows) # Write data rows



# df = pd.read_sql("SELECT * from Patient", connection)
# # Check if the file exists
# if os.path.exists("نسخ_إحتياطي.xlsx"):
# # Remove the file
# os.remove("نسخ_إحتياطي.xlsx")
# df.to_excel("نسخ_إحتياطي.xlsx")
flash("تم التحويل بنجاح!", "success")
return 0
except Exception as e:
flash("لم يتم التحويل إلى ملف إكسل! \n" + str(e), "error")
return 1
raise e


def authentication_func():
# Below code does the authentication
# part of the code
global gauth, root_folder, drive
gauth = GoogleAuth()

if os.path.exists('credentials.txt'):
gauth.LoadCredentialsFile('credentials.txt')

# Refresh the token if expired
if gauth.access_token_expired:
gauth.Refresh()
else:
gauth.Authorize() # Reauthorize if needed

else:
# Perform OAuth authentication
gauth.LocalWebserverAuth() # Open a local webserver for user login

# Creates local webserver and auto
# handles authentication.
gauth.LocalWebserverAuth()
# Save the credentials for future use
gauth.SaveCredentialsFile('credentials.txt')
drive = GoogleDrive(gauth)

# searching for the root folder to save to
Expand All @@ -46,30 +85,24 @@ def authentication_func():
root_folder.Upload()


# replace the value of this variable
# with the absolute path of the directory
db_path = r"patientsdata/Patient.db"
xlsx_path = r"نسخ_إحتياطي.xlsx"


def save_func():
do_backup_xlsx()
global root_folder
try:
if drive is None or gauth is None:
authentication_func()

root_list = drive.ListFile({'q': f"'{root_folder['id']}' in parents and trashed=false"}).GetList()
root_list = drive.ListFile({'q': f"'{root_folder['id']}' in parents and trashed=false"}).GetList() # type: ignore
for file in root_list:
if file['title'] == xlsx_path:
if file['title'] == excel_path:
file.Delete()
if file['title'] == db_path:
file.Delete()
# iterating thought all the files/folder
# of the desired directory

for x in [db_path, xlsx_path]:
f = drive.CreateFile({'parents': [{'id': f"{root_folder['id']}"}]})
for x in [db_path, excel_path]:
f = drive.CreateFile({'parents': [{'id': f"{root_folder['id']}"}]}) # type: ignore
f.SetContentFile(x)
f.Upload()

Expand All @@ -84,15 +117,16 @@ def save_func():
return 0
except Exception as e:
flash("لم يتم الحفظ! \n" + str(e), "error")
return 1
raise e


def load_func():
global root_folder
try:
if drive is None or gauth is None:
authentication_func()

root_list = drive.ListFile({'q': f"'{root_folder['id']}' in parents and trashed=false"}).GetList()
root_list = drive.ListFile({'q': f"'{root_folder['id']}' in parents and trashed=false"}).GetList() # type: ignore
for file in root_list:
file.GetContentFile(fr"نسخ_إحتياطي\{file['title']}")
flash("تم إستعادة الملفات بنجاح!", "success")
Expand Down
Binary file removed output/app/MSVCP140.dll
Binary file not shown.
Binary file modified output/app/Patient.db
Binary file not shown.
Binary file modified output/app/VCRUNTIME140.dll
Binary file not shown.
Binary file removed output/app/VCRUNTIME140_1.dll
Binary file not shown.
Binary file modified output/app/_asyncio.pyd
Binary file not shown.
Binary file modified output/app/_bz2.pyd
Binary file not shown.
Binary file modified output/app/_ctypes.pyd
Binary file not shown.
Binary file modified output/app/_decimal.pyd
Binary file not shown.
Binary file removed output/app/_elementtree.pyd
Binary file not shown.
Binary file modified output/app/_hashlib.pyd
Binary file not shown.
Binary file modified output/app/_lzma.pyd
Binary file not shown.
Binary file modified output/app/_multiprocessing.pyd
Binary file not shown.
Binary file modified output/app/_overlapped.pyd
Binary file not shown.
Binary file modified output/app/_queue.pyd
Binary file not shown.
Binary file modified output/app/_socket.pyd
Binary file not shown.
Binary file modified output/app/_sqlite3.pyd
Binary file not shown.
Binary file modified output/app/_ssl.pyd
Binary file not shown.
Binary file removed output/app/_testcapi.pyd
Binary file not shown.
Binary file removed output/app/_testinternalcapi.pyd
Binary file not shown.
Binary file removed output/app/_tkinter.pyd
Binary file not shown.
Binary file modified output/app/_uuid.pyd
Binary file not shown.
Binary file modified output/app/app.exe
Binary file not shown.
Binary file modified output/app/base_library.zip
Binary file not shown.
Loading

0 comments on commit 61386b5

Please sign in to comment.