Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, flash, render_template, request, url_for
- import pymysql.cursors
- conn = pymysql.connect(user = 'root',
- passwd = '2244ssff11',
- host = '127.0.0.1',
- db = 'tweets',
- charset = 'utf8mb4',
- cursorclass=pymysql.cursors.SSCursor)
- cursor = conn.cursor()
- app = Flask(__name__)
- @app.route("/", methods=["GET", "POST"])
- def index():
- if request.method == "POST":
- result = []
- search_open = open("accounts.txt", "r")
- search_query = request.form.get("query")
- search_query = search_query.lower()
- for account_name in search_open.readlines():
- cursor.execute("SELECT id, name, tweet, created_at, url FROM tweets WHERE name=%s ORDER BY created_at DESC" % (account_name.strip()))
- test_call = cursor.fetchall()
- for data in test_call:
- if search_query in data[2].lower():
- result.append({'id':data[0], 'name':data[1], 'tweet':data[2], 'created_at':data[3], 'url':data[4]})
- cursor.close()
- search_open.close()
- conn.close()
- return render_template("search.html", results = result)
- else:
- return render_template("index.html")
- if __name__ == "__main__":
- app.run(host='0.0.0.0')
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement