Skip to content

Instantly share code, notes, and snippets.

@lavr
Last active September 15, 2019 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lavr/27aebf1facc34092c25322f75b7b013b to your computer and use it in GitHub Desktop.
Save lavr/27aebf1facc34092c25322f75b7b013b to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# encoding: utf-8
import requests
import sys
import logging
class SMSRU(object):
def __init__(self, api_id):
self.api_id = api_id
def send(self, phone, msg):
if len(msg)>100:
msg = msg[:100]
r = requests.get(url='https://sms.ru/sms/send', params={'api_id': self.api_id, 'to': phone, 'msg': msg, 'json': 1, 'from': '***', 'translit': 1})
r.raise_for_status()
logging.debug('sms.ru response: %s %s', r.status_code, r.text)
if __name__ == '__main__':
logging.basicConfig(filename="/var/log/smsru.log", level=logging.DEBUG)
logging.info('smsru call: %s', sys.argv)
if len(sys.argv) != 4:
logging.error('smsru call parameters invalid')
print("Usage: {} [recipient] [subject] [message]".format(sys.argv[0]))
sys.exit(2)
recipient, subject, message = sys.argv[1:]
SMSRU(api_id='***').send(recipient, msg='{} {}'.format(subject, message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment