Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
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
Container registry
Model registry
Operate
Environments
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
AURA
engine
Commits
d68ce6a5
Commit
d68ce6a5
authored
5 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Config API port, CORS setting, trackservice API.
parent
9a29fb4d
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
api.py
+49
-6
49 additions, 6 deletions
api.py
with
49 additions
and
6 deletions
api.py
+
49
−
6
View file @
d68ce6a5
...
@@ -26,11 +26,13 @@ __author__ = 'David Trattnig <david.trattnig@subsquare.at>'
...
@@ -26,11 +26,13 @@ __author__ = 'David Trattnig <david.trattnig@subsquare.at>'
import
logging
import
logging
from
datetime
import
datetime
from
datetime
import
datetime
,
date
from
flask
import
Flask
from
flask
import
Flask
from
flask_cors
import
CORS
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_marshmallow
import
Marshmallow
from
flask_marshmallow
import
Marshmallow
from
marshmallow
import
Schema
,
fields
,
post_dump
from
flask_restful
import
Api
,
Resource
from
flask_restful
import
Api
,
Resource
from
apispec
import
APISpec
from
apispec
import
APISpec
from
apispec.ext.marshmallow
import
MarshmallowPlugin
from
apispec.ext.marshmallow
import
MarshmallowPlugin
...
@@ -50,6 +52,7 @@ config = AuraConfig()
...
@@ -50,6 +52,7 @@ config = AuraConfig()
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app
.
config
[
"
SQLALCHEMY_TRACK_MODIFICATIONS
"
]
=
False
app
.
config
[
"
SQLALCHEMY_TRACK_MODIFICATIONS
"
]
=
False
app
.
config
[
"
SQLALCHEMY_DATABASE_URI
"
]
=
config
.
get_database_uri
()
app
.
config
[
"
SQLALCHEMY_DATABASE_URI
"
]
=
config
.
get_database_uri
()
cors
=
CORS
(
app
,
resources
=
{
r
"
/*
"
:
{
"
origins
"
:
"
*
"
}})
db
=
SQLAlchemy
(
app
)
db
=
SQLAlchemy
(
app
)
ma
=
Marshmallow
(
app
)
ma
=
Marshmallow
(
app
)
api
=
Api
(
app
)
api
=
Api
(
app
)
...
@@ -58,7 +61,7 @@ api = Api(app)
...
@@ -58,7 +61,7 @@ api = Api(app)
class
EngineApi
:
class
EngineApi
:
"""
"""
Provide the Aura Engine API services.
Provide
s
the Aura Engine API services.
"""
"""
config
=
None
config
=
None
api
=
None
api
=
None
...
@@ -91,7 +94,6 @@ class EngineApi:
...
@@ -91,7 +94,6 @@ class EngineApi:
self
.
api
.
add_resource
(
TrackResource
,
config
.
api_prefix
+
"
/trackservice/<int:track_id>
"
)
self
.
api
.
add_resource
(
TrackResource
,
config
.
api_prefix
+
"
/trackservice/<int:track_id>
"
)
self
.
api
.
add_resource
(
CurrentTrackResource
,
config
.
api_prefix
+
"
/trackservice/current
"
)
self
.
api
.
add_resource
(
CurrentTrackResource
,
config
.
api_prefix
+
"
/trackservice/current
"
)
self
.
api
.
add_resource
(
TracksByDayResource
,
config
.
api_prefix
+
"
/trackservice/date/<string:date_string>
"
)
self
.
api
.
add_resource
(
TracksByDayResource
,
config
.
api_prefix
+
"
/trackservice/date/<string:date_string>
"
)
# self.api.add_resource(ProgrammeResource, config.api_prefix + "/programme")
self
.
logger
.
info
(
"
Engine API routes successfully set!
"
)
self
.
logger
.
info
(
"
Engine API routes successfully set!
"
)
...
@@ -108,7 +110,7 @@ class EngineApi:
...
@@ -108,7 +110,7 @@ class EngineApi:
# TODO Extend to provide production-grade app server
# TODO Extend to provide production-grade app server
# Set debug=False if you want to use your native IDE debugger
# Set debug=False if you want to use your native IDE debugger
self
.
api
.
app
.
run
(
port
=
5000
,
debug
=
False
)
self
.
api
.
app
.
run
(
port
=
self
.
config
.
api_port
,
debug
=
False
)
...
@@ -132,7 +134,44 @@ spec = APISpec(
...
@@ -132,7 +134,44 @@ spec = APISpec(
class
TrackServiceSchema
(
ma
.
Schema
):
class
TrackServiceSchema
(
ma
.
Schema
):
class
Meta
:
class
Meta
:
fields
=
(
"
id
"
,
"
schedule_start
"
,
"
track_start
"
,
"
fallback
"
,
"
artist
"
,
"
title
"
,
"
album
"
,
"
duration
"
)
fields
=
(
"
id
"
,
"
schedule.schedule_id
"
,
"
schedule.schedule_start
"
,
"
schedule.schedule_end
"
,
"
track
"
,
"
track_start
"
)
# class ReportSchema(ma.Schema):
# class Meta:
# fields = (
# "id",
# "schedule_start",
# "schedule_end",
# "is_repetition",
# "title", # ?
# "playlist_description", # ?
# "show_name",
# "show_hosts",
# "show_slug",
# "show_funding_category",
# "show_languages",
# "show_type",
# "show_categories",
# "show_topics",
# "show_musicfocus",
# "show_description",
# "show_short_description"
# "show_email",
# "show_image",
# "show_thumbnails",
# "show_logo",
# "show_website",
# "show_type"
# )
#
#
...
@@ -147,7 +186,11 @@ class TrackServiceResource(Resource):
...
@@ -147,7 +186,11 @@ class TrackServiceResource(Resource):
self
.
logger
=
logging
.
getLogger
(
"
engine-api
"
)
self
.
logger
=
logging
.
getLogger
(
"
engine-api
"
)
def
get
(
self
):
def
get
(
self
):
tracks
=
TrackService
.
select_last_hours
(
3
)
today
=
date
.
today
()
today
=
datetime
(
today
.
year
,
today
.
month
,
today
.
day
)
tracks
=
TrackService
.
select_by_day
(
today
)
for
entry
in
tracks
:
print
(
entry
)
return
EngineApi
.
trackservice_schema
.
dump
(
tracks
)
return
EngineApi
.
trackservice_schema
.
dump
(
tracks
)
...
...
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