add run to run code online
This commit is contained in:
parent
b2afabe860
commit
ab9246d55e
1 changed files with 32 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import requests
|
||||||
from zzcore import StdAns
|
from zzcore import StdAns
|
||||||
from config import GLOTTOKEN
|
from config import GLOTTOKEN
|
||||||
|
|
||||||
|
@ -48,6 +49,36 @@ class Ans(StdAns):
|
||||||
return '''Usage:
|
return '''Usage:
|
||||||
/run <lang>
|
/run <lang>
|
||||||
<your code>
|
<your code>
|
||||||
|
|
||||||
|
支持的语言:assembly ats bash c clojure cobol coffeescript cpp crystal csharp d elixir elm erlang fsharp go groovy haskell idris java javascript julia kotlin lua mercury nim ocaml perl perl6 php python ruby rust scala swift typescript
|
||||||
'''
|
'''
|
||||||
msg = f'{self.parms[0]}//{self.parms[1]}//{self.parms[2]}'
|
lang = self.parms[1]
|
||||||
|
i = 6 + len(lang)
|
||||||
|
content = self.raw_msg['message'][i:]
|
||||||
|
try :
|
||||||
|
langconfig = LANGS[lang]
|
||||||
|
name = langconfig['filename']
|
||||||
|
url = langconfig['url'] + '/latest'
|
||||||
|
except :
|
||||||
|
return f'不支持的语言 {lang}'
|
||||||
|
|
||||||
|
msg = glot(name, content, url)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def glot(name, content, url):
|
||||||
|
headers = {
|
||||||
|
'Authorization': f'Token {GLOTTOKEN}',
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"files": [{
|
||||||
|
"name": name,
|
||||||
|
"content": content,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
resp = requests.post(url=url, headers=headers, json=data).json()
|
||||||
|
r = f"stdout:\n{resp['stdout']}\nstderr:\n{resp['stderr']}\nerror:\n{resp['error']}"
|
||||||
|
return r
|
Loading…
Reference in a new issue