コード例 #1
0
ファイル: cron_jobs.py プロジェクト: gregjurman/outages
def scrape_omni_outages_url(service):
    #TODO: Pull this out to generic it
    # Get the utility entry, else create one if it's missing
    utility = None
    utility_query = Utility.query.filter(Utility.key==service['key'])
    if utility_query.count():
        utility = utility_query.one()
    else:
        # Doesn't exist, add new utility
        utility = Utility()
        utility.key = service['key']
        utility.name = service['name']
        DBSession.add(utility)
        DBSession.flush()


    # Clear all outages
    for o_obj in Outage.query.all():
        if o_obj.utility is utility:
            DBSession.delete(o_obj)

    # Get data from Omni
    scraper = OmniScraper(service['base'])

    outage_data = scraper.start(service['base'])
    
    # Setup the root Location as the State
    outage_data.name = service['state']
    outage_data.location_level = 'state'
    
    tot_custs = 0
    for child in outage_data.locations:
        if not outage_data.update_time:
            outage_data.update_time = child.update_time
        tot_custs = tot_custs + child.total_customers
    
    outage_data.total_customers = tot_custs

    populate_database(outage_data, utility)
コード例 #2
0
ファイル: cron_jobs.py プロジェクト: gregjurman/outages
def scrape_natgrid_outages_url(service):
    #TODO: Pull this out to generic it
    # Get the utility entry, else create one if it's missing
    utility = None
    utility_query = Utility.query.filter(Utility.key==service['key'])
    if utility_query.count():
        utility = utility_query.one()
    else:
        # Doesn't exist, add new utility
        utility = Utility()
        utility.key = service['key']
        utility.name = service['name']
        DBSession.add(utility)
        DBSession.flush()


    # Clear all outages
    for o_obj in Outage.query.all():
        if o_obj.utility is utility:
            DBSession.delete(o_obj)

    # Get data from NatGrid
    scraper = NationalGridScraper()

    outage_data = scraper.start(service['base'])

    # First layer is always garbage   
    outage_data = outage_data.locations[0]

    tot_custs = 0
    for child in outage_data.locations:
        if not outage_data.update_time:
            outage_data.update_time = child.update_time
        tot_custs = tot_custs + child.total_customers
    
    outage_data.total_customers = tot_custs

    populate_database(outage_data, utility)