forked from errbotio/err-code
-
Notifications
You must be signed in to change notification settings - Fork 1
/
codepad.py
29 lines (27 loc) · 1.11 KB
/
codepad.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
__author__ = 'gbin'
import requests
from bs4 import BeautifulSoup
class CodePad(object):
def __init__(self, code=None, lang="Python", private=True, run=True):
self.code = code
self.lang = lang
self.private = "True" if private else "False"
self.run = "True" if run else "False"
self.data = {'code': self.code, 'lang': self.lang,
'private': self.private, 'run': self.run,
'submit': 'Submit'}
def eval(self):
r = requests.post("http://codepad.org/", data=self.data)
result = ''
if r.ok:
soup = BeautifulSoup(r.content)
asses = soup.findAll('a')
for a in asses:
name = a.get('name')
if name and name.startswith('output-line'):
res = a.parent.parent.parent.nextSibling.nextSibling.div.pre.string
if res and result != res:
result += res
else:
result = "Error, check the error here : " + r.url
return result.strip('\n ').replace('"', '"')