def __init__(self, start_date, end_date, db, buildings_collection_name='buildings'): self.start_date = start_date self.end_date = end_date self.db = db self.buildings_collection = db[buildings_collection_name] # The building objects at the start of this run. These will not yet # have the new alias information given by user self.current_buildings = list(self.buildings_collection.find()) self.scraper = EventScraper( self.current_buildings, building_callback=self.cl_user_update_aliases)
def update_db_for_dates(start_date, end_date, db, collection_name='events', buildings_collection='buildings'): ''' Insert all events scraped from the website that take place between <start_date> and <end_date> Both parameters should be datetime.date objects ''' buildings = list(db[buildings_collection].find()) scraper = EventScraper(buildings) event_dicts = scraper.get_events_for_dates(start_date, end_date) collection = db[collection_name] inserted_ids = [collection.update(e, e, upsert=True) for e in event_dicts]