Spaces:
Runtime error
Runtime error
youssef1214
commited on
Commit
•
a8ce4bd
1
Parent(s):
89d073d
Upload Classes.py
Browse files- Classes.py +79 -0
Classes.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from firebase_admin import credentials
|
2 |
+
from firebase_admin import firestore
|
3 |
+
import threading
|
4 |
+
from firebase_admin import db
|
5 |
+
# Import the Firebase Admin SDK
|
6 |
+
import firebase_admin
|
7 |
+
|
8 |
+
|
9 |
+
class Shakwa(object):
|
10 |
+
def __init__(self, address, complaintbody, date, governorate, id, organization, summary, title, userid):
|
11 |
+
self.address = address
|
12 |
+
self.complaintbody = complaintbody
|
13 |
+
self.date = date
|
14 |
+
self.governorate = governorate
|
15 |
+
self.id = id
|
16 |
+
self.organization = organization
|
17 |
+
self.summary = summary
|
18 |
+
self.title = title
|
19 |
+
self.userid = userid
|
20 |
+
|
21 |
+
def set_data(self):
|
22 |
+
# Create a document reference with the user's email as the ID
|
23 |
+
doc_ref = db.collection('complaints').document(self.id)
|
24 |
+
# Set the document data with the user's attributes
|
25 |
+
doc_ref.set(self.to_dict())
|
26 |
+
|
27 |
+
# Convert a dictionary to a Shkwa object
|
28 |
+
|
29 |
+
@staticmethod
|
30 |
+
def from_dict(source):
|
31 |
+
# Check if the source is a valid dictionary
|
32 |
+
if not isinstance(source, dict):
|
33 |
+
raise ValueError('Source is not a dictionary')
|
34 |
+
# Create a User object with the source values
|
35 |
+
shakwa = Shakwa(
|
36 |
+
source['address'],
|
37 |
+
source['complaintbody'],
|
38 |
+
source['date'],
|
39 |
+
source['governorate'],
|
40 |
+
source['id'],
|
41 |
+
source['organization'],
|
42 |
+
source['summary'],
|
43 |
+
source['title'],
|
44 |
+
source['userid']
|
45 |
+
)
|
46 |
+
# Return the Shkwa object
|
47 |
+
return shakwa
|
48 |
+
|
49 |
+
# Convert a Shkwa object to a dictionary
|
50 |
+
def to_dict(self):
|
51 |
+
# Create a dictionary with the Shkwa's attributes
|
52 |
+
dest = {
|
53 |
+
'address': self.address,
|
54 |
+
'complaintbody': self.complaintbody,
|
55 |
+
'date': self.date,
|
56 |
+
'governorate': self.governorate,
|
57 |
+
'organization': self.organization,
|
58 |
+
'summary': self.summary,
|
59 |
+
'title': self.title,
|
60 |
+
'userid': self.userid,
|
61 |
+
'id': self.id,
|
62 |
+
}
|
63 |
+
# Return the dictionary
|
64 |
+
return dest
|
65 |
+
|
66 |
+
# Represent a Shkwa object as a string
|
67 |
+
def __repr__(self):
|
68 |
+
return (
|
69 |
+
f'address={self.address}'
|
70 |
+
f'complaintbody={self.complaintbody},'
|
71 |
+
f'date={self.date}, '
|
72 |
+
f'governorate={self.governorate}, '
|
73 |
+
f'organization={self.organization}, '
|
74 |
+
f'summary={self.summary}, '
|
75 |
+
f'title={self.title}, '
|
76 |
+
f'userid={self.userid}, '
|
77 |
+
f'userid={self.id}, '
|
78 |
+
f')'
|
79 |
+
)
|