def updateStatus(id, status): log('Updating application ' + id + ' status to ' + status) # make sure this new status is valid if status not in config.statuses: log('Status update failed; invalid status') return 'Status invalid; no update made.' # update status data = appDict(id) data['Status'] = status with appFile(id, 'w') as file: json.dump(data, file) log('Status update successful') # email member and engineers subject = 'R3IT application status updated' message = "The status of application " + id + \ " has been updated to '" + status + "'. " + \ "Use the following link to your application for more information: " + \ "demo.r3it.ghw.io/report/" + data['ID'] mailer.sendEmail(data.get('Email (Member)', ''), subject, message) mailer.mailEngineers(subject, message) return 'Status updated to ' + status
def plot_lines(direction,x_rows,y_rows): trace1 = go.Scatter(x=x_rows, y=y_rows, # Data mode='lines', name=y_axis_key # Additional options ) title = 'Going' + direction + x_axis_key + 'VS' + y_axis_key layout = go.Layout(title=title, xaxis=dict( title= x_axis_key, titlefont=dict( family='Courier New, monospace', size=18, color='#7f7f7f' ) ), yaxis=dict( title=y_axis_key, titlefont=dict( family='Courier New, monospace', size=18, color='#7f7f7f' ) ), plot_bgcolor='rgb(230, 230,230)') fig = go.Figure(data=[trace1], layout=layout) # Plot data in the notebook url = py.plot(fig, filename=fileName + '-' + title) subject = 'Graph Report for ' + fileName + '-' + title sendEmail(url,subject)
def newpassword(email, token): '''create new password for account''' notification = request.args.get('notification', None) if request.method == "GET": try: userDict = userAccountDict(email) except: return redirect( f"/forgot?{urlencode({'notification': 'Error: Invalid password reset link.'})}" ) if userDict[email].get('resetToken', '') == token: return render_template("newpassword.html", email=email, token=token, notification=notification) else: return redirect( f"/forgot?{urlencode({'notification': 'Error: Invalid password reset link.'})}" ) if request.method == "POST": password = request.form['password'] userDict = {email: {'password': hashPassword(email, password)}} with userAccountFile(email, 'w') as userFile: json.dump(userDict, userFile) mailer.sendEmail(email, 'R3IT Password Reset successfully', 'Your R3IT password has been reset successfully.') log('Password reset successfully for ' + email) return redirect( f"/login?{urlencode({'notification': 'Success: Password successfully updated.'})}" )
def forgot(): '''Sends email to user with a password reset link''' notification = request.args.get('notification', None) if request.method == "GET": return render_template("forgot.html", notification=notification) if request.method == "POST": email = request.form['email'] try: userDict = userAccountDict(email) except: log('Password reset requested for ' + email + '; account not found') return redirect( f"/forgot?{urlencode({'notification': 'Error: Account not found.'})}" ) userDict[email]['resetToken'] = str(random.randint(100000, 1000000)) with userAccountFile(email, 'w') as userFile: json.dump(userDict, userFile) link = 'demo.r3it.ghw.io/newpassword/' + email + '/' + userDict[email][ 'resetToken'] mailer.sendEmail( email, 'R3IT Password Reset Link', 'Use the following link to reset your password: '******'Password reset link sent to ' + email) return redirect( f"/forgot?{urlencode({'notification': 'Success: Password reset email sent.'})}" )
def sendDelegationEmail(id, notification=''): mailer.sendEmail( appDict(id)['Email (Member)'], 'Approve interconnection application', 'Click this link to approve ' + appDict(id)['Email (Contractor)'] + ' to administer an interconnection application for ' + appDict(id)['Address (Service)'] + ': ' + config.DOMAIN + '/delegate/' + id + '/' + hashPassword('delegation', id)) return redirect(f"""/report/{id}?{urlencode( {'notification': f'Success: {notification} Delegation email sent.'})}""" ) # Does notification insert really need to be there?
def check_for_objects(): global last_epoch while True: try: frame, found_obj = camera.get_object(object_classifier) if found_obj and (time.time() - last_epoch) > update_interval: last_epoch = time.time() sendEmail(frame) except: print("error sending email:", sys.exc_info()[0])
def updateApp(id): # get original and edited apps app = appDict(id) appEdits = {key: item for key, item in request.form.items()} # compare original and edited apps and # track values that are unchanged unchanged = [] for key in appEdits.keys(): if key in app.keys(): originalVal = app[key] editedVal = appEdits[key] if originalVal == editedVal: unchanged.append(key) # only keep the values that are different as edits for key in unchanged: del appEdits[key] # save differences into edits.json with appEditsFile(app['ID'], 'w') as editsfile: json.dump(appEdits, editsfile, indent=4) # save and update the statuses of the app app['Previous Status'] = app['Status'] app['Status'] = 'Engineering Review' with appFile(app['ID'], 'w') as appfile: json.dump(app, appfile, indent=4) # log event log('Application ' + app['ID'] + 'edited') # mail engineers the edits link = 'demo.r3it.ghw.io/report/' + app['ID'] mailer.mailEngineers( 'R3IT application edited', 'Application with ID ' + app['ID'] + ' has been edited. Use the following link for details: ' + link) mailer.sendEmail( app.get('Email (Member)', ''), "R3IT application edited", "Your edits to the application with ID " + app['ID'] + ' ' + 'have been submitted.') # redirect to the report but with the edits displayed return redirect(f"""/report/{id}?{urlencode( {'notification': '''Success: Application edits submitted. Awaiting engineer approval.'''})}""")
def add_to_appQueue(): '''Adds an interconnection application to the queue''' app = {key: item for key, item in request.form.items()} app['Time of Request'] = str(datetime.now()) app['Status'] = 'Payment Required' app['ID'] = str( int(datetime.timestamp(datetime.now()) * 10**7) + random.choice(range(999))) try: os.makedirs(appDir(app['ID'])) except: pass with appFile(app['ID'], 'w') as appfile: json.dump(app, appfile) log('Application ' + app['ID'] + 'submitted') link = 'demo.r3it.ghw.io/report/' + app['ID'] mailer.mailEngineers( 'New R3IT application', 'New application with ID ' + app['ID'] + ' submitted. Use the following link for details: ' + link) mailer.sendEmail( app.get('Email (Member)', ''), "R3IT application submitted", "Your application with ID " + app['ID'] + ' submitted. Use the following link for details: ' + link) # TODO: Figure out the fork-but-not-exec issue (below -> many errors) # run analysis on the queue as a separate process if config.enableAutomaticScreening == True: p = Process(target=interconnection.processQueue, args=(processQueueLock, )) p.start() return redirect(f"""/payment/{app['ID']}?{urlencode( {'notification': f'''Success: Application submitted. Please click 'checkout' to complete payment.'''})}""")
import time import sys import process import mailer #ongoing process while (1 > 0): response = process.newProcess() print 'Send error email?: ' + str(not response) #if the process came back with an error... send email if response == False: mailer.sendEmail() print('Restarting Loop in 60s') print('') time.sleep(60)