|
from firebase_admin import credentials |
|
from firebase_admin import firestore |
|
import threading |
|
from firebase_admin import db |
|
|
|
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 |
|
|
|
def __eq__(self, other): |
|
return self.id == other.id |
|
|
|
def get_data(self): |
|
|
|
doc_ref = db.collection('complaints').document(self.id) |
|
|
|
doc = doc_ref.get() |
|
|
|
if doc.exists: |
|
|
|
return Shakwa.from_dict(doc.to_dict()) |
|
else: |
|
|
|
return None |
|
|
|
|
|
@staticmethod |
|
def from_dict(source): |
|
|
|
if not isinstance(source, dict): |
|
raise ValueError('Source is not a dictionary') |
|
|
|
shakwa = Shakwa( |
|
source['address'], |
|
source['complaintbody'], |
|
source['date'], |
|
source['governorate'], |
|
source['organization'], |
|
source['summary'], |
|
source['title'], |
|
source['userid'], |
|
source['id'] |
|
) |
|
|
|
return shakwa |
|
|
|
|
|
def to_dict(self): |
|
|
|
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 dest |
|
|
|
|
|
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,label): |
|
self.date = date |
|
self.feedback = feedback |
|
self.id=id |
|
self.review=review |
|
self.userid=userid |
|
self.label=label |
|
|
|
|
|
def __eq__(self, other): |
|
return self.id == other.id |
|
|
|
|
|
def get_data(self): |
|
|
|
doc_ref = db.collection('feedbacks').document(self.id) |
|
|
|
doc = doc_ref.get() |
|
|
|
if doc.exists: |
|
|
|
return Feedback.from_dict(doc.to_dict()) |
|
else: |
|
|
|
return None |
|
|
|
|
|
@staticmethod |
|
def from_dict(source): |
|
|
|
if not isinstance(source, dict): |
|
raise ValueError('Source is not a dictionary') |
|
|
|
feedback = Feedback( |
|
source['date'], |
|
source['feedback'], |
|
source['id'], |
|
source['review'], |
|
source['userid'], |
|
source['label'], |
|
) |
|
|
|
return feedback |
|
|
|
|
|
def to_dict(self): |
|
|
|
dest = { |
|
'date': self.date, |
|
'feedback': self.feedback, |
|
'id': self.id, |
|
'review': self.review, |
|
'userid': self.userid, |
|
'label': self.label, |
|
|
|
} |
|
|
|
return dest |
|
|
|
|
|
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')' |
|
) |
|
|