| import firebase_admin |
| from firebase_admin import credentials, firestore |
| from models import ETF |
|
|
|
|
| |
| cred = credentials.Certificate('stokistan-332f5-firebase-adminsdk-fbsvc-5b6cddb01e.json') |
| firebase_admin.initialize_app(cred) |
| db = firestore.client() |
|
|
|
|
| def getAllEtf(): |
| try: |
| docs = db.collection('ETF').stream() |
| etf_list = [] |
| for doc in docs: |
| data = doc.to_dict() |
| data['id'] = doc.id |
| print(data) |
| data['keyPeople'] = data.pop('Key People', []) |
| data['etfName'] = data.pop('EtfName',"") |
| data['description'] = data.pop('Description','') |
| |
| etf_list.append(ETF(**data)) |
| print(etf_list) |
| return {"etfs": etf_list} |
| except Exception as e: |
| print(f'error{e}') |
|
|
| def rename_field(): |
| docs = db.collection("ETF").stream() |
|
|
| for doc in docs: |
| data = doc.to_dict() |
|
|
| if " Key People" in data: |
| print(f"Fixing doc: {doc.id}") |
|
|
| db.collection("ETF").document(doc.id).update({ |
| "Key People": data[" Key People"], |
| " Key People": firestore.DELETE_FIELD |
| }) |
|
|
| print("Done!") |
|
|
|
|
| if __name__ == "__main__": |
| getAllEtf() |