def get_stations_for_journey_time_update(self) -> Iterable[Station]: docs: Iterable[DocumentSnapshot] = self._destinations\ .order_by('journey_times_updated')\ .limit(1)\ .get() return map(lambda doc: Station.from_dict(doc.to_dict()), docs)
def get_stations_for_journey_costs_update(self) -> Iterable[Station]: this_year = date.today().year docs: Iterable[DocumentSnapshot] = self._destinations\ .where('journey_costs_updated', '<', datetime(this_year, 1, 1))\ .order_by('journey_costs_updated')\ .limit(1).get() return map(lambda doc: Station.from_dict(doc.to_dict()), docs)
def get_all_stations(self) -> Iterable[Station]: docs: Iterable[DocumentSnapshot] = self._stations.get() return map(lambda doc: Station.from_dict(doc.to_dict()), docs)
import os from google.cloud import firestore from interfaces.database import Database from models import Station from updaters import JourneyTimesInteractor from updaters.journey_costs_interactor import JourneyCostsInteractor if __name__ == '__main__': firestore = firestore.Client() database = Database(firestore) chx = Station.from_dict( firestore.collection('destinations').document('CHX').get().to_dict()) lew = Station.from_dict( firestore.collection('stations').document('LEW').get().to_dict()) time_interactor = JourneyTimesInteractor( db=database, api_key=os.environ['GMAPS_API_KEY']) time = time_interactor.get_update(chx, lew) time_interactor.save_update(chx, lew, time.value) costs_interactor = JourneyCostsInteractor(db=database) costs = costs_interactor.get_update(chx, lew) costs_interactor.save_update(chx, lew, costs.value) print("Updated Lewisham to Charing Cross")