-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_encrypted_database.py
More file actions
49 lines (40 loc) · 1.88 KB
/
Copy pathview_encrypted_database.py
File metadata and controls
49 lines (40 loc) · 1.88 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
from app import create_app, db
from app.models import User, Medicine
import json
from sqlalchemy import text
def main():
"""Display encrypted vs decrypted data for medicine table"""
app = create_app()
with app.app_context():
# Medicines table
medicines = Medicine.query.all()
for medicine in medicines:
print(f"MEDICINE {medicine.id}:")
# Get raw encrypted data
result = db.session.execute(
text('SELECT name, description FROM medicine WHERE id = :id'),
{'id': medicine.id}
).fetchone()
if result:
print(f" Name (encrypted): {result[0]}")
print(f" Name (decrypted): {medicine.name}")
print(f" Description (encrypted): {result[1]}")
print(f" Description (decrypted): {medicine.description}")
# Time fields
time_fields = ['time_mon', 'time_tue', 'time_wed', 'time_thu', 'time_fri', 'time_sat', 'time_sun']
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
for i, field in enumerate(time_fields):
result = db.session.execute(
text(f'SELECT {field} FROM medicine WHERE id = :id'),
{'id': medicine.id}
).fetchone()
if result and result[0]:
decrypted_value = getattr(medicine, field)
print(f" {days[i]} (encrypted): {result[0]}")
print(f" {days[i]} (decrypted): {decrypted_value}")
print(f" Secure ID: {medicine.secure_id}")
print(f" User ID: {medicine.user_id}")
print(f" Data Hash: {medicine.data_hash}")
print()
if __name__ == '__main__':
main()