diff --git a/setup.py b/setup.py index 0fa0520..8523044 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def requirements(): setup( name='smsactivateru', - version='1.2.6', + version='1.0.3', long_description=long_description(), long_description_content_type='text/markdown', description='Wrapper for automatic reception of SMS-messages by sms-activate.ru', diff --git a/smsactivateru/__init__.py b/smsactivateru/__init__.py index 362a509..036555c 100644 --- a/smsactivateru/__init__.py +++ b/smsactivateru/__init__.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- from .sms import Sms from .datatype import SmsTypes -from .actions import GetBalance, GetFreeSlots, GetNumber, SetStatus, GetStatus +from .actions import GetBalance, GetFreeSlots, GetNumber,GetFullSms, SetStatus, GetStatus from .services import SmsService from .activations import SmsActivation __author__ = 'tezmen' -__version__ = '1.0' -__contact__ = 'https://t.me/tezmen' \ No newline at end of file +__version__ = '1.0.3' +__contact__ = 'https://t.me/tezmen' diff --git a/smsactivateru/actions.py b/smsactivateru/actions.py index 366d133..2c10546 100644 --- a/smsactivateru/actions.py +++ b/smsactivateru/actions.py @@ -68,7 +68,7 @@ def request(self, wrapper): """ response = wrapper.request(self) return self.__response_processing(response, wrapper=wrapper) - + class GetStatus(ActionsModel): _name = 'getStatus' @@ -78,7 +78,29 @@ def __init__(self, id): @error_handler def __response_processing(self, response): - data = {'status': response, 'code': None} + data = {'status': response, 'code': None, 'response':response} + if ':' in response: + data['status'] = response.split(':', 1)[0] + data['code'] = response.split(':', 1)[1] + return data + + def request(self, wrapper): + """ + :rtype: dict + """ + response = wrapper.request(self) + return self.__response_processing(response) + + +class GetFullSms(ActionsModel): + _name = 'getFullSms' + + def __init__(self, id): + super().__init__(inspect.currentframe()) + + @error_handler + def __response_processing(self, response): + data = {'status': response, 'code': None, 'response':response} if ':' in response: data['status'] = response.split(':', 1)[0] data['code'] = response.split(':', 1)[1] diff --git a/smsactivateru/activations.py b/smsactivateru/activations.py index 8f3d0e6..aded695 100644 --- a/smsactivateru/activations.py +++ b/smsactivateru/activations.py @@ -5,90 +5,128 @@ class SmsActivation: - """ - This is simple worker! - For hand-settings any other params – check /example/custom.py - """ + """ + This is simple worker! + For hand-settings any other params – check /example/custom.py + """ - def __init__(self, activation_id, number, wrapper): - self.__id = activation_id - self.__number = number - self.__wrapper = wrapper - self.__last_code = str() + def __init__(self, activation_id, number, wrapper): + self.__id = activation_id + self.__number = number + self.__wrapper = wrapper + self.__last_code = str() - def cancel(self): - set_status = smsactivateru.SetStatus( - id=self.__id, - status=smsactivateru.SmsTypes.Status.Cancel - ) - if self.wrapper: - return set_status.request(self.wrapper) - return set_status + def cancel(self): + set_status = smsactivateru.SetStatus( + id=self.__id, + status=smsactivateru.SmsTypes.Status.Cancel + ) + if self.wrapper: + return set_status.request(self.wrapper) + return set_status - def mark_as_used(self): - set_status = smsactivateru.SetStatus( - id=self.__id, - status=smsactivateru.SmsTypes.Status.AlreadyUsed - ) - if self.wrapper: - return set_status.request(self.wrapper) - return set_status + def mark_as_used(self): + set_status = smsactivateru.SetStatus( + id=self.__id, + status=smsactivateru.SmsTypes.Status.AlreadyUsed + ) + if self.wrapper: + return set_status.request(self.wrapper) + return set_status - def was_sent(self): - set_status = smsactivateru.SetStatus( - id=self.__id, - status=smsactivateru.SmsTypes.Status.SmsSent - ) - if self.wrapper: - return set_status.request(self.wrapper) - return set_status + def was_sent(self): + set_status = smsactivateru.SetStatus( + id=self.__id, + status=smsactivateru.SmsTypes.Status.SmsSent + ) + if self.wrapper: + return set_status.request(self.wrapper) + return set_status - def wait_code(self, timeout=1200, callback=None, not_end=False, *args, **kwargs): - """ - :param wrapper: obj for work with sms-activate - :param timeout: timeout waiting of code from sms in secs. 1200 - 20 min, this is max time of a live session. - :param callback: function for eval before getting code - :param not_end: - :return: str - """ - counter = 0 - while True: - time.sleep(1) - counter += 1 - if counter >= timeout: - raise ('Timeout error') - response = smsactivateru.GetStatus(id=self.id).request(self.wrapper) - if response['code'] and not not_end and response['code'] != self.last_code: - self.__last_code = response['code'] - smsactivateru.SetStatus( - id=self.id, - status=smsactivateru.SmsTypes.Status.End - ).request(self.wrapper) - break - elif response['code'] and not_end and response['code'] != self.last_code: - self.__last_code = response['code'] - smsactivateru.SetStatus( - id=self.id, - status=smsactivateru.SmsTypes.Status.OneMoreCode - ) - break - if callback: - callback(self.last_code) - else: - return self.last_code + def wait_code(self, timeout=1200, callback=None, not_end=False, *args, **kwargs): + """ + :param wrapper: obj for work with sms-activate + :param timeout: timeout waiting of code from sms in secs. 1200 - 20 min, this is max time of a live session. + :param callback: function for eval before getting code + :param not_end: + :return: str + """ + counter = 0 + while True: + time.sleep(1) + counter += 1 + if counter >= timeout: + raise ('Timeout error') + response = smsactivateru.GetStatus(id=self.id).request(self.wrapper) + if not response['code'] and response['status'] == "STATUS_OK": + response = smsactivateru.GetFullSms(id=self.id).request(self.wrapper) + if response['code'] and not not_end and response['code'] != self.last_code: + self.__last_code = response['code'] + smsactivateru.SetStatus( + id=self.id, + status=smsactivateru.SmsTypes.Status.End + ).request(self.wrapper) + break + elif response['code'] and not_end and response['code'] != self.last_code: + self.__last_code = response['code'] + smsactivateru.SetStatus( + id=self.id, + status=smsactivateru.SmsTypes.Status.OneMoreCode + ).request(self.wrapper) + break + if callback: + callback(self.last_code.strip()) + else: + return self.last_code.strip() - @property - def id(self): - return self.__id + def wait_text(self, timeout=1200, callback=None, not_end=False, *args, **kwargs): + """ + :param wrapper: obj for work with sms-activate + :param timeout: timeout waiting of code from sms in secs. 1200 - 20 min, this is max time of a live session. + :param callback: function for eval before getting code + :param not_end: + :return: str + """ + counter = 0 + while True: + time.sleep(1) + counter += 1 + if counter >= timeout: + raise ('Timeout error') + response = smsactivateru.GetStatus(id=self.id).request(self.wrapper) + if response['status'] == "STATUS_OK": + response = smsactivateru.GetFullSms(id=self.id).request(self.wrapper) + if response['code'] and not not_end and response['code'] != self.last_code: + self.__last_code = response['code'] + smsactivateru.SetStatus( + id=self.id, + status=smsactivateru.SmsTypes.Status.End + ).request(self.wrapper) + break + elif response['code'] and not_end and response['code'] != self.last_code: + self.__last_code = response['code'] + smsactivateru.SetStatus( + id=self.id, + status=smsactivateru.SmsTypes.Status.OneMoreCode + ).request(self.wrapper) + break + if callback: + callback(self.last_code.strip()) + else: + return self.last_code.strip() - @property - def phone_number(self): - return self.__number + @property + def id(self): + return self.__id - @property - def wrapper(self): - return self.__wrapper + @property + def phone_number(self): + return self.__number - @property - def last_code(self): - return self.__last_code + @property + def wrapper(self): + return self.__wrapper + + @property + def last_code(self): + return self.__last_code diff --git a/smsactivateru/datatype.py b/smsactivateru/datatype.py index 66a2e62..40e963b 100644 --- a/smsactivateru/datatype.py +++ b/smsactivateru/datatype.py @@ -11,11 +11,11 @@ class Country: MM = '5' # Мьянма (Myanmar) ID = '6' # Индонезия (Indonesia) MY = '7' # Малайзия (Malaysia) - # KE = '8' # Кения (Kenya) – temp disable - # TZ = '9' # Танзания (Tanzania) – temp disable + KE = '8' # Кения (Kenya) – temp disable + TZ = '9' # Танзания (Tanzania) – temp disable VN = '10' # Вьетнам (Vietnam) KG = '11' # Кыргызстан (Kyrgyzstan) - US = '12' # США (USA) + US_VIRT = '12' # США ВИРТ (USA) IL = '13' # Израиль (Israel) HK = '14' # Гонконг (Hong Kong) PL = '15' # Польша (Poland) @@ -49,6 +49,28 @@ class Country: HR = '45' # Хорватия ( Croatia) IQ = '47' # Ирак (Iraq) NL = '48' # Нидерланды (Netherlands) + TH = '52' # Таиланд (Thailand) + SA = '53' # Саудовская Аравия (Saudi Arabia) + MX = '54' # Мексика (Mexico) + TW = '55' # Тайвань (Taiwan) + ES = '56' # Испания (Spain) + IR = '57' # Иран (Iran) + DZ = '58' # Алжир (Algeria) + SI = '59' # Словения (Slovenia) + BD = '60' # Бангладеш (Bangladesh) + SN = '61' # Сенегал (Senegal) + TR = '62' # Турция (Turkey) + CZ = '63' # Чехия (Czechia) + LK = '64' # Шри-Ланка (Sri Lanka) + PE = '65' # Перу (Peru) + PK = '66' # Пакистан (Pakistan) + NZ = '67' # Новая Зеландия (New Zealand) + GN = '68' # Гвинея (Guinea) + ML = '69' # Мали (Mali) + VE = '70' # Венесуэла (Venezuela) + ET = '71' # Эфиопия (Ethiopia) + BR = '73' + US = '187' # США class Status: diff --git a/smsactivateru/services.py b/smsactivateru/services.py index 12296cf..572ff58 100644 --- a/smsactivateru/services.py +++ b/smsactivateru/services.py @@ -14,7 +14,7 @@ class ServiceStorage: 'Messenger': 'uk_0', 'LineMessenger': 'me_0', 'Yahoo': 'mb_0', 'DrugVokrug': 'we_0', 'FiveOrochka': 'bd_0', 'TencentQQ': 'kp_0', 'WOG': 'dt_0', 'Yandex': 'ya_0', 'YandexSmsForwarding': 'ya_1', 'Steam': 'mt_0', 'Tinder': 'oi_0', 'Mamba': 'fd_0', 'DromRu': 'zz_0', 'KakaoTalk': 'kt_0', 'AOL': 'pm_0', 'LinkedIN': 'tn_0', - 'DeliveryClub': 'dt_0', + 'DeliveryClub': 'dt_0', 'Craigslist': 'wc_0', 'Offerup': 'zm_0' } @@ -56,6 +56,13 @@ def Viber(self): """ return self._Viber + @property + def Craigslist(self): + """ + :rtype: smsactivateru.models.ServiceModel + """ + return self._Craigslist + @property def Telegram(self): """ @@ -273,6 +280,13 @@ def Steam(self): """ return self._Steam + @property + def Offerup(self): + """ + :rtype: smsactivateru.models.ServiceModel + """ + return self._Offerup + @property def Tinder(self): """ diff --git a/smsactivateru/sms.py b/smsactivateru/sms.py index c031ad1..a273beb 100644 --- a/smsactivateru/sms.py +++ b/smsactivateru/sms.py @@ -5,7 +5,7 @@ class Sms: def __init__(self, api_key): self.key = api_key - self.url = 'http://sms-activate.ru/stubs/handler_api.php' + self.url = 'https://api.sms-activate.org/stubs/handler_api.php' def request(self, action): try: