def check_and_run() :
imap_conn = imapclient.IMAPClient (domain_name, ssl = True)
print (imap_conn)
try :
print (imap_conn.login (emailaddress, password))
except :
print ('Wrong username password combination! Please try again.')
sys.exit()
print (imap_conn.select_folder ('INBOX', readonly = False))
uids = imap_conn.gmail_search ('label:' + label + ' label:Inbox ' + emailaddress + ' subject:' + mysubject + ' label:unread')
print (uids)
messages = imap_conn.fetch (uids, ['BODY[]'])
for x in messages.keys() :
lstcomm = pyzmail.PyzMessage.factory (messages[x][b'BODY[]'])
commands.append (lstcomm.text_part.get_payload().decode (lstcomm.text_part.charset))
print (imap_conn.logout())
twilioClient = TwilioRestClient (twilioSID, twilioAuthToken)
for x in commands[::-1] :
newfile = open ('commandstorun.py', 'w')
newfile.write ('#! /usr/bin/python3\n')
newfile.write (x)
newfile.close()
os.system ('chmod +x commandstorun.py')
os.system ('./commandstorun.py')
print ('Executed script :\n' + x)
msg = twilioClient.messages.create (body = 'Your script has been executed! ' + x, from_ = sender, to = receiver)
print (msg.status)
python类TwilioRestClient()的实例源码
Execute_Instructions_Remotely.py 文件源码
项目:Cool-Scripts
作者: Anishka0107
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def textmyself(message):
twilioCli = TwilioRestClient(accountSID, authToken)
twilioCli.messages.create(body=message, from_=twilioNumber, to=myNumber)
def test_creds_error(creds):
creds.return_value = (None, None)
assert_raises(TwilioException, TwilioRestClient)
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID",
"AUTH_TOKEN")
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN",
timeout=sentinel.timeout)
def getClient(self):
if self.smsclient:
return self.smsclient
assert 'twilio_sid' in self.settings
self.smsclient = TwilioRestClient(self.settings['twilio_sid'],
self.settings['twilio_token'])
return self.smsclient
def __init__(self):
self.map = {}
self.brd = {}
exec(open('./twilio.json').read())
print
sid = x['twilio']['account_sid']
sec = x['twilio']['secret']
self.twilio = TwilioRestClient(sid, sec)
def _get_twilio_client():
"""Return twilio rest client with variables"""
return TwilioRestClient(
current_app.config.get("TWILIO_ACCOUNT_SID"),
current_app.config.get("TWILIO_AUTH_TOKEN"))
def alert(self, matches):
client = TwilioRestClient(self.twilio_accout_sid, self.twilio_auth_token)
try:
client.messages.create(body=self.rule['name'],
to=self.twilio_to_number,
from_=self.twilio_to_number)
except TwilioRestException as e:
raise EAException("Error posting to twilio: %s" % e)
elastalert_logger.info("Trigger sent to Twilio")
tasks.py 文件源码
项目:django-channels-celery-websocket-example
作者: rollokb
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def send_phone_code(user_id, verify_token, phone_number):
customer = Customer.objects.get(id=user_id)
# simulating a short delay
sleep(randint(3, 9))
client = TwilioRestClient( # noqa
settings.TWILLO_API_KEY,
settings.TWILLO_AUTH_TOKEN,
)
try:
client.messages.create(
to=phone_number,
from_=settings.TWILLO_FROM_NUMBER,
body="Your Verify Code is {}".format(
verify_token
)
)
# Notify the FE task has completed
Group('phone_verify-%s' % customer.username).send({
'text': json.dumps({
'success': True,
'msg': 'new message sent'
})
})
except TwilioRestException as e:
Group('phone_verify-%s' % customer.username).send({
'text': json.dumps({
'success': False,
'msg': e.msg
})
})
def send_message(request, source, destination, menu_text):
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
client.messages.create(
to=destination,
from_=source,
body=menu_text,
)
request.session['last_message'] = menu_text
def textmyself(self, message):
twilioCli = TwilioRestClient(self.accountsid, self.authtoken)
twilioCli.messages.create(body=message, from_=self.twiliocell, to=self.mycellphone)
print("successfully sent the text")
def textmyself(message):
twilioCli = TwilioRestClient(accountSID, authToken)
twilioCli.messages.create(body = message, from_ = twilioNumber, to = myNumber)
def sendMessage(mediaURL):
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
client.messages.create(
to="+14254298436",
from_="+19284874422 ",
media_url=mediaURL,
)
return
def get_twilio_client(self):
return TwilioRestClient(self.config['account_sid'],
self.config['auth_token'])
test_credentials.py 文件源码
项目:alexa-ive-fallen-and-cant-get-up
作者: heatherbooker
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def test_creds_error(creds):
creds.return_value = (None, None)
assert_raises(TwilioException, TwilioRestClient)
test_client.py 文件源码
项目:alexa-ive-fallen-and-cant-get-up
作者: heatherbooker
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID",
"AUTH_TOKEN")
test_client.py 文件源码
项目:alexa-ive-fallen-and-cant-get-up
作者: heatherbooker
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN",
timeout=sentinel.timeout)
def send_test_sms(recepient=None):
details = sms_model.get()
client = TwilioRestClient(details['account'], details['token'])
t = threading.Thread(target=_send_sms_in_thread,
kwargs={"client": client,
"from_": details['from_'],
"to": recepient,
"body": "Amon alert!"
})
t.start()