47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import datetime
|
|
import json
|
|
|
|
import firebase_admin
|
|
from firebase_admin import credentials, firestore
|
|
|
|
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
|
from pojo.contact_pojo import ContactPojo
|
|
|
|
ERROR_COLLECTION_NAME = "error_items"
|
|
TIMEOUT = "timeout_items"
|
|
|
|
|
|
class DataManager:
|
|
def __init__(self):
|
|
cred = credentials.Certificate("appointment.json")
|
|
self._app = firebase_admin.initialize_app(cred)
|
|
self._db = firestore.client()
|
|
|
|
def get_all_error_items(self):
|
|
pass
|
|
|
|
def get_all_successful_items(self):
|
|
doc_ref = self._db.collection(u'2022-02-25')
|
|
return doc_ref
|
|
|
|
def save(self, result: ReserveResultPojo):
|
|
if result.type == PublishType.SUCCESS:
|
|
# get id
|
|
id = result.url.split("/")[-1]
|
|
result.id = id
|
|
document_name = str(datetime.date.today())
|
|
doc_ref = self._db.collection(document_name).document(result.id)
|
|
doc_ref.set(result.to_firestore_dict())
|
|
else:
|
|
doc_ref = self._db.collection(ERROR_COLLECTION_NAME).document(result.phone)
|
|
doc_ref.set(result.to_firestore_dict())
|
|
|
|
def save_timeout_contact(self, contact: ContactPojo):
|
|
doc_ref = self._db.collection(TIMEOUT).document(str(contact.phone))
|
|
doc_ref.set(contact.to_firestore_dict())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
manager = DataManager()
|
|
manager.save()
|