You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
import requests
|
|
|
|
|
|
class AlemTat(object):
|
|
COUNTRY_CODE = '0001'
|
|
CITY_CODE = '000003'
|
|
API_KEY = '677a8773-c647-4b8f-8968-32a67d55e0d3'
|
|
CONTRACT = '05828/ИМ'
|
|
|
|
def _build_url(self, url):
|
|
# url = url.replace('\{ext\}', API_KEY)
|
|
retval = url
|
|
if '?' in url:
|
|
retval = url + '&ApiKey={}'.format(self.API_KEY)
|
|
else:
|
|
retval = url + '?ApiKey={}'.format(self.API_KEY)
|
|
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()
|
|
|
|
def get_cities_tuple(self):
|
|
retval = map(lambda cities: (cities['LocalCode'], '{} - {}'.format(cities['LocalityName'].title(), cities[
|
|
'Region'].capitalize())), self.get_cities())
|
|
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()
|
|
|
|
def get_services_tuple(self):
|
|
retval = map(lambda services: (services['LocalCode'], services['Name'],), self.get_services())
|
|
return tuple(retval)
|
|
|
|
# def get_services_tuple(self):
|
|
# retval = map(lambda cities: (cities['LocalCode'], '{} - {}'.format(cities['LocalityName'].title(), cities[
|
|
# 'Region'].capitalize())), self.get_cities())
|
|
# return tuple(retval)
|
|
|
|
def get_amount(self, to, places, weight, service):
|
|
url = self._build_url(
|
|
'http://api.alemtat.kz/web/{ext}/Calc/getAmount'.format(ext=self.API_KEY))
|
|
post_data = dict(
|
|
FromCountryCode=self.COUNTRY_CODE,
|
|
FromLocalCode=self.CITY_CODE,
|
|
ToCountryCode=self.COUNTRY_CODE,
|
|
ToLocalCode=to,
|
|
ServiceLocalCode=service,
|
|
Places=places,
|
|
Weight=weight,
|
|
Contract=self.CONTRACT,
|
|
)
|
|
r = requests.post(url, data=post_data)
|
|
return r.json()
|
|
|
|
|
|
def alemtat_get_cities_tuple():
|
|
a = AlemTat()
|
|
return a.get_cities_tuple()
|
|
|
|
def alemtat_get_services_tuple():
|
|
a = AlemTat()
|
|
return a.get_services_tuple()
|
|
|
|
|