-
Notifications
You must be signed in to change notification settings - Fork 0
/
smsresponse-github-copy.py
72 lines (69 loc) · 2.78 KB
/
smsresponse-github-copy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask, request, redirect
from twilio.rest import TwilioRestClient
import twilio.twiml
import os
import time
import re
app = Flask(__name__)
sendToAaron = False
@app.route("/", methods=['GET', 'POST'])
def hello_monkey():
"""Respond to incoming calls with a simple text message."""
resp = twilio.twiml.Response()
messageBody = request.values.get('Body', None)
if "song" in messageBody.lower():
os.chdir('/Users/qadirhaqq/')
if "song" in messageBody:
messageBody = messageBody.split("song")[1].strip()
elif "Song" in messageBody:
messageBody = messageBody.split("Song")[1].strip()
os.system('casperjs song-scrape-lazy.js "' + messageBody + '"')
if "manga" in messageBody.lower():
path = '/Users/qadirhaqq/Desktop/latestChapter/'
os.chdir('/Users/qadirhaqq/Documents/ScrapingScripts/')
if "1" in messageBody:
print("Downloading One Piece")
os.system('casperjs pictureGrab.js 1')
if "2" in messageBody:
print("Downloading Kingdom")
os.system('casperjs pictureGrab.js 2')
print("Messagebody: " + messageBody)
pictures = open('/Users/qadirhaqq/Desktop/images.txt')
account_sid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client = TwilioRestClient(account_sid, auth_token)
first = True
chapter = ""
for line in pictures:
if(first):
lineSplit = line.split('/')
chapter = lineSplit[6]
first = False
if chapter not in line:
lineSplit = line.split('/')
newLine = lineSplit[0] + "/";
for i in range(1,6):
newLine += lineSplit[i] + "/"
newLine += chapter + "/" + lineSplit[len(lineSplit)-1]
line = newLine
print(line)
time.sleep(10)
sendPicture(line.strip(), client, "+12157912925")
os.chdir('/Users/qadirhaqq/Desktop')
os.system('rm images.txt')
if "alert" in messageBody.lower():
# find consistent time layout
alert = messageBody.split('-')[1]
print(time.asctime( time.localtime(time.time() + 8000) ))
resp = twilio.twiml.Response()
resp.message(alert)
print("Message body: " + messageBody)
resp = twilio.twiml.Response()
resp.message("Process Completed")
return str(resp)
def sendPicture(picture, client, number):
message = client.messages.create(to=number, from_="+12679918238",
media_url=[picture])
return message
if __name__ == "__main__":
app.run(debug=True)