def setupCredentials(N):
    for fN in N:
        if fN.startswith('gServo'):
            subApplication = fN[6:]
            myCredentials = gauth.get_credentials(subApplication.lower())
            http = myCredentials.authorize(httplib2.Http())
            N[fN] = discovery.build('gmail','v1',http=http)
    return N
Exemple #2
0
def setupCredentials(N):
	for fN in N:
		if fN.startswith('gServo'):
			subApplication = fN[6:]
			myCredentials = gauth.get_credentials(subApplication.lower())
			http = myCredentials.authorize(httplib2.Http())
			N[fN] = discovery.build('gmail','v1',http=http)
	return N
# MAIN:
processStartTime = time.perf_counter()
[P,N] = readParams()
P = {k:1*v for (k,v) in P.items()}         # MULTIPLICATION FACTOR for DEBUGGING !
N = getCustomers(N)
LT = dict.fromkeys(P, processStartTime)
LT['time_eStatus'] = processStartTime - 2*P['time_eStatus'] # always beacon first iter
LT['time_readData'] = processStartTime - 3*P['time_readData']
DF = pd.DataFrame(index=range(0),columns=cabiFields())
dfS = DF[idFields()+timestampFields()+staticFields()]
dStatics = {}
dumpCount=0
try:
    #N = setupCredentials(N)
    credentials = gauth.get_credentials()
    http = credentials.authorize(httplib2.Http())
    N['gService'] = discovery.build('gmail', 'v1', http=http)
    outgoingMail = []
    # initialize DF:
    
    # do a single full read here, creating DF
    while True:
        try:
            (DF,status_url_gbfs) = initialize_dataframe_from_gbfs(N['gbfs_url'])
            print(DF.shape)
            break
        except:
            print('%.2f: Failed to retrieve GBFS data. Trying again in %.0f seconds...'\
                              %(time.perf_counter(),P['time_checkPingbox']))
            time.sleep(P['time_checkPingbox'])
Exemple #4
0
# MAIN:
processStartTime = time.clock()
[P,N] = readParams()
P = {k:1*v for (k,v) in P.iteritems()} 		# MULTIPLICATION FACTOR for DEBUGGING !
N = getCustomers(N)
LT = dict.fromkeys(P, processStartTime)
LT['time_eStatus'] = processStartTime - 2*P['time_eStatus'] # always beacon first iter
LT['time_readData'] = processStartTime - 3*P['time_readData']
DF = pd.DataFrame(index=range(0),columns=cabiFields())
dfS = DF[idFields()+timestampFields()+staticFields()]
dStatics = {}
dumpCount=0
try:
	#N = setupCredentials(N)
	credentials = gauth.get_credentials()
	http = credentials.authorize(httplib2.Http())
	N['gService'] = discovery.build('gmail', 'v1', http=http)
	outgoingMail = []
	# main loop
	while True:
		iterStartTime = time.clock()
		if ((LT['time_readData']+P['time_readData']) < (LT['time_checkPingbox']+P['time_checkPingbox']+P['bufferTime_readData'])):
			print(time.ctime() + ': ' + str(iterStartTime) + ': reading new Data')
			# scrape new data:
			try:
				[DF_new,rawXML] = getNewData(N['scrapeURL'])
				DF = DF.append(DF_new)
			except Exception as e:
				#send alert email if read failed
				[subject,body] = buildEmailAlert('failed to read CaBi data',str(e),P,dbName(N,dumpCount))