File size: 4,963 Bytes
0901162 d3c3acd 0901162 d3c3acd 0901162 d3c3acd 0901162 d3c3acd 0901162 d3c3acd 0901162 |
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
from firebase_admin import credentials
from firebase_admin import firestore
import threading
from firebase_admin import db
# Import the Firebase Admin SDK
import firebase_admin
db = firestore.client()
class Shakwa(object):
def __init__(self, address, complaintbody, date, governorate, id,organization,summary,title,userid):
self.address = address
self.complaintbody = complaintbody
self.date = date
self.governorate = governorate
self.id = id
self.organization = organization
self.summary = summary
self.title = title
self.userid = userid
# Get the user data from Firestore
def get_data(self):
# Get a document reference with the user's email as the ID
doc_ref = db.collection('complaints').document(self.id)
# Get the document snapshot
doc = doc_ref.get()
# Check if the document exists
if doc.exists:
# Return the document data as a User object
return Shakwa.from_dict(doc.to_dict())
else:
# Return None if the document does not exist
return None
# Convert a dictionary to a User object
@staticmethod
def from_dict(source):
# Check if the source is a valid dictionary
if not isinstance(source, dict):
raise ValueError('Source is not a dictionary')
# Create a User object with the source values
shakwa = Shakwa(
source['address'],
source['complaintbody'],
source['date'],
source['governorate'],
source['organization'],
source['summary'],
source['title'],
source['userid'],
source['id']
)
# Return the User object
return shakwa
# Convert a User object to a dictionary
def to_dict(self):
# Create a dictionary with the user's attributes
dest = {
'address': self.address,
'complaintbody': self.complaintbody,
'date': self.date,
'governorate': self.governorate,
'organization':self.organization,
'summary': self.summary,
'title': self.title,
'userid': self.userid,
'id': self.id,
}
# Return the dictionary
return dest
# Represent a User object as a string
def __repr__(self):
return (
f'Shakwa('
f'address={self.address}, '
f'complaintbody={self.complaintbody}, '
f'date={self.date}, '
f'governorate={self.governorate}, '
f'organization={self.organization}'
f'summary={self.summary}'
f'title={self.title}'
f'userid={self.userid}'
f'id={self.id}'
f')'
)
class Feedback(object):
def __init__(self,date, feedback, id,review,userid,lebel):
self.date = date
self.feedback = feedback
self.id=id
self.review=review
self.userid=userid
self.label=label
# Get the Feedback data from Firestore
def get_data(self):
# Get a document reference with the Feedback's Id
doc_ref = db.collection('feedbacks').document(self.id)
# Get the document snapshot
doc = doc_ref.get()
# Check if the document exists
if doc.exists:
# Return the document data as a Feedback object
return Feedback.from_dict(doc.to_dict())
else:
# Return None if the document does not exist
return None
# Convert a dictionary to a Feedback object
@staticmethod
def from_dict(source):
# Check if the source is a valid dictionary
if not isinstance(source, dict):
raise ValueError('Source is not a dictionary')
# Create a Feedback object with the source values
shakwa = Feedback(
source['date'],
source['feedback'],
source['id'],
source['review'],
source['userid'],
source['label'],
)
# Return the User object
return Feedback
# Convert a Feedback object to a dictionary
def to_dict(self):
# Create a dictionary with the Feedback's attributes
dest = {
'date': self.date,
'feedback': self.feedback,
'id': self.id,
'review': self.review,
'userid': self.userid,
'label': self.label,
}
# Return the dictionary
return dest
# Represent a Feedback object as a string
def __repr__(self):
return (
f'Feedback('
f'date={self.date}, '
f'feedback={self.feedback}, '
f'id={self.id}, '
f'review={self.review}, '
f'userid={self.userid}'
f'label={self.label}'
f')'
)
|