diff --git a/store/alemtat.py b/store/alemtat.py index 16cc4e2..3b8e7fa 100644 --- a/store/alemtat.py +++ b/store/alemtat.py @@ -1,5 +1,5 @@ import requests - +from django.core.cache import cache class AlemTat(object): COUNTRY_CODE = '0001' @@ -17,10 +17,15 @@ class AlemTat(object): return retval def get_cities(self): - url = self._build_url( - 'http://api.alemtat.kz/web/{ext}/Catalog/getCitiesByCountry?CountryLocalCode={}'.format(self.COUNTRY_CODE, ext=self.API_KEY)) - r = requests.get(url) - return r.json() + cache_key = 'alemtat_cities' + retval = cache.get(cache_key, None) + if not retval: + url = self._build_url( + 'http://api.alemtat.kz/web/{ext}/Catalog/getCitiesByCountry?CountryLocalCode={}'.format(self.COUNTRY_CODE, ext=self.API_KEY)) + r = requests.get(url) + retval = r.json() + cache.set(cache_key, retval, 60*60*24*7) + return retval def get_cities_tuple(self): retval = map(lambda cities: (cities['LocalCode'], '{} - {}'.format(cities['LocalityName'].title(), cities[ @@ -28,10 +33,15 @@ class AlemTat(object): return tuple(retval) def get_services(self): - url = self._build_url( - 'http://api.alemtat.kz/web/{ext}/Catalog/getServices'.format(ext=self.API_KEY)) - r = requests.get(url) - return r.json() + cache_key = 'alemtat_services' + retval = cache.get(cache_key, None) + if not retval: + url = self._build_url( + 'http://api.alemtat.kz/web/{ext}/Catalog/getServices'.format(ext=self.API_KEY)) + r = requests.get(url) + retval = r.json() + cache.set(cache_key, retval, 60*60*24*7) + return retval def get_services_tuple(self): retval = map(lambda services: (services['LocalCode'], services['Name'],), self.get_services())