Skip to content

Conversation

@nemoralis
Copy link

This PR adds a REST API.

Changes

  • Extracted data loading logic from app.py into a new data_store.py module. This allows the database state to be shared between the main Flask app and the new API blueprint without circular imports.
  • Created a new api blueprint in api.py with the following endpoints:
    • GET /api/events: List all available events.
    • GET /api/events/<slug>: Get detailed statistics for a specific event (e.g., monuments2016).
    • GET /api/country/<name>: Get statistics for a specific country.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@JeanFred
Copy link
Owner

JeanFred commented Dec 17, 2025

Thanks a lot for this! I finally had time to look at it.

  • I could test this fine with the docker-compose setup and the dummy database − all 3 endpoints answer as expected
  • Formatter/Linter is unfortunately broken in this repo :-( but I did have a pass locally. I also broke out your commit in two and copied over your excellent explanations from the PR. I would have liked to push them (as your kindly ticked "Maintainers are allowed to edit this pull request." alas I could not push the changes [1] (it’s my first time trying to amend someone else's PR from a fork, maybe I did something wrong) − I stashed them in https://github.com/JeanFred/wikiloves/tree/nemoralis/master
  • Thanks for making unit tests! I tried running them, both with tox/nose (that setup is a bit broken too >_>) and with uv/pytest − it fails with [2] I think the issue is that the import app, which itself tries loading the DB, is executed before the mock in setUp ?

[1] Getting

! [remote rejected] nemoralis/master -> nemoralis/master (permission denied)
error: failed to push some refs to 'github.com:nemoralis/wikiloves.git'

[2]

======================================================================
ERROR: Failure: JSONDecodeError (Expecting value: line 1 column 1 (char 0))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "wikiloves/.tox/py39/lib/python3.9/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "wikiloves/.tox/py39/lib/python3.9/site-packages/nose/loader.py", line 417, in loadTestsFromName
    module = self.importer.importFromPath(
  File "wikiloves/.tox/py39/lib/python3.9/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "wikiloves/.tox/py39/lib/python3.9/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File ".local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File ".local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 711, in _load
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "wikiloves/tests/test_api.py", line 12, in <module>
    from app import app
  File "wikiloves/app.py", line 29, in <module>
    data_store.loadDB()
  File "wikiloves/data_store.py", line 33, in loadDB
    db = json.load(f)
  File ".local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File ".local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File ".local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File ".local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

…e level and restore `loadDB` in `tearDownClass`.
@nemoralis
Copy link
Author

Thanks for the feedback, I've fixed the test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants