Spaces:
Runtime error
Runtime error
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 | |
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): | |
self.date = date | |
self.feedback = feedback | |
self.id=id | |
self.review=review | |
self.userid=userid | |
# 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 | |
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'], | |
) | |
# 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, | |
} | |
# 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')' | |
) | |