Commit c03eadee authored by birk's avatar birk
Browse files

load programs from json

parent 8bbdde1e
......@@ -62,14 +62,11 @@ class ApiClient(object):
# TODO: find actual id
return path_.split('/').pop(), type_
def __init__(self, server_, user_, pass_):
def __init__(self, server_: str, user_: str, pass_: str):
"""
:param server_: URL of the server, like 'http://medienarchiv.zhdk.ch'
:type server_: str
:param user_: username of API-client
:type user_: str
:param pass_: password of API-client
:type pass_: str
"""
super(ApiClient, self).__init__()
self.__auth = aiohttp.BasicAuth(user_, pass_)
......@@ -418,21 +415,17 @@ class ApiClient(object):
class MediaEntryParams():
def __init__(self,
public_get_metadata_and_previews_=True,
public_get_full_size_=None,
me_get_metadata_and_previews_=None,
me_get_full_size_=None,
filter_by_=None,
order_='desc',
collection_id_=None):
self.order = order_
self.public_get_metadata_and_previews = public_get_metadata_and_previews_
self.public_get_full_size = public_get_full_size_
self.me_get_metadata_and_previews = me_get_metadata_and_previews_
self.me_get_full_size = me_get_metadata_and_previews_
self.filter_by = filter_by_
self.collection_id = collection_id_
def __init__(self, json_:dict={}):
self.order = json_.get('order', 'desc')
self.public_get_metadata_and_previews = json_.get('public_get_metadata_and_previews', True)
self.public_get_full_size = json_.get('public_get_full_size')
self.me_get_metadata_and_previews = json_.get('me_get_metadata_and_previews')
self.me_get_full_size = json_.get('me_get_metadata_and_previews')
default_media = json.loads('{"media_files":[{"key": "media_type","value": "image"}, {"key": "media_type","value": "video"}]}')
self.filter_by = json_.get('filter_by', default_media)
if 'media_files' not in self.filter_by:
self.filter_by['media_files'] = default_media['media_files']
self.collection_id = json_.get('collection_id')
@property
def data(self):
......
......@@ -8,17 +8,20 @@ from content.apidata import KeywordData, PeopleData
class Program(EventDispatcher):
def __init__(self, api_, name_, params_, meta_data_white_list_=None, limit_=0, limit_selection_=0):
def __init__(self, api_, json_):
EventDispatcher.__init__(self)
self._api = api_
self._name = name_
self._params = params_
self._name = json_['name']
self._params = MediaEntryParams(json_.get('parameters'))
self._meta_data_white_list = json_.get('meta_data')
self._limit = int(json_.get('limit', 20))
self._limit_selection = self._limit
if json_.get('limit_selection'):
self._limit_selection = int(json_.get('limit_selection'))
self._start_url = None
self._playlist = None
self.__index = None
self._meta_data_white_list = meta_data_white_list_
self._limit = limit_
self._limit_selection = limit_selection_
def set_limit(self, limit_=0):
self._limit = limit_
......
import asyncio
import os
import simplejson as json
import pyglet
from random import shuffle
......@@ -32,29 +33,11 @@ class Main(object):
# defining programs
self._programs = []
# TODO: read programs from JSON file
# self._programs.append(Program(self._api, 'another sender test set', MediaEntryParams(
# public_get_metadata_and_previews_=None,
# me_get_metadata_and_previews_=True,
# collection_id_='3ff67136-38fb-470e-9766-a1196390d288')))
self._programs.append(Program(self._api, 'Testset Sender Medienarchiv', MediaEntryParams(
public_get_metadata_and_previews_=None,
me_get_metadata_and_previews_=True,
collection_id_='187af3e9-1c81-44bc-98e7-e38733d7a729'),
['madek_core:title', 'madek_core:keywords'], 5))
self._programs.append(Program(self._api, 'Schlagwort Theater', MediaEntryParams(
filter_by_={"media_files":[{"key":"media_type","value":"image"}],"meta_data":[{"key":"madek_core:keywords","value":"d7b20e04-ce56-4cee-bb17-bee2feed65f5"}]}),
None, 4))
self._programs.append(FollowupProgram(self._api, 'FollowupProgram', None, 11))
self._programs.append(Program(self._api, 'Kontext Unterrichtssituation', MediaEntryParams(
filter_by_={"media_files":[{"key":"media_type","value":"image"}],"meta_data":[{"key":"zhdk_bereich:project_type","value":"a736f812-ad2d-45e6-a17e-38f570bae5d2"}]}),
None, 9, 21))
self._programs.append(Program(self._api, 'Forschung Film', MediaEntryParams(
filter_by_={"media_files":[{"key":"media_type","value":"image"}],"meta_data":[{"key":"zhdk_bereich:project_type","value":"592a91ed-8981-4753-a841-ec6d135cdd43"},{"key":"media_content:type","value":"c31e836b-ccd0-42a2-b5dc-290342d3703e"}]}),
None, 8, 24))
self._programs.append(Program(self._api, 'Bereich Industrial Design', MediaEntryParams(
filter_by_={"media_files":[{"key":"media_type","value":"image"}],"meta_data":[{"key":"zhdk_bereich:institutional_affiliation","value":"865f08be-6ace-4ca7-b020-9adab4c666ec"}]}),
None, 11, 23))
with open('programs.json') as json_data:
for p in json.load(json_data)['programs']:
self._programs.append(Program(self._api, p))
shuffle(self._programs)
self._program_index = -1
......
{
"programs": [
{
"name": "Testset Sender Medienarchiv",
"parameters": {
"order": "desc",
"collection_id": "187af3e9-1c81-44bc-98e7-e38733d7a729"
},
"meta_data": [
"madek_core:title",
"madek_core:keywords"
],
"limit": 5
},
{
"name": "Schlagwort Theater",
"parameters": {
"order": "desc",
"public_get_metadata_and_previews": "true",
"filter_by": {
"media_files": [
{
"key": "media_type",
"value": "image"
}
],
"meta_data": [
{
"key": "madek_core:keywords",
"value": "d7b20e04-ce56-4cee-bb17-bee2feed65f5"
}
]
}
},
"limit": 5
},
{
"name": "Kontext Unterrichtssituation",
"parameters": {
"order": "desc",
"public_get_metadata_and_previews": "true",
"filter_by": {
"meta_data": [
{
"key": "zhdk_bereich:project_type",
"value": "a736f812-ad2d-45e6-a17e-38f570bae5d2"
}
]
}
},
"limit": 5
},
{
"name": "Forschung Film",
"parameters": {
"order": "desc",
"public_get_metadata_and_previews": "true",
"filter_by": {
"meta_data": [
{
"key": "zhdk_bereich:project_type",
"value": "592a91ed-8981-4753-a841-ec6d135cdd43"
},
{
"key": "media_content:type",
"value": "c31e836b-ccd0-42a2-b5dc-290342d3703e"
}
]
}
},
"limit": 5,
"limit_selection": 20
},
{
"name": "Bereich Industrial Design",
"parameters": {
"order": "desc",
"public_get_metadata_and_previews": "true",
"filter_by": {
"meta_data": [
{
"key": "zhdk_bereich:institutional_affiliation",
"value": "865f08be-6ace-4ca7-b020-9adab4c666ec"
}
]
}
},
"limit": 10
},
{
"name": "Schlagwort Theater",
"parameters": {
"order": "desc",
"public_get_metadata_and_previews": "true",
"filter_by": {
"meta_data": [
{
"key": "madek_core:keywords",
"value": "d7b20e04-ce56-4cee-bb17-bee2feed65f5"
}
]
}
},
"limit": 5
}
]
}
\ No newline at end of file
{
"programs": [
{
"name": "name",
"parameters": {
"order": "desc",
"public_get_metadata_and_previews": null,
"public_get_full_size": null,
"me_get_metadata_and_previews": "true",
"me_get_full_size": null,
"filter_by": null,
"collection_id": null
},
"meta_data": [
"madek_core:title",
"madek_core:keywords"
],
"limit": 5,
"limit_selection": null
}
]
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment