import time
my_list = []
data = 12
add_timer = int(time.time())
clear_timer = int(time.time())
while True:
if int(time.time()) - clear_timer >= 15:
clear_timer = int(time.time())
my_list.clear() # Очищаем список каждые 15 сек
print('Удаляем')
if int(time.time()) - add_timer >= 2:
add_timer = int(time.time())
my_list.append(data) # Записываем числа в список каждые 2 сек
print('Записываем')
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/price', methods=['GET', 'POST'])
def price():
if request.method == 'POST':
price = request.form['price']
if int(price) < 1000:
return jsonify({'msg': 'Нищий'})
else:
# Сюда алгоритм
return jsonify({'msg': 'Вот тебе компьюдахтех'})
else:
return {'msg': '!'}
if __name__ == '__main__':
app.run()
import requests
price = 10000
r = requests.post('http://localhost:5000/price', data={'price':price})
print(r.json())
import pymysql.cursors
def idProduct(id):
connection = pymysql.connect(host='localhost',user='ЛОГИН', password='ПАРОЛЬ', db='ИМЯБД',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
SQL = "SELECT * FROM mytable WHERE id=%s"
cursor.execute(SQL, (id))
result = cursor.fetchall()
return result
finally:
connection.close()
print(idProduct(1))
[{'id': 1, 'name': 'Трусы', 'number': 3543352, 'price': 100}]
def numberProduct(number):
connection = pymysql.connect(host='localhost',user='ЛОГИН', password='ПАРОЛЬ', db='ИМЯБД',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
SQL = "SELECT * FROM mytable WHERE `number`=%s"
cursor.execute(SQL,(number))
result = cursor.fetchall()
return result
finally:
connection.close()
print(numberProduct(2123332))
[{'id': 3, 'name': 'Штаны', 'number': 2123332, 'price': 500}]