-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Iwakura Lain
committed
May 15, 2020
0 parents
commit f2c61db
Showing
43 changed files
with
1,592 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from smspva_wrapper import Client, Backends, Services, Countries | ||
from smspva_wrapper.types import country_dict, service_dict | ||
|
||
SIMSMS_API_KEY = '' | ||
SMSPVA_API_KEY = '' | ||
|
||
c = Client(api_key=SMSPVA_API_KEY, backend=Backends.SMSPVA) | ||
|
||
|
||
def cheapest_price_finder(): | ||
prices = [] | ||
for country in country_dict: | ||
a = c.get_service_price(Services.TELEGRAM, country) | ||
item = (a.price, a.country) | ||
prices.append(item) | ||
|
||
prices.sort() | ||
for item in prices: | ||
print(f"{item[1]}: {item[0]}") | ||
|
||
|
||
if '__main__' == __name__: | ||
print(c.name) | ||
print(c.balance) | ||
print(c.karma) | ||
print(c.name) | ||
cheapest_price_finder() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from smspva_wrapper.client import Client | ||
from smspva_wrapper.errors import Errors | ||
from smspva_wrapper.types import Countries, Services, Backends, Operators |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .caller import caller as caller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import requests | ||
from smspva_wrapper.errors import Errors | ||
|
||
|
||
def caller(query: str) -> dict: | ||
"""Low-level function for calling API | ||
Args: | ||
query (str): API link to request | ||
Returns: | ||
json_dict (dict): containing dictionary of parsed json from API | ||
Raises: | ||
InvalidAPIKeyError | ||
InsufficientFundsError | ||
TooShortIntervalError | ||
RepeatRequestLaterError | ||
RequestSyntaxError | ||
APIGeneralError | ||
NetworkingError | ||
UnknownAPIError | ||
""" | ||
r = requests.get(query) | ||
print("Called API") | ||
|
||
if r.status_code == 200: | ||
try: | ||
json_dict: dict = r.json() | ||
return json_dict | ||
except ValueError: | ||
error = r.content.decode() | ||
if 'API KEY не получен!' == error: | ||
raise Errors.InvalidAPIKeyError(error) | ||
elif 'API KEY не найден!' == error: | ||
raise Errors.InvalidAPIKeyError(error) | ||
elif 'API KEY not received!' == error: | ||
raise Errors.InvalidAPIKeyError(error) | ||
elif 'Недостаточно средств!' == error: | ||
raise Errors.InsufficientFundsError(error) | ||
elif 'Превышено количество попыток!' == error: | ||
raise Errors.TooShortIntervalError(error) | ||
elif 'Произошла неизвестная ошибка.' == error: | ||
raise Errors.RepeatRequestLaterError(error) | ||
elif 'Неверный запрос.' == error: | ||
raise Errors.RequestSyntaxError(error) | ||
elif 'Произошла внутренняя ошибка сервера.' == error: | ||
raise Errors.RepeatRequestLaterError(error) | ||
else: | ||
raise Errors.UnknownAPIError(error) | ||
else: | ||
raise Errors.NetworkingError("status code: ", r.status_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
from typing import Union | ||
|
||
from smspva_wrapper.types import Backends, Services, Countries, Containers | ||
from smspva_wrapper.methods import Methods | ||
|
||
|
||
# noinspection PyCallByClass | ||
class Client: | ||
def __init__(self, api_key: str, backend: Backends): | ||
self._api_base = f'{backend}apikey={api_key}' | ||
self.name = self.me.name | ||
|
||
@property | ||
def api_base(self) -> str: | ||
return str(self._api_base) | ||
|
||
@property | ||
def me(self) -> Containers.UserInfo: | ||
return self.get_userinfo() | ||
|
||
@property | ||
def balance(self) -> float: | ||
return float(self.me.balance) | ||
|
||
@property | ||
def karma(self) -> float: | ||
return float(self.me.karma) | ||
|
||
def get_balance(self) -> Containers.Balance: | ||
return Containers.Balance( | ||
Methods.get_balance( | ||
api_base=self.api_base | ||
) | ||
) | ||
|
||
def get_userinfo(self) -> Containers.UserInfo: | ||
return Containers.UserInfo( | ||
Methods.get_userinfo( | ||
api_base=self.api_base | ||
) | ||
) | ||
|
||
def get_count_new(self, service: Union[Services, str], country: Union[Countries, str]) -> Containers.CountNew: | ||
return Containers.CountNew( | ||
Methods.get_count_new( | ||
api_base=self.api_base, | ||
service=str(service), | ||
country=str(country) | ||
) | ||
) | ||
|
||
def get_service_price(self, service: Union[Services, str], country: Union[Countries, str]) -> Containers.ServicePrice: | ||
return Containers.ServicePrice( | ||
Methods.get_service_price( | ||
api_base=self.api_base, | ||
service=str(service), | ||
country=str(country) | ||
) | ||
) | ||
|
||
def get_number(self, service: Union[Services, str], country: Union[Countries, str]) -> Containers.Number: | ||
return Containers.Number( | ||
Methods.get_number( | ||
api_base=self.api_base, | ||
service=str(service), | ||
country=str(country) | ||
) | ||
) | ||
|
||
def ban(self, service: Union[Services, str], _id: str) -> Containers.Ban: | ||
return Containers.Ban( | ||
Methods.ban( | ||
api_base=self.api_base, | ||
service=str(service), | ||
_id=_id | ||
) | ||
) | ||
|
||
def get_sms(self, service: Union[Services, str], country: Union[Countries, str], _id: str) -> Containers.SMS: | ||
return Containers.SMS( | ||
Methods.get_sms( | ||
api_base=self.api_base, | ||
service=str(service), | ||
country=str(country), | ||
_id=_id | ||
) | ||
) | ||
|
||
def denial(self, service: Union[Services, str], country: Union[Countries, str], _id: str) -> Containers.Denial: | ||
return Containers.Denial( | ||
Methods.denial( | ||
api_base=self.api_base, | ||
service=str(service), | ||
country=str(country), | ||
_id=_id | ||
) | ||
) | ||
|
||
def get_proveka(self, service: Union[Services, str], number: str) -> Containers.Proverka: | ||
return Containers.Proverka( | ||
Methods.get_proverka( | ||
api_base=self.api_base, | ||
service=str(service), | ||
number=number | ||
) | ||
) | ||
|
||
def balance_sim(self, service: Union[Services, str], _id: str) -> Containers.BalanceSIM: | ||
return Containers.BalanceSIM( | ||
Methods.balance_sim( | ||
api_base=self.api_base, | ||
service=str(service), | ||
_id=_id | ||
) | ||
) | ||
|
||
def redirect(self, service: Union[Services, str], number_redirect: str, _id: str) -> Containers.Redirect: | ||
return Containers.Redirect( | ||
Methods.redirect( | ||
api_base=self.api_base, | ||
service=str(service), | ||
_id=_id, | ||
number_redirect=number_redirect | ||
) | ||
) | ||
|
||
def get_2fa(self, secret: str) -> Containers.TwoFA: | ||
return Containers.TwoFA( | ||
Methods.get_2fa( | ||
api_base=self.api_base, | ||
secret=str(secret) | ||
) | ||
) | ||
|
||
def get_clearsms(self, service: Union[Services, str], _id: str) -> Containers.ClearSMS: | ||
return Containers.ClearSMS( | ||
Methods.get_clearsms( | ||
api_base=self.api_base, | ||
service=str(service), | ||
_id=_id | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Errors: | ||
from .errors import GeneralError | ||
from .errors import NetworkingError | ||
from .errors import APIError | ||
from .errors import UnknownAPIError | ||
from .errors import MaxRequestsPerMinuteError | ||
from .errors import NegativeKarmaError | ||
from .errors import MaxConcurrentStreamsError | ||
from .errors import InvalidAPIKeyError | ||
from .errors import InsufficientFundsError | ||
from .errors import TooShortIntervalError | ||
from .errors import RepeatRequestLaterError | ||
from .errors import RequestSyntaxError | ||
from .errors import UserInfoError | ||
from .errors import NumberAlreadyTakenError | ||
from .errors import BanError | ||
from .errors import GetSMSError | ||
from .errors import DenialFailedError | ||
from .errors import ClearSMSError | ||
from .errors import BalanceSIMError | ||
from .errors import ProverkaNumberForServiceError | ||
from .errors import ProverkaGSMBusyError | ||
from .errors import ProverkaNumberError | ||
from .errors import RedirectFailError | ||
from .errors import RedirectInvalidNumberFormat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
class GeneralError(Exception): | ||
"""Base class for exceptions in this module.""" | ||
|
||
|
||
class NetworkingError(GeneralError): | ||
"""Networking Error""" | ||
|
||
|
||
# API errors | ||
class APIError(GeneralError): | ||
"""Base class for API error""" | ||
|
||
|
||
class UnknownAPIError(APIError): | ||
"""Unknown API error""" | ||
|
||
|
||
# Return code errors | ||
class MaxRequestsPerMinuteError(APIError): | ||
"""You have exceeded the number of requests per minute""" | ||
|
||
|
||
class NegativeKarmaError(APIError): | ||
"""You will be banned for 10 minutes, because scored negative karma""" | ||
|
||
|
||
class MaxConcurrentStreamsError(APIError): | ||
"""You have exceeded the number of concurrent streams. SMS Wait from previous orders""" | ||
|
||
|
||
class InvalidAPIKeyError(APIError): | ||
"""Invalid API KEY has been entered""" | ||
|
||
|
||
class InsufficientFundsError(APIError): | ||
"""Insufficient funds""" | ||
|
||
|
||
class TooShortIntervalError(APIError): | ||
"""Set a longer interval between calls to API server""" | ||
|
||
|
||
class RepeatRequestLaterError(APIError): | ||
"""Try to repeat your request later.""" | ||
|
||
|
||
class RequestSyntaxError(APIError): | ||
"""Check the request syntax and the list of parameters used (can be found on the page with method description).""" | ||
|
||
|
||
# Method errors | ||
# get_balance, get_userinfo | ||
class UserInfoError(APIError): | ||
"""Not ID or user balance""" | ||
|
||
|
||
# get_number | ||
class NumberAlreadyTakenError(APIError): | ||
"""Number is already taken""" | ||
|
||
|
||
# ban | ||
class BanError(APIError): | ||
"""Ban request has failed""" | ||
|
||
|
||
# get_sms | ||
class GetSMSError(APIError): | ||
"""No such SMS or invalid request ID or SMS waiting time has expired (no more than 10 minutes)""" | ||
|
||
|
||
# denial | ||
class DenialFailedError(APIError): | ||
"""Denial request has failed""" | ||
|
||
|
||
# clearsms | ||
class ClearSMSError(APIError): | ||
"""ClearSMS error""" | ||
|
||
|
||
# balance_sim | ||
class BalanceSIMError(APIError): | ||
"""SIM card balance info hasn't been received""" | ||
|
||
|
||
# get_proverka errors | ||
class ProverkaNumberForServiceError(APIError): | ||
"""You didn't order a number for this service""" | ||
|
||
|
||
class ProverkaGSMBusyError(APIError): | ||
"""GSM module is busy try to repeat your request 5 minutes later""" | ||
|
||
|
||
class ProverkaNumberError(APIError): | ||
"""There's no such number in the system any longer""" | ||
|
||
|
||
# redirect errors | ||
class RedirectFailError(APIError): | ||
"""Redirecting failed""" | ||
|
||
|
||
class RedirectInvalidNumberFormat(APIError): | ||
"""Invalid number format for redirecting""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Methods: | ||
from .balance_sim import balance_sim | ||
from .ban import ban | ||
from .denial import denial | ||
from .get_2fa import get_2fa | ||
from .get_balance import get_balance | ||
from .get_clearsms import get_clearsms | ||
from .get_count_new import get_count_new | ||
from .get_number import get_number | ||
from .get_proverka import get_proverka | ||
from .get_service_price import get_service_price | ||
from .get_sms import get_sms | ||
from .get_userinfo import get_userinfo | ||
from .redirect import redirect |
Oops, something went wrong.