Last active
March 15, 2019 08:16
-
-
Save limitedeternity/b19bcf33bddc8aada9a12943336c6db0 to your computer and use it in GitHub Desktop.
Dcoder CLI app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import argparse | |
| from pathlib import Path | |
| from requests import Session | |
| extToLangCodeMap = { | |
| ".cs": 1, # C# | |
| ".java": 4, # Java | |
| ".c": 6, # C | |
| ".cpp": 7, # C++ | |
| ".php": 8, # PHP | |
| ".pas": 9, # Pascal | |
| ".rb": 12, # Ruby | |
| ".asm": 15, # Assembly | |
| ".lisp": 18, # Common Lisp | |
| ".go": 20, # Golang | |
| ".js": 23, # Node.js | |
| ".py": 24, # Python3 | |
| ".swift": 37, # Swift | |
| ".rs": 45 # Rust | |
| } | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("-f", "--file", help="Quoted path to your program", required=True) | |
| parser.add_argument("-c", "--compilerArgs", help="Compiler arguments") | |
| parser.add_argument("-i", "--input", help="Stdin for your program (use \\n as splitter to make multiline input)") | |
| args = parser.parse_args() | |
| filePath = Path(args.file) | |
| if not filePath.is_file(): | |
| raise Exception("Invalid file") | |
| with open(filePath, "r") as file: | |
| contents = file.read() | |
| response = Session().post("https://m314.dcoder.tech/api/compiler", json={ | |
| "CompilerArgs": args.compilerArgs if args.compilerArgs else "", | |
| "Input": args.input.replace("\\n", "\n") if args.input else "", | |
| "LanguageChoice": extToLangCodeMap[filePath.suffix.lower()], | |
| "Program": contents | |
| }) | |
| json = response.json() | |
| if json["Result"]: | |
| print(f"Result:\n{json['Result']}") | |
| else: | |
| print(f"Errors:\n{json['Errors']}") | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| requests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment