Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GAYDAMAKHA MIKHAIL
weather-cli
Commits
bc602022
Commit
bc602022
authored
Sep 19, 2021
by
STEINMETZ THOMAS
Browse files
Merge branch 'feature/prevision-weather' into 'develop'
Feature/prevision weather See merge request
!5
parents
4e42e078
cfaa7925
Changes
2
Hide whitespace changes
Inline
Side-by-side
requirements/common.txt
View file @
bc602022
docopt
requests
weather.py
View file @
bc602022
...
...
@@ -15,20 +15,59 @@ Options:
--version Show version.
"""
import
json
from
docopt
import
docopt
import
requests
def
city
(
arguments
):
if
arguments
[
'<city_name>'
]
and
arguments
[
'--raw'
]:
r
=
requests
.
get
(
'https://richie.u-strasbg.fr/~virgile/sf4/public/index.php/weather/city/'
+
arguments
[
'<city_name>'
],
headers
=
{
"apiKey"
:
"PommeTacosDockerBatiment"
})
print
(
r
.
content
)
def
city_raw
(
city_name
):
"""Function city_raw
Args:
city_name (string): city's name
Returns:
string: response
"""
response
=
requests
.
get
(
'https://richie.u-strasbg.fr/~virgile/sf4/public/
\
index.php/weather/city/'
+
city_name
,
headers
=
{
"apiKey"
:
"PommeTacosDockerBatiment"
}
)
return
response
.
text
def
city
(
args
):
"""Function city
Args:
args (array): arguments in command line
Returns:
string|None: response city
"""
if
args
[
'<city_name>'
]
and
args
[
'--raw'
]:
return
city_raw
(
args
[
'<city_name>'
])
return
None
def
forecast
(
args
):
"""function forecast
Args:
args (array): arguments in command line
"""
if
args
[
'<city_name>'
]:
data_city
=
city_raw
(
args
[
'<city_name>'
])
city_id
=
json
.
loads
(
data_city
)[
'id'
]
response
=
requests
.
get
(
'https://richie.u-strasbg.fr/~virgile/sf4/
\
public/index.php/weather/forecast/'
+
str
(
city_id
),
headers
=
{
"apiKey"
:
"PommeTacosDockerBatiment"
})
print
(
response
.
text
)
if
__name__
==
'__main__'
:
arguments
=
docopt
(
__doc__
,
version
=
'0.1'
)
if
arguments
[
'city'
]:
city
(
arguments
);
print
(
city
(
arguments
))
elif
arguments
[
'forecast'
]:
forecast
(
arguments
)
else
:
print
(
arguments
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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