From a7293b9f447f7d0c6f84c348018a168891f120d2 Mon Sep 17 00:00:00 2001 From: Gena Date: Sun, 14 Jun 2015 00:15:19 +0600 Subject: [PATCH] no message --- store/alemtat.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) 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())