-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
82 lines (72 loc) · 2.75 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
import requests
import pymysql.cursors
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from data import *
# Connect to the database
conn = pymysql.connect(host=sqlhostname,
user=sqluser,
password=sqlpassword,
db=sqldbname,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
def CreateNeededTable():
global conn
cursor = conn.cursor()
query = "CREATE TABLE IF NOT EXISTS `messages`( `datanumber` int NOT NULL AUTO_INCREMENT,`id` text NOT NULL, PRIMARY KEY (datanumber)) ENGINE=MEMORY;"
cursor.execute(query)
def saveMessageId(x):
global conn
cursor = conn.cursor()
query = "INSERT INTO `messages` (`id`) VALUES (%s)"
cursor.execute(query, (str(x)))
def checkMessageId(x):
global conn
cursor = conn.cursor()
query = "SELECT * FROM `messages` WHERE id = '" + str(x) + "'"
cursor.execute(query)
row = cursor.fetchone()
if row == None:
print "Uploading New Message..."
print "Message: " + str(x)
saveMessageId(x)
if printMessageById(x) != False:
name, text = printMessageById(x)
SendText(str(name), str(text))
def printMessageById(idnumber):
global apikey
global token
texttypes = ["mentionedOnCard"]
querystring = {"key":apikey,"token":token}
url = "https://api.trello.com/1/notifications/" + str(idnumber)
response = requests.request("GET", url, params=querystring).json()
if response["type"] in texttypes:
name = response["memberCreator"]["fullName"]
text = response["data"]["text"]
return str(name), str(text)
else:
return False
def CheckMessages():
global username
url = "https://api.trello.com/1/members/" + username + "/notifications?fields=name,url&key=" + str(apikey) + "&token=" + str(token)
request = requests.get(url).json()
for i in range(0,len(request)):
try:
request[i]["id"]
except NameError:
print "well, it WASN'T defined after all!"
else:
checkMessageId(request[i]["id"])
def SendText(name, message):
global phonenumber
driver = webdriver.Firefox(executable_path=r'/usr/local/bin/geckodriver')
driver.get("http://www.24sms.net/")
driver.find_element_by_name('SendFrom').send_keys(str(name))
driver.find_element_by_name('SendTo').send_keys(str(phonenumber))
driver.find_element_by_name("Msg").send_keys(str(message))
driver.find_element_by_xpath("//input[@type='submit']").click()
CreateNeededTable()
CheckMessages()