def get_time_list(initial, end, interval): """the purpose of this function is to calculate the amount and at what intervals they should occur.""" import datetime as dt # ensure data is actually legit try: initial = dt.datetime.strptime(initial, "%Y-%m-%d %H:%M:%S") end = dt.datetime.strptime(end, "%Y-%m-%d %H:%M:%S") except ValueError: fl.flask("Internal Server Error", "error") return None except TypeError: pass # time delta indicates the period we need to calculate over time_delta = end - initial # now divide this between the interval int = dt.timedelta(days=interval) # now create and return a list of each interval name = [] start_date = [] end_date = [] for i in range(0, round(time_delta.days / int.days), 1): t_start = initial + dt.timedelta(i * int.days) t_end = t_start + dt.timedelta(7 - 1) start_date.append(t_start) end_date.append(t_end) name.append( dt.datetime.strftime(t_start, "%d-%m-%y") + "->" + dt.datetime.strftime(t_end, "%d-%m-%y")) return name, start_date, end_date
def hello_world(name): return "Hello, {}!".format(name) if __name__ == "__main__": app.run(host=’0.0.0.0’, port=8080) # In[ ]: from flask import flask app = flask(__name__) # request from url @app.route(’18.207.92.139:8000/random company’, methods=[’GET’]) ##def hello_world(name): ##return "Hello, {}!".format(name) ##return render template? ##GET_RESP = REQUESTS.GET(’18.207.92.139:8000/random company’,TIMEOUT) get_resp = requests.get(’18.207.92.139:8000/random company’, timeout=5) ##post_resp = requests.post(URL_STRING, data=DICTIONARY) # Download the HTML of this website and extract the name and purpose of the generated company. # beautiful soup to parse through HTML # repeat x50 with sleeps ## write to external file, use file handler with open() as fh
def post(self): if 'logout' in flask.request.form: flask.session.pop('username', None) return flask.redirect(flask.url_for('index')) required = ['username', 'passwd'] for r in required: if r not in flask.request.form: flask.flask("Error: {0} is required.".format(r)) return flask.redirect(flask.url_for('index')) username = flask.request.form['username'] passwd = flask.request.form['passwd'] if username in users and users[username] == passwd: flask.session['username'] = username else: flask.flash("Username doesn't exist or incorrect password") return flask.redirect(flask.url_for('index'))
# Flask Tutorial: http://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972 from flask import flask app = flask(option_app)
from flask import flask app=flask("marconi") @app.route ('/') aef hello(); return "ciao"
def main(): hours = [744, 672, 744, 720, 744, 720, 744, 744, 720, 744, 720, 744] month = 9 value = 0 powerUsage = [] modelUsage = [] deltas = [0] # Uncomment below to run a simulation using different delta perameters # while(value < 3): # deltas.append(value) # value = value+0.5 # Uncomment below to run a simulation using different time thresholds # timeThresh=[] # value=1 # while(value < 10): # timeThresh.append(value) # value = value+0.5 # power = [0.2] models = [1, 2, 3, 4] kVals = [15] pelt = [] # Uncomment below to run a simulation using different temperature thresholds # thresh=10 # kVals = [] # while(thresh<15.5): # kVals.append(thresh) # thresh+=0.5 # visualiseAllTemp() visualiseMultisim() for i in models: month = 9 for delta in deltas: for k in kVals: # Change 0.2 to change the power of the Peltier device used fl = flask(i, k, delta, 0.2) with open("temp.csv") as f: # Change to step.csv to view the step response for temp in f: fl.updateTemp(float(temp)) value = value + 1 if (value > hours[month % 12]): circ = circuit( # Calculates the monthly energy usage of the device (fl.peltierTime/(60**2)), hours[month % 12]) powerUsage.append(circ.calculateTotalPower()) value = 0 month = (month+1) fl.peltierTime = 0 # if((month % 12) == 2): #Saves the time that the peltier is on during the worst month # pelt.append(fl.secondsOn) fl.secondsOn = [] # modelUsage.append(powerUsage) powerUsage = [] # Uncomment below to visualise various aspects of the device, used in finding optimal perameters and viewing the device's functioning # Uncomment to stop visualising the flask's internal temperature during the simulation fl.visualisedata()
from flask import Flask as flask from flask import request from flask import render_template import leds app = flask(__name__) @app.route('/', methods=['POST']) def index(name=None): if request.method=='POST': value = request.form['btn'] print value, type(value) if value=='1': leds.fade(leds.encode(255, 0, 0)) elif value=='2': leds.fade(leds.encode(0, 255, 0)) elif value=='3': leds.fade(leds.encode(0, 0, 255)) return render_template('index.html', name=name) if __name__ == '__main__': app.debug = True app.run()
from flask import flask, fender_template app - flask(__name__) @app.ruote('/') def home(): return "WEbsite Title goes here!" if __name__ == "__main__": app.run(degbug=True)
from flask import flask imdb_api =flask(__name__) @imdb_api.route('/') def home_page(): return "I've created my first API service!" if __name__ ='__main__': imdb_api.run()
from flask import flask app = flask(__app__) """ Flask te permite usar plantillas para el contenido dinámico de páginas web. se utiliza para generar resultados a partir de un archivo de plantilla basado en el motor Jinja2 que se encuentra en la carpeta de plantillas de la aplicación. """
from flask import flask.render_template app - flask(_name_) @app.route('/') det index(): name='kyaw kyaw' return render_template('index.htal'.name=name)^S^X S
from flask import Flask as flask from flask import redirect, url_for, render_template, flash, session, request import psycopg2 as psql import MySQLdb from login import login_api #connection = psql.connect(user = "******", # password = "******", # host = "127.0.0.1", # port = "5432", # database = "webapp") connection = MySQLdb.connect("localhost", "root", "", "webapp") con = connection.cursor() app = flask(__name__, template_folder = 'templates') app.secret_key = "A34562EF" app.register_blueprint(login_api) #con.execute('use webapp') if __name__ == "__main__": app.run() @app.route('/signup', methods = ['GET', 'POST']) def signup(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') check_sql_1 = "SELECT * FROM users WHERE username = '******'".format(username,) con.execute(check_sql_1)
from flask import flask # Import Flask to allow us to create our app. app = flask(__name__) # Global variable __name__ tells Flask whether or not we are running the file # directly, or importing it as a module. print(__name__) # Just for fun, print __name__ to see what it is @app.route('/') # The "@" symbol designates a "decorator" which attaches the following # function to the '/' route. This means that whenever we send a request to # localhost:5000/ we will run the following "hello_world" function. def hello_world(): return 'Hello World!' # Return the string 'Hello World!' as a response. if __name__=="__main__": # If __name__ is "__main__" we know we are running this file directly and not importing # it from a different module app.run(debug=True) # Run the app in debug mode. @app.route('/success') def success(): return "success" @app.route('/hello/<name>') # for a route '/hello/____' anything after '/hello/' gets passed as a variable 'name' def hello(name): print(name) return "hello "+name @app.route('/users/<username>/<id>') # for a route '/users/____/____', two parameters in the url get passed as username and id def show_user_profile(username, id): print(username) print(id) return "username: "******", id: " + id
from flask import flask application = flask(__name__) @application.route('/') def hello(); return "Hello World" if __name__ == "__main__"; application.run()
from flask import flask, request import json app = flask("Web App Mahasiswa") data_mahasiswa = [{"nim": 123, "nama": "Andi"}, {"nim": 234, "nama": "Budi"}] @app.route('/mahasiswa', methods=['POST']) def add_mahasiswa(): nim = request.json['nim'] nama = request.json['nama'] mahasiswa_baru = {"nim": nim, "nama": nama} data_mahasiswa.append(mahasiswa_baru) json_mahasiswa = json.dumps(data_mahasiswa) return json_mahasiswa @app.route('/mahasiswa', methods=['GET']) def edit_mahasiswa(): nim = request.json['nim'] nama = request.json['nama'] mahasiswa_baru = {"nim": nim, "nama": nama} pass @app.route('/mahasiswa/', methods=['GET']) def delete_mahasiswa(): nim = request.json['nim'] nama = request.json['nama'] mahasiswa_baru = {"nim": nim, "nama": nama}
from flask import flask app=flask(_name_) @app.route('/') def index(); return 'hello, world'
from flask import Flask as flask, render_template, request, send_from_directory, jsonify import json import query import signal import socket app = flask(__name__, static_url_path='', static_folder='templates/') @app.route('/query', methods=['POST']) def queryAnalyzer(): nlq = str(request.form['query']) print("Query: " + nlq) results = query.query(nlq) print("query done") # print(results) return json.dumps({'query': nlq, 'data': results}) @app.route('/shutdown', methods=['GET', 'POST']) def shutdown_server(): func = request.environ.get('werkzeug.server.shutdown') if func is None: raise RuntimeError('Not running with the Werkzeug Server') print('Quitting! Bye!') func() return 'Shut Down' @app.route('/') def home():
from flask import flask app = flask(__name__) @app.route("/") def index(): return "hello, world"
from flask import flask app = flask(_name_) #_name_ 代表目前執行的模組 @app.route("/") # decorator 附加功能 def home(): return "Hello Flask" if _name_ == "_main_": #如果主程式執行 app.run() #立即啟動伺服器