select name from user where replace(phone, '-', '') like '%12345678901%';
для начала from sqlalchemy import create_engine
db_connect = create_engine('mysql://root:pwd@localhost/dbname', encoding='koi8-r')
user_id = 36200
conn = db_connect.connect()
query = conn.execute("SELECT id, login, fio FROM user WHERE id=%d " %int(user_id))
for i in query.cursor:
print(i)
>>> (36200, 'login', 'ëÁÊ åËÁÔÅÒÉÎÁ îÉËÏÌÁÅ×ÎÁ')
from urllib import request
import json
from sys import argv
with request.urlopen("http://server.ru:8088/users/{0}".format(argv[1])) as url:
data = json.loads(url.read())
print(data['data'][0]['fio'])
#!/usr/bin/env python3
from flask import Flask, request, jsonify
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
db_connect = create_engine('mysql://root:passwd@localhost/my_database', encoding='koi8-r')
app = Flask(__name__)
api = Api(app)
class Users(Resource):
def get(self, user_id):
conn = db_connect.connect()
query = conn.execute("SELECT id, login, fio FROM user WHERE id=%d " %int(user_id))
result = {'data': [dict(zip(tuple (query.keys()), i)) for i in query.cursor]}
return jsonify(result)
api.add_resource(Users, '/users/<int:user_id>')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8088, threaded=True, debug=True)