def compile(source, lang, stdin=''): """Compile and evaluate source sode using the ideone API and return a dict containing the output details. Keyword arguments: source -- a string containing source code to be compiled and evaluated lang -- the programming language pertaining to the source code stdin -- optional "standard input" for the program >>> d = compile('print("Hello World")', 'python') >>> d['output'] Hello World """ lang = LANG_ALIASES.get(lang.lower(), lang) # Login to ideone and create a submission i = ideone.Ideone(I_USERNAME, I_PASSWORD) sub = i.create_submission(source, language_name=lang, std_input=stdin) sub_link = sub['link'] details = i.submission_details(sub_link) # The status of the submission indicates whether or not the source has # finished executing. A status of 0 indicates the submission is finished. while details['status'] != 0: details = i.submission_details(sub_link) time.sleep(3) details['link'] = sub_link return details
""" Script that generates a formatted table of supported languages for the CompileBot wiki. """ import yaml import ideone SETTINGS_FILE = 'compilebot/config.yml' with open(SETTINGS_FILE, 'r') as f: SETTINGS = yaml.load(f) i = ideone.Ideone(SETTINGS['ideone_user'], SETTINGS['ideone_pass']) languages = i.languages() simple_langs = dict( (k, v.split('(')[0].strip()) for (k, v) in languages.items()) lang_shortcuts = SETTINGS['lang_aliases'] table = "Language Name | Short Names \n---------|----------\n" rows = [] count = 0 for num, lang in languages.items(): shortcuts = '' simple_name = simple_langs[num] for shortcut, simple in lang_shortcuts.items(): if simple.lower() == simple_name.lower(): shortcuts += ', {}'.format(shortcut) rows.append("{}|{}\n".format(lang, simple_name + shortcuts)) count += 1 rows.sort(key=lambda s: s.lower()) table += ''.join(rows) print(table)