-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmonitoring.py
46 lines (35 loc) · 1009 Bytes
/
monitoring.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
import MySQLdb
import requests
db = MySQLdb.connect(host="",
user="",
passwd="",
db="",
charset="utf8")
list_of_tweets = []
def query(url):
r = requests.get(url)
if r.status_code != 200:
return True
else:
print "Tweet still exists"
def read_database(db):
cur = db.cursor()
cur.execute("""SELECT * \
FROM Tweets \
WHERE Deleted=0""")
for tweet in cur:
list_of_tweets.append(tweet)
print tweet
return list_of_tweets
def check_tweet():
for tweet in read_database(db):
if query(tweet[3]) is True:
cur = db.cursor()
cur.execute("""UPDATE Tweets \
SET Deleted=1 \
WHERE Tweet_Id=%s""", [tweet[4]])
db.commit()
print "tweet deleted, id is", tweet[4]
print "url is", tweet[3]
if __name__ == "__main__":
check_tweet()