Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DashboardLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
PlayWallDesktop wird heute 10 Jahre alt!
Show more breadcrumbs
ProjectLeaf
DashboardLeaf
Commits
2a918dc1
Commit
2a918dc1
authored
Jul 5, 2020
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
initial weather on weather forecast service
parent
36dadabf
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Pipfile
+4
-1
4 additions, 1 deletion
Pipfile
src/logic/services/WeatherSevenDaysService.py
+94
-0
94 additions, 0 deletions
src/logic/services/WeatherSevenDaysService.py
with
98 additions
and
1 deletion
Pipfile
+
4
−
1
View file @
2a918dc1
...
...
@@ -16,7 +16,10 @@ flask = "==1.1.2"
gevent = "
=
=
20.6
.
1
"
TheCodeLabs-BaseUtils
=
"*"
TheCodeLabs-FlaskUtils
=
"*"
python-jenkins
=
"=
=
1.5
.
0
"
Pillow
=
"=
=
7.2
.
0
"
# services
python-jenkins = "
=
=
1.5
.
0
"
plotly = "
=
=
4.8
.
2
"
[dev-packages]
This diff is collapsed.
Click to expand it.
src/logic/services/WeatherSevenDaysService.py
0 → 100644
+
94
−
0
View file @
2a918dc1
import
locale
from
datetime
import
datetime
from
typing
import
Dict
import
requests
import
plotly.graph_objects
as
go
from
TheCodeLabs_BaseUtils
import
CachedService
class
WeatherSevenDaysService
(
CachedService
):
URL
=
'
https://api.openweathermap.org/data/2.5/onecall
'
def
__init__
(
self
,
settings
):
super
().
__init__
(
settings
[
'
fetchIntervalInSeconds
'
])
self
.
_settings
=
settings
def
_fetch_data
(
self
)
->
Dict
:
response
=
requests
.
get
(
self
.
URL
,
params
=
{
'
lat
'
:
self
.
_settings
[
'
lat
'
],
'
lon
'
:
self
.
_settings
[
'
lon
'
],
'
appid
'
:
self
.
_settings
[
'
apiKey
'
],
'
lang
'
:
'
de
'
,
'
units
'
:
'
metric
'
})
if
response
.
status_code
!=
200
:
raise
Exception
(
f
'
Invalid status code:
{
response
.
status_code
}
'
)
# TODO less invasive modification
locale
.
setlocale
(
locale
.
LC_ALL
,
'
de_DE
'
)
forecast
=
response
.
json
()[
'
daily
'
]
forecastData
=
{}
for
day
in
forecast
:
date
=
day
[
'
dt
'
]
date
=
datetime
.
fromtimestamp
(
date
)
date
=
datetime
.
strftime
(
date
,
'
%a
'
)
forecastData
[
date
]
=
(
int
(
day
[
'
temp
'
][
'
min
'
]),
int
(
day
[
'
temp
'
][
'
max
'
]))
formattedDates
=
[
f
'
<b>
{
value
}
</b>
'
for
value
in
forecastData
.
keys
()]
minValues
=
[
x
[
0
]
for
x
in
forecastData
.
values
()]
maxValues
=
[
x
[
1
]
for
x
in
forecastData
.
values
()]
layout
=
go
.
Layout
(
plot_bgcolor
=
'
rgba(0,0,0,0)
'
,
showlegend
=
False
,
xaxis
=
{
'
tickfont
'
:
{
'
family
'
:
'
sans-serif
'
,
'
size
'
:
18
},
'
showgrid
'
:
False
,
},
yaxis
=
{
'
visible
'
:
False
,
})
fig
=
go
.
Figure
(
layout
=
layout
)
fig
.
add_trace
(
go
.
Scatter
(
x
=
formattedDates
,
y
=
minValues
,
text
=
[
f
'
<b>
{
value
}
</b>
'
for
value
in
minValues
],
mode
=
'
lines+text
'
,
line
=
dict
(
color
=
'
#CCCCCC
'
),
textfont
=
dict
(
family
=
'
sans-serif
'
,
size
=
18
,
color
=
'
royalblue
'
)))
fig
.
add_trace
(
go
.
Scatter
(
x
=
formattedDates
,
y
=
maxValues
,
text
=
[
f
'
<b>
{
value
}
</b>
'
for
value
in
maxValues
],
mode
=
'
lines+text
'
,
line
=
dict
(
color
=
'
#CCCCCC
'
),
textfont
=
dict
(
family
=
'
sans-serif
'
,
size
=
18
,
color
=
'
crimson
'
)))
fig
.
show
()
return
{}
if
__name__
==
'
__main__
'
:
ws
=
WeatherSevenDaysService
({
'
fetchIntervalInSeconds
'
:
10
,
'
apiKey
'
:
''
,
'
lat
'
:
51.012825
,
'
lon
'
:
13.666365
})
data
=
ws
.
get_data
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment