import sqlite3 from pprint import pprint as print from flask import Flask, request, Response, redirect, jsonify from db_wrapper import request_db app = Flask(__name__) db = request_db('database') @app.route('/first') def first(): dct = {} response = [] cities = db.request_select_join('*', 'Users', 'Actions') for item in cities: if item[2] in dct.keys(): dct[item[2]] += 1 else: dct[item[2]] = 1 for item in dct.keys(): response.append((dct[item], item)) response.sort(key=lambda tup: tup[0]) return jsonify(response) @app.route('/second') def second(): lst = [] dct = {} lst_sorted = [] actions = db.request_select_join('*', 'Users', 'Actions')
import sqlite3 import uuid import time from flask import Flask, request, Response, redirect, jsonify from db_wrapper import request_db db = request_db('db.db') def add_note(data): if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 if ('title' not in data) or ('text' not in data): return jsonify({"msg": "Bad request"}), 400 id = str(uuid.uuid4()) title = data['title'] text = data['text'] if len(title) > 30 or len(text) > 500: return jsonify({"msg": "Bad request"}), 400 date_create = int(time.time()) date_update = date_create try: db.request_insert('Notes', 'id, title, text, date_create, date_update', id, title, text, date_create, date_update) except Exception as e: print(e) return jsonify({"status": "OK"}), 200
from flask import render_template, flash, redirect, url_for from app import app from app.forms import LinkForm import db_wrapper from hash import getHash db = db_wrapper.request_db('db.db') @app.route('/', methods=['GET', 'POST']) # @app.route('/index', methods=['GET', 'POST']) def index(): form = LinkForm() if form.validate_on_submit(): hashed = None try: last_id = db.request_insert_one('Urls', 'url', form.link._value()) hashed = getHash(last_id[0][0]) db.request_update('Urls', 'short_url', hashed, 'url_id', last_id[0][0]) except Exception: print(Exception) flash('Сокращенная ссылка - {}'.format(hashed)) return redirect(url_for('index')) return render_template('index.html', title='Home', form=form) @app.route('/short/<short_url>') def short(short_url): reqv = db.request_select('url, times_opened', 'Urls', 'short_url', short_url) print(reqv) times_opened = reqv[0][1] + 1 print(times_opened)