-
ANTO SAGAYA JUSTIN R authoredANTO SAGAYA JUSTIN R authored
app.py 2.36 KiB
from flask import Flask
app = Flask(__name__)
import os
import math
basename = '/iotcloud'
# app.debug = True ( for any debug error for True that line )
# @app.route
# 1.To Searching route ex:[172.30.0.231:7000/hello] to view your flask project.
@app.route('/hello')
def hello_world():
return "<h1>Hello World 123<h1/>"
@app.route('/')
def hello():
return "<h1>Hello Justin Welcome<h1/>"
@app.route('/whoami')
def whoami():
return "<h1>"+os.popen('whoami').read()+"<h1/>"
# whoami:
# Lhis Linux Command To Return This System Username For Example [ justinmass2001 ].
@app.route(basename+'/cpuinfo')
def cpuinfo():
return "<pre>" "<h3>"+ os.popen('cat /proc/cpuinfo').read() +"<pre/>" "<h3/>"
'''
<pre> and cat /proc/cpuinfo:
1. <pre> = This HTML Tag Which Terminal output You Can Inset to Same output to display
Not Using <pre> output result:
processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 183
Example Result using <pre> output:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 183
2. cat /proc/cpuinfo = This is Linux Command For CPU Full Informations.
'''
@app.route(basename+'/echo', methods = ['GET','POST'])
def echo_help():
return '<h1>'+"Please use as /echo/some string"+'</h1>'
@app.route(basename+'/echo/<string>')
# echo:
# echo = your any input type to same return output this echo
# Example:[172.30.0.231:7000/iotcloud/echo/justin] output result justin.
def echo(string):
return "You said: {}".format(string)
# app.add_url_rule (Basename+'/whoami','whoami',whoami)
# app.add_url_rule (Basename+'/cpuinfo','cpuinfo',cpuinfo)
@app.route(basename+'/pow/<int:a>/<int:b>')
def power ( a , b ):
try:
return "pow of {}, {}: {}".format ( a , b ,math.pow( a , b ))
except:
return "This is too much"
# <int:a> /<int:b>:
# int = integer value.
# search browser 172.30.0.231:7000/iotcloud/pow/(integer valu)10/30.
# try = error handling any error to return except command.
if __name__ == '__main__':
app.run(host = '0.0.0.0' , port = '7000' , debug = True )
# host = '0.0.0.0':
# your access all type of IP address to add [host = '0.0.0.0'] Running on all IP addresses