Created
July 3, 2015 20:46
-
-
Save sksullivan/7384de0f8ec03f6a7f50 to your computer and use it in GitHub Desktop.
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
import requests | |
import time | |
import urllib | |
RUN_URL = u'http://api.hackerearth.com/v3/code/run/' | |
CLIENT_SECRET = 'huehuehuehuehuehuehuehuehuehueheu' | |
class RequestMaker(): | |
def __init__(self, lastUpdateID): | |
self.lastID = lastUpdateID | |
def run(self): | |
print('run') | |
reply = requests.get("https://api.telegram.org/bot999999999:HUEHUEHUEHUEHUEHUEHUEHUEHUEHUE/getUpdates?offset={}".format(self.lastID)) | |
updates = reply.json()['result'] | |
if (len(updates) > 0): | |
for update in updates: | |
print(update) | |
if 'text' in update['message']: | |
chatID = update['message']['chat']['id'] | |
source = update['message']['text'][1:] | |
data = { | |
'client_secret': CLIENT_SECRET, | |
'async': 0, | |
'source': source, | |
'lang': "C", | |
'time_limit': 5, | |
'memory_limit': 262144, | |
} | |
r = requests.post(RUN_URL, data=data) | |
if 'run_status' in r.json(): | |
if (r.json()['run_status']['status'] == 'AC'): | |
resp = r.json()['run_status']['output'] | |
elif (r.json()['run_status']['status'] == 'RE'): | |
resp = r.json()['run_status']['status_detail'] | |
elif (r.json()['run_status']['status'] == 'CE'): | |
resp = r.json()['run_status']['status_detail'] | |
else: | |
resp = "Werid, non compile or runtime error." | |
else: | |
resp = "John you broke it." | |
requests.get("https://api.telegram.org/bot999999999:HUEHUEHUEHUEHUEHUEHUEHUEHUEHUE/sendMessage?chat_id={}&text={}".format(chatID,resp)) | |
self.lastID = update['update_id'] if update['update_id'] > self.lastID else self.lastID | |
self.lastID += 1 | |
print(self.lastID) | |
time.sleep(10) | |
return self.lastID | |
if __name__ == '__main__': | |
#app.run() | |
print("starting") | |
lastID = 0 | |
while (1): | |
req = RequestMaker(lastID) | |
lastID = req.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment