Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aura-engine
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Kruse
aura-engine
Commits
302381bd
Commit
302381bd
authored
5 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Fixed cleaning of unnessecary API records.
parent
e99937f6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/scheduling/calender_fetcher.py
+42
-12
42 additions, 12 deletions
modules/scheduling/calender_fetcher.py
with
42 additions
and
12 deletions
modules/scheduling/calender_fetcher.py
+
42
−
12
View file @
302381bd
...
...
@@ -116,7 +116,9 @@ class CalendarFetcher:
schedule
=
simplejson
.
loads
(
html_response
)
# check data
self
.
logger
.
critical
(
"
no JSON data checks. I believe what i get here
"
)
if
not
schedule
:
self
.
logger
.
warn
(
"
Got no schedule via Playout API (Steering)!
"
)
return
None
#self.fetched_schedule_data = self.remove_unnecessary_data(schedule)
return
self
.
remove_unnecessary_data
(
schedule
)
...
...
@@ -139,7 +141,7 @@ class CalendarFetcher:
#schedule["show_fallback"] = self.__fetch_schedule_playlist__(schedule, "show_fallback_id", fetched_entries)
#schedule["station_fallback"] = self.__fetch_schedule_playlist__(schedule, "station_fallback_id", fetched_entries)
self
.
logger
.
info
(
str
(
schedule
))
#
self.logger.info(str(schedule))
except
Exception
as
e
:
self
.
logger
.
error
(
"
Error:
"
+
str
(
e
))
...
...
@@ -227,15 +229,26 @@ class CalendarFetcher:
self
.
has_already_fetched
=
True
return
html_response
.
decode
(
"
utf-8
"
)
# ------------------------------------------------------------------------------------------ #
def
__build_url__
(
self
,
type
,
placeholder
=
None
,
value
=
None
):
"""
Builds an API request URL using passed placeholder and value.
"""
url
=
self
.
url
[
type
]
if
placeholder
:
url
=
url
.
replace
(
placeholder
,
value
)
# print("built URL: "+url)
return
url
# ------------------------------------------------------------------------------------------ #
def
remove_unnecessary_data
(
self
,
schedule
):
"""
Removes all schedules which are not relevant for
further processing.
"""
count_before
=
len
(
schedule
)
schedule
=
self
.
remove_data_more_than_24h_in_the_future
(
schedule
)
schedule
=
self
.
remove_data_in_the_past
(
schedule
)
...
...
@@ -243,8 +256,16 @@ class CalendarFetcher:
self
.
logger
.
info
(
"
Removed %d unnecessary schedules from response. Entries left: %d
"
%
((
count_before
-
count_after
),
count_after
))
return
schedule
# ------------------------------------------------------------------------------------------ #
def
remove_data_more_than_24h_in_the_future
(
self
,
schedule_from_pv
):
"""
Removes entries 24h in the future and 12 hours in the past.
Note: This might influence resuming (in case of a crash)
single schedules which are longer than 12 hours long.
Think e.g. live broadcasts.
"""
act_list
=
[]
now
=
datetime
.
now
()
now_plus_24hours
=
now
+
timedelta
(
hours
=
24
)
...
...
@@ -253,29 +274,38 @@ class CalendarFetcher:
date_start
=
datetime
.
strptime
(
s
[
"
start
"
],
"
%Y-%m-%dT%H:%M:%S
"
)
# append only elements which are close enough to now
if
date_start
<=
now_plus_24hours
and
date_start
>=
now
-
timedelta
(
hours
=
1
):
if
date_start
<=
now_plus_24hours
and
date_start
>=
now
-
timedelta
(
hours
=
1
2
):
act_list
.
append
(
s
)
return
act_list
# ------------------------------------------------------------------------------------------ #
def
remove_data_in_the_past
(
self
,
schedule_from_pv
):
"""
Removes all schedules from the past, except the one which is
currently playing.
"""
act_list
=
[]
now
=
datetime
.
now
()
count
=
len
(
schedule_from_pv
)
for
index
,
curr
in
enumerate
(
schedule_from_pv
[:
-
1
]
):
for
index
,
curr
in
enumerate
(
schedule_from_pv
):
date_start
=
datetime
.
strptime
(
curr
[
"
start
"
],
"
%Y-%m-%dT%H:%M:%S
"
)
date_next_start
=
datetime
.
strptime
(
schedule_from_pv
[
index
+
1
][
"
start
"
],
"
%Y-%m-%dT%H:%M:%S
"
)
if
index
+
1
<
count
:
date_next_start
=
datetime
.
strptime
(
schedule_from_pv
[
index
+
1
][
"
start
"
],
"
%Y-%m-%dT%H:%M:%S
"
)
#
a
ppend all elements in the future
#
A
ppend all elements in the future
if
date_start
>=
now
:
act_list
.
append
(
curr
)
#
a
ppend the one which is now playing
if
date_start
<
=
now
and
date_next_start
>=
now
:
#
A
ppend the one which is now playing
el
if
date_start
<
now
and
date_next_start
>=
now
:
act_list
.
append
(
curr
)
return
act_list
# ------------------------------------------------------------------------------------------ #
def
create_test_data
(
self
,
id_name
,
schedule
):
import
random
...
...
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