Last active
December 10, 2015 12:19
-
-
Save theneosloth/4433407 to your computer and use it in GitHub Desktop.
Facepunch Ticker Checker (Unfinished)
This file contains hidden or 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
import urllib2,json,time,urllib2,getpass,hashlib,sys | |
from datetime import datetime | |
try: | |
f = open ("date.txt", "r") | |
date = json.load(f) | |
print "Date loaded is " +str(datetime.utcfromtimestamp(1356645899)) | |
f.close() | |
except IOError: | |
print "File not found" | |
date = 0 | |
user = raw_input("Input Username ") | |
password = getpass.getpass() | |
passwordmd5 = hashlib.md5(password).hexdigest() | |
url ="http://api.facepun.ch/?action=authenticate&username=superstepa&password="+passwordmd5 | |
link = urllib2.urlopen(url) | |
auth = json.load(link) | |
for line in auth: | |
if "error" in line: | |
print "Error: Invalid username or password" | |
raw_input("Press enter to exit") | |
sys.exit(1) | |
else: | |
session = auth["session_id"] | |
print "Authorized" | |
url ="http://api.facepun.ch/?action=getticker&session_id-"+session | |
while 1: | |
time.sleep(30) | |
feed = urllib2.urlopen(url) | |
jsonfeed = json.load(feed) | |
events = jsonfeed["events"] | |
for event in events: | |
try: | |
if (event["username"] == user) and (event['date'] > date): | |
if (event['type'] == 'post'): | |
print "You posted in the '" + event['thread'] + "' thread in the " + event['forum'] + ' subforum' | |
elif (event['type'] == 'closed'): | |
print "Your '" + event['thread'] + "' thread have been closed, because '" + event["reason"] + "'" | |
elif (event['type'] == 'ban'): | |
print "You have been banned by " + event['modusername'] + " for " + event["duration"] + ", because '" + event["reason"] + "'" | |
elif (event['type'] == 'rating'): | |
print event['username'] + ' rated you ' + event ['rating'] + " in the '" + event['thread'] + "'' thread" | |
date = event['date'] | |
try: | |
f = open ("date.txt", "w") | |
json.dump(date,f) | |
f.close() | |
except IOError: | |
print "File Error" | |
except KeyError: | |
pass | |
try: | |
if (event["mentioned"] == True): | |
print "You have been mentioned by " + event["username"] + " in the '" + event['thread'] + "' thread" | |
except KeyError: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't get an error in the authentication check at line 19 but I am not receiving the "rating" and "mentioned" events