-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
143 lines (110 loc) · 4.22 KB
/
server.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from flask import Flask, render_template, request, send_file, redirect, url_for
from weather import get_current_weather
from waitress import serve
from finance import get_earnings
from ytvideo import get_video
from werkzeug.utils import secure_filename
import cv2
import os
app = Flask(__name__)
UPLOAD_FOLDER = 'static/uploads/'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
@app.route('/index')
def index():
return render_template('main.html')
@app.route('/acceptweather')
def accept_weather():
return render_template("index.html")
@app.route('/weather')
def get_weather():
city = request.args.get('city')
weather_data = get_current_weather(city)
if not weather_data['cod'] == 200:
return render_template("error.html")
return render_template(
"weather.html",
title=weather_data["name"],
status = weather_data["weather"][0]["description"].capitalize(),
temp=f"{weather_data['main']['temp']:.1f}",
feels_like=f"{weather_data['main']['feels_like']:.1f}"
)
@app.route('/finance')
def finance_graph():
st1 = request.args.get('stock1')
st2 = request.args.get('stock2')
st3 = request.args.get('stock3')
x = get_earnings(st1)
y = get_earnings(st2)
z = get_earnings(st3)
stockname1 = x["meta"]["symbol"]
earningsdaterevenue1 = x["body"]["earnings"]["earningsChart"]["earningsDate"][0]["raw"]
earningsdate1 = x["body"]["earnings"]["earningsChart"]["earningsDate"][0]["fmt"]
stockname2 = y["meta"]["symbol"]
earningsdaterevenue2 = y["body"]["earnings"]["earningsChart"]["earningsDate"][0]["raw"]
earningsdate2 = y["body"]["earnings"]["earningsChart"]["earningsDate"][0]["fmt"]
stockname3 = z["meta"]["symbol"]
earningsdaterevenue3 = z["body"]["earnings"]["earningsChart"]["earningsDate"][0]["raw"]
earningsdate3 = z["body"]["earnings"]["earningsChart"]["earningsDate"][0]["fmt"]
return render_template(
"finance.html",
stockName1 = stockname1,
earningsdate1 = earningsdate1,
earningsestimate1 = earningsdaterevenue1,
stockName2 = stockname2,
earningsdate2 = earningsdate2,
earningsestimate2 = earningsdaterevenue2,
stockName3 = stockname3,
earningsdate3 = earningsdate3,
earningsestimate3 = earningsdaterevenue3
)
@app.route('/acceptf')
def accept_stock():
return render_template("acceptstock.html")
@app.route('/error')
def error_page():
#Separate error page
return render_template("error.html")
@app.route('/ytdown')
def yt_video_downloader():
video_url = request.args.get('youtube-link')
responses = get_video(video_url)
video_path = responses["adaptiveFormats"][0]["url"]
audio_path = responses["adaptiveFormats"][-1]["url"]
return render_template(
"ytplay.html",
videoLink = video_path,
audioLink = audio_path
)
@app.route('/ytaccept')
def get_yt_page():
return render_template("youTube.html")
@app.route('/upload', methods=['POST'])
def upload_image():
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
if file.filename == '':
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(filepath)
img = cv2.imread(filepath)
if img is None:
return 'Error: Could not open the uploaded image.'
processed_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
processed_filename = 'processed_' + filename
processed_filepath = os.path.join(app.config['UPLOAD_FOLDER'], processed_filename)
cv2.imwrite(processed_filepath, processed_image)
return render_template('opencv.html', uploaded_image=filename, processed_image=processed_filename)
return redirect(request.url)
@app.route('/trialupload')
def opencvpage():
return render_template('opencv.html')
if __name__ == "__main__":
#serve(app, host="0.0.0.0", port=8000)
app.run(debug=True)