Skip to content

Instantly share code, notes, and snippets.

@rane-hs
Last active December 28, 2015 20:59
Show Gist options
  • Save rane-hs/7561320 to your computer and use it in GitHub Desktop.
Save rane-hs/7561320 to your computer and use it in GitHub Desktop.
犬小屋python 雑
import urllib2
import json
cp_url = "http://melpon.org/wandbox/api/compile.json?"
list_url = "http://melpon.org/wandbox/api/list.json"
compilation_list = {}
def get_type(ext):
response = urllib2.urlopen(list_url)
response_json = json.JSONDecoder().decode(response.read())
for v in response_json:
language = v[u'language']
if compilation_list.get(language, None) is None:
compilation_list[language] = []
compilation_list[language].append(v)
print str(compilation_list)
return "php"
def goto_wand_main(input_string, compilation_type):
reqdata = {}
reqdata['compiler'] = "php-5.5.6"
reqdata['options'] = ""
reqdata['code'] = input_string
# reqdata['code'] = urllib.quote(input_string)
# reqdata['code'] = input_string
headers = { 'Content-type' : 'application/json' }
# print "input : " + contents + '\n'
# params = urllib.quote( json.JSONEncoder().encode(reqdata) )
params = json.JSONEncoder().encode(reqdata)
print "params : "+str(params)
response = urllib2.urlopen(urllib2.Request(cp_url, headers=headers), params )
print "response/url : "+str(response.geturl())
print "response/status : "+str(response.getcode())
print "response/info : "+str(response.info())
print "response/read : "+str(response.read())
edit = """<?php
class myclass {
var $var1; // this has no default value...
var $var2 = "xyz";
var $var3 = 100;
// constructor
function myclass() {
// change some properties
$this->var1 = "foo";
$this->var2 = "bar";
return true;
}
}
$my_class = new myclass();
$class_vars = get_class_vars(get_class($my_class));
foreach ($class_vars as $name => $value) {
echo "$name : $value\n";
}
echo $val = $class_vars['var4'];
echo "vars : ".var_export($class_vars, true);
?>
"""
compilation_type = get_type('php')
goto_wand_main(edit, compilation_type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment