#coding=utf-8
__author__ = 'mac'
#API地址:http://localhost:5000/time, Get方法
import time
from flask import Flask
import logging
app=Flask(__name__)
#写入日志,用内置的basicConfig的格式写入,level:日志级别,format:格式, datefmt:时间,filenam:日志文件名,filemode:写入模式是以追加方式
def write_log(msg):
logging.basicConfig(level=logging.ERROR,
format='%(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='app.log',
filemode='a')
logging.error(msg)
@app.route('/time')
def index():
write_log(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
@app.route('/loop1')
def loop():
while 1:
a=1
if __name__=='__main__':
#下面是本机的Ip,若要在服务器上可调,就要将本机的ip地址做路由器端口映射即可
# app.run(host='111.0.0.8',port=5001,debug=True)
#用到服务器上改成下面服务器的ip即可,端口号随便
app.run(host='114.215.196.178',port=5001,debug=True)