Класс для работы с API на Python
Класс для BashКласс для СКласс для C++Класс для C#Класс для GoLangКласс для JavaКласс для Node.jsКласс для PHPКласс для LaravelКласс для PythonКласс для RubyКласс для RustКласс для PerlКласс для swift
Класс для работы с API на Python
Установка
pip install -U smsaero-apiАсинхронная версия
pip install -U smsaero-api-asyncИспользование
from pprint import pprint
from smsaero import SmsAero, SmsAeroException
SMSAERO_EMAIL = 'your email'
SMSAERO_API_KEY = 'your api key'
def send_sms(phone: int, message: str) -> dict:
"""
Sends an SMS message
Parameters:
phone (int): The phone number to which the SMS message will be sent.
message (str): The content of the SMS message to be sent.
Returns:
dict: A dictionary containing the response from the SmsAero API.
"""
api = SmsAero(SMSAERO_EMAIL, SMSAERO_API_KEY)
return api.send_sms(phone, message)
if __name__ == '__main__':
try:
result = send_sms(70000000000, 'Hello, World!')
pprint(result)
except SmsAeroException as e:
print(f"An error occurred: {e}")Доступные методы и параметры вызова смотрите в исходном коде.
Асинхронное использование
import pprint
import asyncio
import smsaero
SMSAERO_EMAIL = 'your email'
SMSAERO_API_KEY = 'your api key'
async def send_sms(phone: int, message: str) -> None:
"""
Sends an SMS message
Parameters:
phone (int): The phone number to which the SMS message will be sent.
message (str): The content of the SMS message to be sent.
"""
api = smsaero.SmsAero(SMSAERO_EMAIL, SMSAERO_API_KEY)
try:
result = await api.send_sms(phone, message)
pprint.pprint(result)
finally:
await api.close_session()
if __name__ == '__main__':
asyncio.run(send_sms(70000000000, 'Hello, World!'))Доступные методы и параметры вызова смотрите в исходном коде асинхронной версии.
Мы используем на сайте cookie.
Исключительно с благими намерениями.
Вы соглашаетесь с условиями обработки, используя сайт. Подробнее
Вы соглашаетесь с условиями обработки, используя сайт. Подробнее