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 | |
| 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 set_data(self): | |
| # Create a document reference with the user's email as the ID | |
| doc_ref = db.collection('complaints').document(self.id) | |
| # Set the document data with the user's attributes | |
| doc_ref.set(self.to_dict()) | |
| # Convert a dictionary to a Shkwa 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['id'], | |
| source['organization'], | |
| source['summary'], | |
| source['title'], | |
| source['userid'] | |
| ) | |
| # Return the Shkwa object | |
| return shakwa | |
| # Convert a Shkwa object to a dictionary | |
| def to_dict(self): | |
| # Create a dictionary with the Shkwa'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 Shkwa object as a string | |
| def __repr__(self): | |
| return ( | |
| 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'userid={self.id}, ' | |
| f')' | |
| ) | |