-
-
Save idlethreat/40f75359d67c7b0c17c7 to your computer and use it in GitHub Desktop.
reddit-messages-to-graylog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import praw | |
from gelfclient import UdpClient | |
# ++ reddit items | |
# setting your username and password | |
myUsername = "yourusername" # your reddit username | |
myPassword = "yourpassword" # your reddit password | |
# ++ gelf items | |
myGraylogServer = 'ip_add_goes_here' # IP address of your graylog instance | |
def send_gelf_message(r_message_id,r_author,r_subject,r_body,r_link): | |
gelf_server = myGraylogServer | |
gelf = UdpClient(gelf_server, port=12201, mtu=8000, source='reddit messages') | |
data = {} | |
data['message_id'] = r_message_id | |
data['author'] = r_author | |
data['subject'] = r_subject | |
data['short_message'] = r_body | |
data['full_message'] = r_body | |
data['link'] = r_link | |
gelf.log(data) | |
r = praw.Reddit(user_agent='PythonPrawProject') | |
r.login(myUsername, myPassword) | |
unread = r.get_unread(limit=None) | |
for msg in unread: | |
message_id = msg.id | |
author = msg.author.name | |
subject = msg.subject | |
body = msg.body | |
message_link = "https://www.reddit.com/message/messages/" + message_id | |
# debugging messages. reenable if you need to see what is being received | |
# print "id: ", message_id | |
# print "author: ", author | |
# print "subject: ", subject | |
# print "body: ", body | |
# print "message link: ", message_link | |
print "Logging the contents of message " + message_id + " in graylog at " + myGraylogServer + " and marking as read." | |
send_gelf_message(message_id,author,subject,body,message_link) | |
# this will mark all messages as read in reddit, so should be called last at the end of pass | |
msg.mark_as_read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment