lamagetter = fetcher.Fetcher(cfg['connection'])
    localdb = LocalStore(dbname)
    for notice in notices:
        try:
            rows = lamagetter.fetch(notice['sql'].format(searchdate))
        except fetcher.FetcherError as e:
            print ' - Error accessing DB: {0}'.format(e.message)
            sys.exit(1)
        localdb.save_data(notice['table'], rows, notice['uidfield'])
        print ' - {0} rows saved to table {1}'.format(len(rows), notice['table'])
        if len(rows) > 0:
            #Extract all the users from the AOI featureclass.
            allusers = set()
            usrflds = [cfg['addrfield'], notice['preffield']]
            rawaddrs = spatial.extract_results(cfg['aoisource'], usrflds, usrflds)
            for addr in rawaddrs:
                if addr[notice['preffield']] == '1':
                    allusers.add(addr[cfg['addrfield']])
            print ' - {0} users to be notified for {1}'.format(len(allusers), notice['table'])
        
            #This gets a little brute-forcey.  Probably should be rolled up in localstore.
            getuidssql = 'SELECT DISTINCT {0} FROM {1}'.format(notice['uidfield'], notice['table'])
            uidres = localdb.exec_sql(getuidssql)
            noticeuids = '|'.join([str(x[notice['uidfield']]) for x in uidres])
            rows = []
            fields = [cfg['namefield'], cfg['addrfield'], cfg['uidfield']]
            for addr in allusers:
                rows.append(collections.OrderedDict(zip(fields, [cfg['citywidearea'], addr, noticeuids])))
            localdb.save_points(cfg['mailtable'], rows, notice['table'], cfg['sourcefield'])
Example #2
0
    lamagetter = fetcher.Fetcher(cfg['connection'])
    localdb = LocalStore(dbname)
    for notice in notices:
        try:
            rows = lamagetter.fetch(notice['sql'].format(searchdate))
        except fetcher.FetcherError as e:
            print ' - Error accessing DB: {0}'.format(e.message)
            sys.exit(1)
        localdb.save_data(notice['table'], rows, notice['uidfield'])
        print ' - {0} rows saved to table {1}'.format(len(rows),
                                                      notice['table'])
        if len(rows) > 0:
            #Extract all the users from the AOI featureclass.
            allusers = set()
            usrflds = [cfg['addrfield'], notice['preffield']]
            rawaddrs = spatial.extract_results(cfg['aoisource'], usrflds,
                                               usrflds)
            for addr in rawaddrs:
                if addr[notice['preffield']] == '1':
                    allusers.add(addr[cfg['addrfield']])
            print ' - {0} users to be notified for {1}'.format(
                len(allusers), notice['table'])

            #This gets a little brute-forcey.  Probably should be rolled up in localstore.
            getuidssql = 'SELECT DISTINCT {0} FROM {1}'.format(
                notice['uidfield'], notice['table'])
            uidres = localdb.exec_sql(getuidssql)
            noticeuids = '|'.join([str(x[notice['uidfield']]) for x in uidres])
            rows = []
            fields = [cfg['namefield'], cfg['addrfield'], cfg['uidfield']]
            for addr in allusers:
                rows.append(
Example #3
0
        try:
            joined = spatial.select_and_join(cfg['aoisource'], notice['table'],
                                             gdb, aoifilter, outfields,
                                             notice['uidfield'])
        except spatial.ArcError as e:
            print ' - Error completing spatial join: {0}'.format(e.message)
            sys.exit(1)

        if joined is not None:
            fcfields = [
                notice['namefield'], notice['addrfield'], notice['uidfield']
            ]
            exportfields = [
                cfg['namefield'], cfg['addrfield'], cfg['uidfield']
            ]
            joinedrows = spatial.extract_results(joined, fcfields,
                                                 exportfields)
            if len(joinedrows) > 0:
                localdb.save_points(cfg['mailtable'], joinedrows,
                                    notice['table'], cfg['sourcefield'])
            totaljoined += len(joinedrows)
            print ' - {0} rows saved for notice {1}'.format(
                len(joinedrows), notice['table'])
        else:
            print ' - {0} rows saved for notice {1}'.format(0, notice['table'])
    localdb.close_db()

    #Now, delete the temp GDB, unless the --keep option has been passed.
    if args.rename:
        print 'Keeping scratch GDB for posterity...'
        currdate = datetime.date.today().strftime('%Y%m%d')
        try:
        except spatial.ArcError as e:
            print ' - Error creating points from notices: {0}'.format(e.message)
            sys.exit(1)

        aoifilter = notice['aoifilter'].format(frequency)
        try:
            joined = spatial.select_and_join(cfg['aoisource'], notice['table'], 
                                             gdb, aoifilter, outfields, notice['uidfield'])
        except spatial.ArcError as e:
            print ' - Error completing spatial join: {0}'.format(e.message)
            sys.exit(1)

        if joined is not None:
            fcfields = [notice['namefield'], notice['addrfield'], notice['uidfield']]
            exportfields = [cfg['namefield'], cfg['addrfield'], cfg['uidfield']]
            joinedrows = spatial.extract_results(joined, fcfields, exportfields)
            if len(joinedrows) > 0:
                localdb.save_points(cfg['mailtable'], joinedrows, 
                                    notice['table'], cfg['sourcefield'])
            totaljoined += len(joinedrows)
            print ' - {0} rows saved for notice {1}'.format(len(joinedrows), notice['table'])
        else:
            print ' - {0} rows saved for notice {1}'.format(0, notice['table'])
    localdb.close_db()

    #Now, delete the temp GDB, unless the --keep option has been passed.
    if args.rename:
        print 'Keeping scratch GDB for posterity...'
        currdate = datetime.date.today().strftime('%Y%m%d')
        try:
            spatial.keep_gdb(gdb, currdate)