-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.py
126 lines (99 loc) · 3.56 KB
/
weather.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
from flask import Flask, render_template, request, redirect
import json
import math
import urllib.request
from dotenv import load_dotenv
import os
load_dotenv()
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return render_template('home.html')
@app.route('/weather', methods=['GET'])
def weather_route():
location = request.args.get('location')
if location == None:
return '<h1>Please specify a location!</h1><br/><a href="/">Home Page</a>'
try:
source = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?q=' + location + '&appid=' + os.getenv("WEATHER_API_KEY")).read()
list_of_data = json.loads(source)
fahrenheit = math.floor(list_of_data['main']['temp'] - 273.15) * 9/5 + 32
data = {
"country_code": str(list_of_data['sys']['country']),
"coordinate": str(list_of_data['coord']['lon']) + ' '
+ str(list_of_data['coord']['lat']),
"temp": str(fahrenheit),
"pressure": str(list_of_data['main']['pressure']),
"humidity": str(list_of_data['main']['humidity']),
}
return render_template('index.html', data=data, location=location)
except:
return '<script>alert("Invalid Location");document.location.href=`${new URL(document.location.href).origin}/`;</script>'
if __name__ == '__main__':
app.run(debug = True)
"""
so it's kind of embarassing that there is .9 percent more html than there is python in this repo,
so this comment will make it so that this repo looks cooler and has a lot more python code with this passage:
We’re no strangers to love,
You know the rules and so do I.
A full commitment’s what I’m thinking of,
You wouldnt get this from any other guy.
I just wanna tell you how I’m feeling,
Gotta make you understand…
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
We’ve known each other for so long
Your heart’s been aching
But you’re too shy to say it.
Inside we both know what’s been going on,
We know the game and we’re gonna play it.
Annnnnd if you ask me how I’m feeling,
Don’t tell me you’re too blind to see…
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
Give you up. give you up.
Give you up, give you up.
Never gonna give
Never gonna give, give you up.
Never gonna give
Never gonna give, give you up.
We’ve known each other for so long
Your heart’s been aching
But you’re too shy to say it.
Inside we both know what’s been going on,
We know the game and we’re gonna play it.
I just wanna tell you how I’m feeling,
Gotta make you understand…
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
"""