-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (34 loc) · 1.14 KB
/
main.py
File metadata and controls
47 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import yaml
import json
from flask import Flask, render_template
import mysql.connector
import variables
api_link = "https://techy-api.vercel.app/api/json"
app = Flask(__name__)
def get_response():
request = requests.get(api_link)
json_response = request.json()
yaml_response = yaml.dump(json_response, default_flow_style=False)
return(yaml_response)
@app.route('/')
def index():
mydb = mysql.connector.connect(
host=variables.host,
user=variables.user,
password=variables.password,
database=variables.database
)
mycursor = mydb.cursor()
mycursor.execute("CREATE TABLE IF NOT EXISTS tech_phrases (ID INT AUTO_INCREMENT PRIMARY KEY, CREATED TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONTENT TEXT NOT NULL)")
content = (get_response())
def data_entry():
sql = "INSERT INTO tech_phrases (content) VALUES(%s)"
val = [(content)]
mycursor.execute(sql, val)
mydb.commit()
data_entry()
mydb.close()
return render_template(f'index.html', variable=(content))
if __name__ == "__main__":
app.run(debug=True)