Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
John Donnal
/
comms_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
64ab234b
authored
Oct 19, 2020
by
source_reader
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
updated http client
parent
dd7cd711
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
http_client.py
http_client.py
View file @
64ab234b
import
json
import
requests
API_KEY
=
"--REDACTED--"
city_name
=
"Annapolis"
URL
=
"https://api.openweathermap.org/data/2.5/weather?q=
%
s&appid=
%
s&units=imperial"
%
(
city_name
,
API_KEY
)
r
=
requests
.
get
(
URL
)
city
=
"Annapolis"
api_key
=
"--REDACTED--"
units
=
"imperial"
# URL Components
scheme
=
"https"
host
=
"api.openweathermap.org"
resource
=
"/data/2.5/weather"
query
=
"q=
%
s&appid=
%
s&units=
%
s"
%
(
city
,
api_key
,
units
)
# Put it all together
url
=
scheme
+
"://"
+
host
+
resource
+
"?"
+
query
print
(
url
)
# Request library handles the *whole* protocol stack :)
r
=
requests
.
get
(
url
)
data
=
r
.
json
()
print
(
"It is currently
%
d degrees in
%
s"
%
(
data
[
'main'
][
'temp'
],
city_name
))
# Show some interesting weather data
print
(
"It is currently
%
d degrees in
%
s"
%
(
data
[
'main'
][
'temp'
],
city
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment