Last active
May 9, 2020 07:45
-
-
Save burning-croissant/5ebbca9aa39c74a3dbfc5ec2bf46c54f to your computer and use it in GitHub Desktop.
[Recipe of Code] GET /makers/{mid}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pymysql | |
from flask import Flask, request | |
from flask_restful import Api, Resource | |
host = 'your_mysql_ip' | |
user = 'your_username' | |
password = 'your_password' | |
database = 'rest' | |
class Maker(Resource): | |
""" /makers/{mid} """ | |
def get(self, mid): | |
query = f'SELECT * FROM rest.Makers where id={mid}' | |
conn = pymysql.connect(host=host, user=user, password=password, database=database) | |
dataframe = pd.read_sql(sql=query, con=conn) | |
conn.close() | |
maker = dataframe.to_dict('record')[0] | |
ret = { 'data': maker } | |
return ret, 200 | |
if __name__ == '__main__': | |
app = Flask(__name__) | |
api = Api(app) | |
api.add_resource(Maker, '/makers/<mid>') | |
app.run(host='0.0.0.0', port=5555) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment