from flask import Flask
from flask import request
import json
import pymysql
app = Flask(__name__)

@app.route('/')
def hello_world():
  con='接口:http://fb.qingningz.cn/fb\n请求方式:GET\n示例:http://fb.qingningz.cn/fb?name=句子图片'
  return con
@app.route('/fb',methods=['get','post'])
def fb():
  name_a = request.values.get('name')
  print(name_a)
  if name_a=='':
    return'你什么参数都不给,在查毛线'
  else:
    conn = pymysql.connect(
      host='localhost',
      port=3306,
      user='用户名',
      passwd='密码',
      db='数据库名',
      charset='utf8')
    #
    cur = conn.cursor()
    sql = "SELECT * FROM fbAPI WHERE shuju LIKE '%{}%'".format(name_a)
    cur.execute(sql)
    results = cur.fetchone()
    print(results)
    conn.close()
    if results=='None':
      return 'wu'
    else:
      return json.dumps(results,ensure_ascii=False)#将字典转换为Json串,json是字符串

if __name__ == '__main__':
 app.run(debug=True)

 

© 版权声明
评论 抢沙发