Skip to content
Snippets Groups Projects
Commit 496d67c8 authored by jarmil's avatar jarmil Committed by jan.bednarik
Browse files

Cache na API requesty

parent 475f4a71
No related branches found
No related tags found
No related merge requests found
......@@ -4,4 +4,4 @@ line_length = 88
multi_line_output = 3
default_sectiont = "THIRDPARTY"
include_trailing_comma = true
known_third_party = arrow,django,environ,faker,ics,markdown,modelcluster,nbconvert,pirates,pytest,pytz,requests,sentry_sdk,snapshottest,taggit,traitlets,wagtail,wagtailmetadata
known_third_party = arrow,django,environ,faker,ics,markdown,modelcluster,nbconvert,pirates,pytest,pytz,requests,requests_cache,sentry_sdk,snapshottest,taggit,traitlets,wagtail,wagtailmetadata
......@@ -9,6 +9,7 @@ pirates<=0.4
whitenoise
opencv-python
requests
requests-cache
ics
arrow
sentry-sdk
......
import requests
import requests_cache
from django.db import models
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey
......@@ -8,6 +9,11 @@ from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
# cacheovani requestu na piratska api, ttl 1 hodina
requests_cache.install_cache(
cache_name="shared_models", backend="memory", expire_after=3600
)
class SharedSubpageMixin:
"""Must be used in class definition before MetadataPageMixin!"""
......@@ -76,17 +82,13 @@ class PersonPage(SharedSubpageMixin, MetadataPageMixin, Page):
]
def _iapi(self):
""" Vrati data o osobe z piratskeho IAPI jako json
TODO: neni cacheovano
"""
""" Vrati data o osobe z piratskeho IAPI jako json. Cached via requests_cache """
return requests.get(
"https://iapi.pirati.cz/v1/user?username=%s" % self.pirate_id
).json()
def _graph(self):
""" Vrati data o osobe z graph.pirati.cz (forum) jako json
TODO: neni cacheovano
"""
""" Vrati data o osobe z graph.pirati.cz (forum) jako json. Cached via requests_cache """
return requests.get("https://graph.pirati.cz/user/%s" % self.pirate_id).json()
@property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment