Skip to content

Commit

Permalink
improves event_series_api webservice
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Nov 19, 2023
1 parent 2d21398 commit 1a14898
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion corpus/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Version():

version=corpus.__version__
date = '2020-09-10'
updated = '2023-11-18'
updated = '2023-11-19'

doc_url="https://wiki.bitplan.com/index.php/ConferenceCorpus"
chat_url="https://github.com/WolfgangFahl/ConferenceCorpus/discussions"
Expand Down
11 changes: 4 additions & 7 deletions corpus/web/cc_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ def __init__(self):
self.event_series_api=EventSeriesAPI(self.lookup)

@app.get('/eventseries/{name}')
def get_eventseries(name:str):
bks=""
reduce=False
markup_format="json"

event_series_dict=self.event_series_api.getEventSeries(name, bks, reduce)
response=self.event_series_api.convertToRequestedFormat(name, event_series_dict, markup_format)
def get_eventseries(name: str, bks: str = "", reduce: bool = False, format: str = "json"):
# Use the parameters directly in the API calls
event_series_dict = self.event_series_api.getEventSeries(name, bks, reduce)
response = self.event_series_api.convertToRequestedFormat(name, event_series_dict, format)
return response

def setup_home(self):
Expand Down
13 changes: 9 additions & 4 deletions corpus/web/eventseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from ngwidgets.orjson_response import ORJSONResponse
from fastapi.responses import FileResponse
from tabulate import tabulate
from typing import Any,List
from typing import List
from spreadsheet.spreadsheet import ExcelDocument
from corpus.lookup import CorpusLookup

from corpus.datasources.openresearch import OREvent, OREventSeries
from corpus.eventseriescompletion import EventSeriesCompletion
from datetime import date,datetime
from ngwidgets.markup_header import MarkupHeader

class EventSeriesAPI():
"""
Expand Down Expand Up @@ -173,9 +173,14 @@ def convertToRequestedFormat(self, name: str, dictOfLods: dict, markup_format: s

else:
# Using tabulate for other formats (including HTML)
tabulated_content = tabulate([lod for lod in dictOfLods.values()], headers="keys", tablefmt=markup_format)
all_tables = ""
for source, lod in dictOfLods.items():
if isinstance(lod, list):
table = tabulate(lod, headers="keys", tablefmt=markup_format)
table_header=MarkupHeader.get_markup(source, markup_format=markup_format, level=1)
all_tables += table_header +"\n"+ table
media_type = "text/plain" if markup_format.lower() != "html" else "text/html"
return Response(content=tabulated_content, media_type=media_type)
return Response(content=all_tables, media_type=media_type)

@dataclass
class MetadataMappings:
Expand Down
19 changes: 18 additions & 1 deletion tests/test_restful_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,21 @@ def test_event_series_api(self):
if debug:
print(f"Event Count: {event_count}")
self.assertEquals(expected_sources,sources)
self.assertTrue(expected_event_count<=event_count)
self.assertTrue(expected_event_count<=event_count)

def test_event_series_api_formats(self):
"""
test different markup formats
"""
test_series=[
("AISI","")
]
debug=True
for name,needle in test_series:
for markup_format in ["github"]:
path=f"/eventseries/{name}?format={markup_format}"
markup=self.get_html(path)
if debug:
print(f"{markup_format}:")
print(markup)

0 comments on commit 1a14898

Please sign in to comment.