fork download
  1.  
  2. from os.path import exists, split, splitext
  3. from sys import argv
  4.  
  5. from urllib.parse import urlunparse
  6. from requests import get, post
  7. from lxml.etree import HTML
  8. namespaces = dict(re="http://e...content-available-to-author-only...t.org/regular-expressions")
  9.  
  10. from pprint import pprint
  11.  
  12.  
  13. extensions = {
  14. ".c": "C",
  15. ".cpp": "C++14",
  16. ".java": "Java7",
  17. ".pl": "Perl",
  18. ".php": "PHP",
  19. ".py": "Python 3",
  20. ".ruby": "Ruby",
  21. ".sql": "SQL",
  22. ".vb": "VB.NET",
  23. ".go": "GO",
  24. ".js": "JavaScript (rhino)",
  25. ".lua": "Lua",
  26. }
  27.  
  28. def get_ideone(_lang):
  29. url = "http://i...content-available-to-author-only...e.com/"
  30. headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" }
  31. rs = get(url, headers=headers)
  32. root = HTML(rs.content if rs.ok else "<error/>")
  33.  
  34. data = {}
  35. for x in root.xpath('//*[re:test(@id,"p[1-3]")]', namespaces=namespaces):
  36. data[x.get("id")] = x.get("value")
  37.  
  38. p2 = int(data["p2"])
  39. p3 = int(data["p3"])
  40. p4 = p2 * sum(range(p3))
  41. data["p4"] = str(p4)
  42.  
  43. _langs = {}
  44. for x in root.xpath('//li/*[re:test(@id,"menu-lang-[0-9]+")]', namespaces=namespaces):
  45. _langs[x.text.upper()] = int(x.get("data-id"))
  46. data["_lang"] = _langs[_lang]
  47.  
  48. return rs.cookies, data
  49.  
  50. def ideone(path, _lang=''):
  51. d, f = split(path)
  52. n, e = splitext(f)
  53.  
  54. if len(_lang) <= 0:
  55. _lang = "Text"
  56. if e.lower() in extensions.keys():
  57. _lang = extensions[e.lower()]
  58.  
  59. cookies, data = get_ideone(_lang.upper())
  60.  
  61. data.update({
  62. "input": '',
  63. "syntax": 1,
  64. "timelimit": 0,
  65. "note": '',
  66. "public": 1,
  67. "run": 1,
  68. "Submit": '',
  69. })
  70.  
  71. with open(path, 'r') as ro:
  72. data["file"] = ro.read()
  73.  
  74. url = "http://i...content-available-to-author-only...e.com/ideone/Index/submit/"
  75. headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" }
  76. rs = post(url, headers=headers, cookies=cookies, data=data, allow_redirects=False)
  77.  
  78. scheme = "http"
  79. netloc = "ideone.com"
  80. path = rs.headers["Location"]
  81. params = ''
  82. query = ''
  83. favorite = ''
  84. return _lang, urlunparse((scheme, netloc, path, params, query, favorite))
  85.  
  86. def usage(name):
  87. print("Usage: ./{} <file1> <file2> ...".format(name))
  88.  
  89. def main(argc, args):
  90. if argc == 1:
  91. d, f = split(__file__)
  92. usage(f)
  93. else:
  94. for i, x in enumerate(args[1:]):
  95. d, f = split(x)
  96. _lang, url = ideone(x)
  97. print(" - #{} ({}): {} - {}".format(i + 1, f, _lang, url))
  98.  
  99. if __name__ == "__main__":
  100. main(len(argv), argv)
  101.  
  102.  
Success #stdin #stdout #stderr 0.26s 52024KB
stdin
Standard input is empty
stdout
Usage: ./prog <file1> <file2> ...
stderr
/bin/sh: 1: cannot create /dev/null: Permission denied
/bin/sh: 1: cannot create /dev/null: Permission denied
/bin/sh: 1: cannot create /dev/null: Permission denied
/bin/sh: 1: cannot create /dev/null: Permission denied