def setUp(self): self.api_username = API_USERNAME self.api_password = API_PASSWORD self.api = SmsAPI() self.api.set_username(self.api_username) self.api.set_password(self.api_password)
def __init__(self, fail_silently=False, **kwargs): self.fail_silently = fail_silently self.username = kwargs.get('username', None) self.password = kwargs.get('password', None) self.auth_token = kwargs.get('auth_token', None) if not self.username and not self.password and not self.auth_token: raise ImproperlyConfigured( 'Please provide user credentials or auth_token for SMSApi ' 'backend in settings') self.api = SmsAPI(username=self.username, password=self.password, auth_token=self.auth_token)
class SmsBackend(object): """ SMSAPI backend implementation. SMSApi is a polish sms service provider see _`https://www.smsapi.pl/` for more information. """ def __init__(self, fail_silently=False, **kwargs): self.fail_silently = fail_silently self.username = kwargs.get('username', None) self.password = kwargs.get('password', None) self.auth_token = kwargs.get('auth_token', None) if not self.username and not self.password and not self.auth_token: raise ImproperlyConfigured( 'Please provide user credentials or auth_token for SMSApi ' 'backend in settings') self.api = SmsAPI(username=self.username, password=self.password, auth_token=self.auth_token) def send_messages(self, messages): """ Sends one or more SmsMessage objects and returns the number of messages sent """ for message in messages: self.api.service('sms').action('send') self.api.set_content(message.body) self.api.set_to(message.to) self.api.execute() return len(messages)
class SmsApiTestCase(unittest.TestCase): def setUp(self): self.api_username = API_USERNAME self.api_password = API_PASSWORD self.api = SmsAPI() self.api.set_username(self.api_username) self.api.set_password(self.api_password) if sys.version_info[:2] == (2, 6): def assertIsInstance(self, x, y): assert isinstance(x, y), "%r is not instance of %r" % (x, y) def assertIsNotNone(self, x): assert x is not None, "%x is None" % x
def send_sms(message, recipient): app = current_app._get_current_object() api = SmsAPI() api.auth_token = app.config['SMSAPI_TOKEN'] try: api.service('sms').action('send') api.set_content(message) api.set_to(recipient) api.execute() return True except ApiError: return False
import random from smsapi.client import SmsAPI from smsapi.responses import ApiError api = SmsAPI() api.set_username('email_address') api.set_password('account_password') people = { 'person1': 'polish_phone_number_1', 'person2': 'polish_phone_number_2', 'person3': 'polish_phone_number_3', } def shuffle(): while True: try: set_ = set(people.keys()) pairs = [] for person in set_: to_choose = list(set_ - {person} - {w for _, w in pairs}) pairs.append((person, random.choice(to_choose))) except IndexError: # someones left with empty list to shuffle pass else: return pairs
from smsapi.client import SmsAPI api = SmsAPI() api.set_username('client_username') api.set_password('client_password') api.service('sms').action('send') api.set_content('sample message') api.set_to('some_phone_number') result = api.execute() for r in result: print(r.id, r.points, r.status)
from smsapi.client import SmsAPI api = SmsAPI() api.set_username('client_username') api.set_password('client_password') api.service('sms').action('send') api.set_content('Hello [%1%] [%2%]') api.set_params('name', 'last name') api.set_to('some_phone_number') result = api.execute() for r in result: print(r.id, r.points, r.status)
from smsapi.client import SmsAPI api = SmsAPI() api.set_username('client_username') api.set_password('client_password') api.service('phonebook').action('contact_add') api.set_number('some_phone_number') api.set_first_name('first_name') api.set_last_name('last_name') api.set_email('*****@*****.**') api.set_birthday('01-01-1970') api.set_city('city') api.set_groups(['some_existing_group_name']) result = api.execute() for r in result: print(r.id, r.points, r.status)
def __init__(self, username, password): self.api = SmsAPI() self.api.set_username(username) self.api.set_password(password)
from smsapi.client import SmsAPI api = SmsAPI() api.set_username('client_username') api.set_password('client_password') api.service('sms').action('get') api.set_id('sms_id') response = api.execute() print(response.status, response.points, response.number)
def send_sms_smsapi(parent_phone, message): api = SmsAPI() # autoryzacyja standardowa api.set_username(settings.SMS_API_USERNAME) api.set_password(settings.SMS_API_PASS) try: api.service('sms').action('send') api.set_content(message) api.set_to(parent_phone) api.set_from('Info') result = api.execute() for r in result: # print r.id, r.points, r.status mail_body = 'Wyslano sms do %s o tresci: %s \n\ id: %s, points: %s, status: %s' % (parent_phone, message, r.id, r.points, r.status) mail_title = 'SMS wyslany do %s' % parent_phone admin_email(mail_title, mail_body) except ApiError, e: # print '%s - %s' % (e.code, e.message) mail_body = 'Blad wysylania smsa do %s, o tresci: %s \n\ kod bledu: %s, tresc bledu: %s, points: %s' % ( parent_phone, message, r.id, r.status, r.points) mail_title = 'Blad SMSa do %s' % parent_phone admin_email(mail_title, mail_body)
from smsapi.client import SmsAPI api = SmsAPI() api.set_username('client_username') api.set_password('client_password') api.service('client').action('account_details') response = api.execute() print(response.points)
img.save(obj, format='PNG', quality=90) obj.seek(0) return obj.read() def render_qrcode( request, text ): #text is pin #this is considered a helper function not really a view func text = web_url + 'result?pin=' + text qrcode = save_to_string( qrcodeGenerator.init(text)) #render and save it in mem response = HttpResponse(qrcode, content_type='image/png') return response api = SmsAPI() api.set_username('tike') api.set_password('869579e0598bd70a216261a80507efed') api.auth_token = 'q6QWErR7qkI9MNzA4bJJ86fltC5KfselYYiO2DUi' #sending SMS def id_generator(size=4, chars=string.ascii_uppercase + string.digits): """ generate a 4 character pin that is unique in db/ticket """ pin = ''.join(random.choice(chars) for _ in range(size)) if ticket.objects.filter(pin=pin).count() != 0: id_generator() else:
def send_sms(number, keyword, url): api = SmsAPI() api.auth_token = 'ombgS9YCMn0N6Do6iav1kwWlYwGocV6NbRIQAs5r' try: api.service('sms').action('send') api.set_content( u'Welcome, recently keyword: [%1%] appeared on page you are following. Go to post: [%2%] $echo-warsaw team' ) api.set_params(keyword, url) api.set_to(str(number)) # api.set_from('$echo-warsaw') result = api.execute() for r in result: print r.id, r.points, r.status except ApiError, e: print '%s - %s' % (e.code, e.message)
def send(message, settings): try: smsapi = SmsAPI() smsapi.set_username(settings['SMSAPI_LOGIN']) smsapi.set_password(settings['SMSAPI_PASS']) smsapi.service('sms').action('send') if settings['SMSAPI_PRO']: smsapi.set_from(settings['SMSAPI_PRO_FROM']) else: smsapi.set_eco(True) for phone in settings['PHONE_NUMBERS']: smsapi.set_content(message.encode('utf-8')) smsapi.set_to(phone) smsapi.execute() except ApiError, e: print 'ERROR: %s - %s' % (e.code, e.message)
def validate(request): try: pin = request.GET['pin'] ticket = Ticket.objects.get(pin=pin) dpapi.ddt['transaction_token'] = ticket.token event = Show.objects.get(id=ticket.event_id) tk_type = tickettype.objects.get(id=ticket.tickettype_id) dpapi.verify_token() print '###################' print 'validated', ticket.pin print '###################' ticket.payed = True ticket.save() #add sms stuff api = SmsAPI() api.set_username('tike') api.set_password('869579e0598bd70a216261a80507efed') api.auth_token = 'q6QWErR7qkI9MNzA4bJJ86fltC5KfselYYiO2DUi' api.service('sms').action('send') api.set_content( '[%1%] this ticket is for [%2%] in [%3%] at [%4%] your pin is [%5%],Help Call: 07893637884 Thank you! TIKE.' ) api.set_params(ticket.full_name, event.title, tk_type.tike_type, event.date.strftime("%d-%b at %H:%M"), pin) phone = str(ticket.phone_number) if phone[:4] != '+250': phone = '+250' + phone api.set_to(phone) api.set_from('Tike ltd') #Requested sender name result = api.execute() for r in result: print(r.id, r.points, r.status) return JsonResponse( {'stat': True}) #HttpResponseRedirect("/all")#render thank you page except: return JsonResponse({'stat': False}) #HttpResponseRedirect("/")
def send_sms(phone, token): api = SmsAPI() api.set_username(sms_user) api.set_password(sms_pass) api.auth_token = sms_token try: api.service('sms').action('send') api.set_content('Witaj, Twoj kod aktywacyjny: ' + str(token)) api.set_to(phone) api.set_from('Info') result = api.execute() for r in result: print r.id, r.points, r.status except ApiError, e: print '%s - %s' % (e.code, e.message)