forked from Charcoal-SE/SmokeDetector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetasmoke.py
62 lines (44 loc) · 2.35 KB
/
metasmoke.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
import json
import requests
from globalvars import GlobalVars
import threading
class Metasmoke:
@classmethod
def send_stats_on_post(self, title, link, reasons, body, username, user_link, why, owner_rep, post_score, up_vote_count, down_vote_count):
if GlobalVars.metasmoke_host is None:
print "Metasmoke location not defined, not reporting"
return
metasmoke_key = GlobalVars.metasmoke_key
try:
post = {'title': title, 'link': link, 'reasons': reasons, 'body': body, 'username': username, 'user_link': user_link, 'why': why, 'user_reputation': owner_rep, 'score': post_score, 'upvote_count': up_vote_count, 'downvote_count': down_vote_count}
post = dict((k, v) for k, v in post.iteritems() if v) # Remove None values (if they somehow manage to get through)
payload = {'post': post, 'key': metasmoke_key}
headers = {'Content-type': 'application/json'}
requests.post(GlobalVars.metasmoke_host + "/posts.json", data=json.dumps(payload), headers=headers)
except Exception as e:
print e
@classmethod
def send_feedback_for_post(self, post_link, feedback_type, user_name):
if GlobalVars.metasmoke_host is None:
print "Metasmoke location not defined; not reporting"
return
metasmoke_key = GlobalVars.metasmoke_key
try:
payload = {'feedback': {'user_name': user_name, 'feedback_type': feedback_type, 'post_link': post_link}, 'key': metasmoke_key}
headers = {'Content-type': 'application/json'}
requests.post(GlobalVars.metasmoke_host + "/feedbacks.json", data=json.dumps(payload), headers=headers)
except Exception as e:
print e
@classmethod
def send_status_ping(self):
if GlobalVars.metasmoke_host is None:
print "Metasmoke location not defined; not sending status ping"
return
threading.Timer(60, Metasmoke.send_status_ping).start()
metasmoke_key = GlobalVars.metasmoke_key
try:
payload = {'location': GlobalVars.location, 'key': metasmoke_key}
headers = {'Content-type': 'application/json'}
requests.post(GlobalVars.metasmoke_host + "/status-update.json", data=json.dumps(payload), headers=headers)
except Exception as e:
print e