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.
33 lines
897 B
33 lines
897 B
# -*- coding:utf-8 -*-
|
|
from json import loads
|
|
|
|
import requests
|
|
from requests.exceptions import ConnectionError
|
|
|
|
from models import deserialize_tariffs, deserialize_abonents
|
|
import settings
|
|
|
|
|
|
def load_from_db():
|
|
try:
|
|
r = requests.get('%s://%s:%d/abons/api/abons' % (
|
|
'https' if settings.IS_USE_SSL else 'http',
|
|
settings.SERVER_IP,
|
|
settings.SERVER_PORT
|
|
), verify=False)
|
|
user_data = loads(r.text)
|
|
|
|
# Получаем тарифы
|
|
tariffs = deserialize_tariffs(user_data)
|
|
|
|
# Получаем пользователей
|
|
abons = deserialize_abonents(user_data, tariffs)
|
|
|
|
return abons, tariffs
|
|
|
|
except ValueError as e:
|
|
print('Error:', e, r.text)
|
|
|
|
except ConnectionError:
|
|
print("Can not connect to server %s:%d..." % (settings.SERVER_IP, settings.SERVER_PORT))
|
|
exit(0)
|