Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rest_lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Show more breadcrumbs
SOFT Core
SOFT 161 and 162
rest_lab
Commits
df6f11cd
Commit
df6f11cd
authored
Apr 13, 2022
by
Shruti Bolman
Browse files
Options
Downloads
Patches
Plain Diff
main file
parent
25e42f14
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+82
-0
82 additions, 0 deletions
main.py
with
82 additions
and
0 deletions
main.py
0 → 100644
+
82
−
0
View file @
df6f11cd
from
kivy.app
import
App
from
kivy.uix.boxlayout
import
BoxLayout
from
kivy.uix.label
import
Label
from
kivy.properties
import
ListProperty
from
kivy.logger
import
Logger
from
datetime
import
datetime
from
api_key
import
API_KEY
from
rest
import
RESTConnection
UNL_LATITUDE
=
40.8207
UNL_LONGITUDE
=
-
96.7005
UNITS
=
'
imperial
'
def
to_human_readable_time
(
timestamp
):
return
datetime
.
fromtimestamp
(
timestamp
).
strftime
(
'
%A %I:%M %p
'
)
def
format_forecast_record
(
record
):
try
:
time
=
to_human_readable_time
(
record
[
'
dt
'
])
description
=
'
,
'
.
join
(
condition
[
'
description
'
]
for
condition
in
record
[
'
weather
'
])
temperature
=
record
[
'
main
'
][
'
temp
'
]
humidity
=
record
[
'
main
'
][
'
humidity
'
]
feels_like
=
record
[
'
main
'
][
'
feels_like
'
]
return
\
f
'
{
time
}
:
{
description
}
,
{
temperature
:
.
1
f
}
degrees F,
{
humidity
:
.
0
f
}
% humidity,
'
+
\
f
'
feels like
{
feels_like
:
.
1
f
}
degrees F
'
except
KeyError
:
return
'
[invalid forecast record]
'
class
Record
(
Label
):
pass
class
Records
(
BoxLayout
):
records
=
ListProperty
([])
def
rebuild
(
self
):
self
.
clear_widgets
()
for
record
in
self
.
records
:
self
.
add_widget
(
Record
(
text
=
record
))
def
on_records
(
self
,
_
,
__
):
self
.
rebuild
()
class
RestApp
(
App
):
records
=
ListProperty
([])
def
load_records
(
self
):
self
.
records
=
[]
connection
=
RESTConnection
(
'
api.openweathermap.org
'
,
443
,
'
/data/2.5
'
)
connection
.
send_request
(
'
weather
'
,
{
'
appid
'
:
API_KEY
,
'
lat
'
:
UNL_LATITUDE
,
'
lon
'
:
UNL_LONGITUDE
,
'
units
'
:
UNITS
},
None
,
self
.
on_records_loaded
,
self
.
on_records_not_loaded
,
self
.
on_records_not_loaded
)
def
on_records_loaded
(
self
,
_
,
response
):
self
.
records
=
[
format_forecast_record
(
response
)]
def
on_records_not_loaded
(
self
,
_
,
error
):
self
.
records
=
[
'
[Failed to load records]
'
]
Logger
.
error
(
f
'
{
self
.
__class__
.
__name__
}
:
{
error
}
'
)
if
__name__
==
'
__main__
'
:
app
=
RestApp
()
app
.
run
()
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