-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfull_otherdm.py
executable file
·57 lines (40 loc) · 1.87 KB
/
full_otherdm.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
#!/usr/bin/env python3
import json
import os
import urllib3
from urllib.parse import quote
from settings import *
SPATH = "/home/grief/lis_grievances"
#I'm using RUBY for the love of...
os.system("twurl -X GET /1.1/direct_messages/events/list.json > /home/grief/lis_grievances/dms.json")
dj = json.loads(open("/home/grief/lis_grievances/dms.json").read())
if "errors" in dj:
print("Hit an error " + json.dumps(dj))
exit()
if dj["events"] == []:
print("nothing sent")
exit()
for e in dj["events"]:
message_id = e["id"]
message_text = e["message_create"]["message_data"]["text"]
sender_id = e["message_create"]["sender_id"]
print(message_text.encode("utf-8"))
# Post to GF
http = urllib3.PoolManager()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
if len(message_text) > 280:
r = http.request('GET',GFORM_URL+quote("LONG "+message_text))
else:
r = http.request('GET',GFORM_URL+quote(message_text))
#Delete Original
del_line = "twurl -X DELETE /1.1/direct_messages/events/destroy.json?id="+message_id
os.system(del_line)
#Send success message & delete it
feedback_line = "twurl -A 'Content-type: application/json' -X POST /1.1/direct_messages/events/new.json -d '{\"event\": {\"type\": \"message_create\", \"message_create\":{\"target\": {\"recipient_id\": \""+sender_id+"\"}, \"message_data\": {\"text\": \"Thanks for submitting your grievance. \\n It has been queued for approval. \\n Details here: http:\/\/lisgrievances.com \"}}}}'"
os.system(feedback_line+"> /home/grief/lis_grievances/to_del.json")
del_mes = json.loads(open("/home/grief/lis_grievances/to_del.json").read())
del_mes_id = del_mes["event"]["id"]
del_res_line = "twurl -X DELETE /1.1/direct_messages/events/destroy.json?id="+del_mes_id
os.system(del_res_line)
os.remove("/home/grief/lis_grievances/to_del.json")
os.remove("/home/grief/lis_grievances/dms.json")