Skip to content
Snippets Groups Projects
Commit d68ce6a5 authored by David Trattnig's avatar David Trattnig
Browse files

Config API port, CORS setting, trackservice API.

parent 9a29fb4d
No related branches found
No related tags found
No related merge requests found
...@@ -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. Provides 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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment