def processApi(logdir, spots, monthlies, to): global fails # Get the PM API response url = 'https://nforce.parkmobile.us/nforceapi/parkingrights/zone/3125?format=json' usr = '******' pwd = 'x2warEya' i = 0 while True: try: resp = requests.get(url, auth=(usr, pwd), verify=True) break except Exception, e: i += 1 print 'BAD NEWS PARKMOBILE!' print 'Error number %d' % (i) if i == 5: msg = """ %s Park Mobile API is not responding! """ % time.asctime() notify.send_msg('Error', msg, to) fails += 1 if fails == 5: raise
def processApi( logdir, spots, monthlies, to ): global fails # Get the PM API response url = 'https://nforce.parkmobile.us/nforceapi/parkingrights/zone/3125?format=json' usr = '******' pwd = 'x2warEya' i = 0 while True: try: resp = requests.get(url, auth=(usr,pwd), verify=True) break except Exception, e: i += 1 print 'BAD NEWS PARKMOBILE!' print 'Error number %d' % (i) if i==5: msg = """ %s Park Mobile API is not responding! """ % time.asctime() notify.send_msg('Error',msg,to) fails += 1 if fails == 5: raise
cv2.imwrite(sfname,ims) res = alpr.recognize_file(fname) lpn = '' try: lpn = str( res['results'][0]['plate'] ) print "LPN = %s" % lpn except: print "no dice with lpr..." sub = 'Occupation has changed' msg = 'Spot Status = %s' % str(now_occupied) print '%s\n%s' % (sub,msg) msg += '\nLPN = %s' % lpn #notify.send_msg_with_jpg( sub, msg, sfname, team ) # Set occupation to current status occupied = now_occupied except Exception, e: print e sys.exit() bad_count += 1 if bad_count == 5: print "too many failures\n\t%s" % str(e) notify.send_msg('Error',str(e),team) sys.exit() time.sleep(sleepytime)
slog_fname = 'spot' + str(spot['number']) + '.log' slog_ffname = os.path.join(sld,slog_fname) with open(slog_ffname,'a') as l: w = csv.writer(l) w.writerow(slog_data) # Reset failure notification log failure_notifications = 0 else: msg = """ %s Camera %d is not producing images ! """ % (time.asctime(),camera['number']) if failure_notifications < 5: notify.send_msg(msg,to) failure_notifications += 1 elif failure_notifications == 5: msg += """ Camera is BROKEN -- DONE SENDING MESSAGES LIKE THIS""" print msg # cleanup: # delete the image that has been processed os.remove(fname) # store the current state of the camera dict_fname = 'camera' + str(c) + '.dict'
def processCameras( cameras, dirs, to, spam=None ): for c, camera in cameras.iteritems(): ## Write jpeg to image dir and ## populate camera dict with time info #result = gi.get_image( camera, dirs['wd'] ) # Use images already popped into server result = useImage( camera, dirs['pd'] ) existantFailure = False if result['success']: delta_time = result['delta_time'] fname = result['fname'] # Process image aiSuccess = ai.analyzeImage( fname, camera ) if not aiSuccess: existantFailure = True break # Judging for spot in camera['spots']: present = dp.determinePresence( spot ) res = ep.evaluatePresence( spot, present, delta_time, camera['im_ts'] ) if res['message'] is not None and spam is not None: notify.send_msg_with_jpg( res['subject'], res['message'], fname, spam ) # Store all current images sfname = 'spot' + str(spot['number']) + '.jpg' cfname = os.path.join( dirs['cd'], sfname ) copyfile(fname,cfname) # Log spot data log.logSpot( camera['im_ts'], spot, dirs['sld'] ) # reset failure counter camera['nFails'] = 0 # delete the image that has been processed os.remove(fname) else: existantFailure = True if existantFailure: camera['nFails'] += 1 if camera['nFails'] == 5: msg = """ %s Camera %d is not producing images ! """ % (time.asctime(),camera['number']) notify.send_msg('Error',msg,to) print msg # Protect against giant seepage if camera['nFails'] > 100: camera['nFails'] = 100 # store the current state of the camera #log.addState( camera, dirs['cld'] ) log.recordState( camera, dirs['csd'] ) return
def judge( spots, freeTime, monthlies, to, team, imdir, vdir, udir ): for s, spot in spots.iteritems(): if s in monthlies: continue if spot['timeOccupied'] > freeTime and not spot['paid']: if not spot['violation']: spot['violation'] = True lt = time.localtime(spot['occupationStartTime']) tss = time.strftime('%Y%m%dT%H%M%S',lt) ss = str(s) fname = 'spot' + ss + '.jpg' fname = os.path.join( imdir, fname ) vfname = 'spot' + ss + '_' + tss + '.jpg' vfname = os.path.join( vdir, vfname ) copied = try_copy( fname, vfname ) send_image = vfname sub = "Violation" msg = """ %s Spot %d in VIOLATION """ % (time.asctime(lt), s) if copied: notify.send_msg_with_jpg( sub, msg, send_image, team ) else: notify.send_msg( sub, msg, team ) else: spot['violation'] = False if spot['paid'] == 1 and spot['timePresent'] == 0: pst = spot['payStartTime'] pet = spot['payEndTime'] oet = spot['occupationEndTime'] if oet < pst : if not spot['failedDetection']: spot['failedDetection'] = True tss = spot['payStartTime'] pstt = time.localtime(tss) pss = time.strftime('%Y%m%dT%H%M%S',pstt) ss = str(s) fname = 'spot' + ss + '.jpg' fname = os.path.join( imdir, fname ) ufname = 'spot' + ss + '_' + pss + '.jpg' ufname = os.path.join( udir, ufname ) copied = try_copy( fname, ufname ) send_image = ufname sub = "Failed Detection?" msg = """ %s Spot %d Detection Failed, or ... Person left spot within pay period """ % (pss, s) if copied: notify.send_msg_with_jpg( sub, msg, send_image, to ) else: notify.send_msg( sub, msg, to ) else: spot['failedDetection'] = False else: spot['failedDetection'] = False return
# # os.system(ncall) # # if n_logs == 9: # sys.exit() except Exception, e: tb = traceback.format_exc() msg = """ %s Catch2 is going offline due to user error ! Check my error logs for details... Exception: %s Traceback: %s""" % (time.asctime(),str(e),tb) print "%s\n\n%s" % (msg, str(e)) notify.send_msg('Error',msg,toall) os.killpg(os.getpgid(proc.pid), signal.SIGTERM) sys.exit() # Do it all over again, after some rest time.sleep(sleepytime) os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
processCameras.processCameras(cameras, dirs, toErr) processSpots.write(cameras, spots) processApi.processApi(data_dir, spots, monthlies, toErr) processSpots.judge(spots, violationThresh, monthlies, toErr, toForce, cd, vd, ud) writeTable.writeTable(spots) writeDemo.writeTable(spots) except Exception, e: tb = traceback.format_exc() msg = """ %s Catch is going offline due to user error ! Check my error logs for details... Exception: %s Traceback: %s""" % (time.asctime(), str(e), tb) print "%s\n\n%s" % (msg, str(e)) notify.send_msg('Error', msg, toErr) sys.exit() # Do it all over again, after some rest time.sleep(sleepytime)
def processCameras( cameras, dirs, to, spam=None ): for c, camera in cameras.iteritems(): # Write jpeg to image dir and # populate camera dict with time info result = gi.get_image( camera, dirs['wd'] ) if result['success']: delta_time = result['delta_time'] fname = result['fname'] # Process image ai.analyzeImage( fname, camera ) # Judging for spot in camera['spots']: present = dp.determinePresence( spot ) res = ep.evaluatePresence( spot, present, delta_time, camera['im_ts'] ) if res['message'] is not None and spam is not None: notify.send_msg_with_jpg( res['subject'], res['message'], fname, spam ) # Store all current images sfname = 'spot' + str(spot['number']) + '.jpg' cfname = os.path.join( dirs['cd'], sfname ) copyfile(fname,cfname) # Log spot data log.logSpot( camera['im_ts'], spot, dirs['sld'] ) # reset failure counter camera['nFails'] = 0 # delete the image that has been processed os.remove(fname) else: camera['nFails'] += 1 if camera['nFails'] == 5: msg = """ %s Camera %d is not producing images ! """ % (time.asctime(),camera['number']) notify.send_msg('Error',msg,to) print msg # Protect against giant seepage if camera['nFails'] > 100: camera['nFails'] = 100 # store the current state of the camera #log.addState( camera, dirs['cld'] ) log.recordState( camera, dirs['csd'] ) return
processSpots.write( cameras, spots ) processApi.processApi( data_dir, spots, monthlies, toErr ) processSpots.judge( spots, violationThresh, monthlies, toErr, toForce, cd, vd, ud ) writeTable.writeTable( spots ) writeDemo.writeTable( spots ) except Exception, e: tb = traceback.format_exc() msg = """ %s Catch is going offline due to user error ! Check my error logs for details... Exception: %s Traceback: %s""" % (time.asctime(),str(e),tb) print "%s\n\n%s" % (msg, str(e)) notify.send_msg('Error',msg,toErr) sys.exit() # Do it all over again, after some rest time.sleep(sleepytime)
slog_fname = 'spot' + str(spot['number']) + '.log' slog_ffname = os.path.join(sld, slog_fname) with open(slog_ffname, 'a') as l: w = csv.writer(l) w.writerow(slog_data) # Reset failure notification log failure_notifications = 0 else: msg = """ %s Camera %d is not producing images ! """ % (time.asctime(), camera['number']) if failure_notifications < 5: notify.send_msg(msg, to) failure_notifications += 1 elif failure_notifications == 5: msg += """ Camera is BROKEN -- DONE SENDING MESSAGES LIKE THIS""" print msg # cleanup: # delete the image that has been processed os.remove(fname) # store the current state of the camera dict_fname = 'camera' + str(c) + '.dict' dict_ffname = os.path.join(csd, dict_fname)