lsoaresesilva / respe

An interactive web IDE to support the learning of programming.
14 stars 7 forks source link

Backup do firestore #858

Open lsoaresesilva opened 1 year ago

lsoaresesilva commented 1 year ago

class City:
    def __init__(self, name, state, country, capital=False, population=0, regions=[]):
        self.name = name
        self.state = state
        self.country = country
        self.capital = capital
        self.population = population
        self.regions = regions

    @staticmethod
    def from_dict(source):
        # ...

    def to_dict(self):
        # ...

    def __repr__(self):
        return f"City(\
                name={self.name}, \
                country={self.country}, \
                population={self.population}, \
                capital={self.capital}, \
                regions={self.regions}\
            )"

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

# Use a service account.
cred = credentials.Certificate('path/to/serviceAccount.json')

app = firebase_admin.initialize_app(cred)

db = firestore.client()
cities_ref = db.collection("cities")

query_start_at = cities_ref.order_by("population").start_at({"population": 1000000})
# ou

docs = (
    db.collection("cities")
    .where(filter=FieldFilter("capital", "==", True))
    .stream()
)

for doc in docs:
    print(f"{doc.id} => {doc.to_dict()}")