Skip to content

Added a new Project- Code Compiler #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions Code Compiler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
67 changes: 67 additions & 0 deletions Code Compiler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--Please do not remove this part-->
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)
[![View My Profile](https://img.shields.io/badge/View-My_Profile-green?logo=GitHub)](https://github.com/thecoddiwompler)

# Code Compiler

## 🛠️ Description

This project is a code execution tool that interacts with an online code compiler API. It consists of the following folders and files:

- **src:** Contains the main Python scripts.
- `list_languages.py`: Retrieves and prints a list of available programming languages from the online code compiler API based on the contents of `language_list.txt` in the `input` folder.
- `main.py`: Prompts the user for a programming language, checks its availability using the API, and then executes the code from `code.txt` in the `input` folder with corresponding input from `input.txt`. The output is stored in `output.txt` in the `bin` folder.
- **bin:** Stores the output of code execution (`output.txt`) and logs (`logfile.log`).
- **input:** Contains input files for code (`code.txt` and `input.txt`) and a list of languages (`language_list.txt`).
- **.env:** Environment configuration file.
- **requirements.txt:** Specifies the project's dependencies. Developers can install these dependencies using the `pip install -r requirements.txt` command to ensure a consistent environment.
- **README.md:** Documentation file.
- **.gitignore:** Ignored files and directories for version control.
- **LICENSE:** License information for the project.

## ⚙️ Languages or Frameworks Used
<!--Remove the below lines and add yours -->
The script was created with Python3 and the built-in functions in it

## 🌟 How to run

1. Use the following command to install dependencies:

```bash
pip install -r requirements.txt
```

2. Set the following environment variables in the `.env` file. You can get these details by subscribing to - [Online Code Compiler](https://rapidapi.com/Glavier/api/online-code-compiler/)

```markdown

- `API_KEY`: Your API key for authentication.
- `HOST` : Host for the online compiler. [online-code-compiler.p.rapidapi.com]
- `LANGUAGE_LIST_URL` : API base URL to GET Languages. [https://online-code-compiler.p.rapidapi.com/v1/languages/]
- `COMPILE_CODE_URL` : API base URL to POST Request on online code compiler to execute the code. [https://online-code-compiler.p.rapidapi.com/v1/]

```

3. Execute the `list_languages.py` script to retrieve and display the list of available programming languages. The information is sourced from the `language_list.txt` file located in the `input` directory. Note that this file is pre-populated for reference, and user don't need to run this script.


```bash
python src/list_languages.py
```

4. Execute the `main.py` script to run user-specified code. The script will prompt the user for a programming language input. It will then perform the following steps:

1. Check if the specified language exists using the `get_language` API call.
2. Verify the presence of the `code.txt` file in the `input` directory, containing the code to be executed.
3. Check for the existence of the `input.txt` file in the `input` directory for providing input to the code.
4. If all checks pass, the script will execute the code and return the output, which will be recorded in `output.txt` in the `bin` directory.
5. Logs for all operations will be generated and recorded in `logfile.log` in the `bin` directory. <br><br>

```bash
python src/main.py
```


## 🤖 Author
[Indrajeet Mishra](https://github.com/thecoddiwompler)
3 changes: 3 additions & 0 deletions Code Compiler/bin/logfile.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2023-11-26 15:42:58,582 - INFO - Successfully fetched language data.
2023-11-26 15:43:06,089 - INFO - Successfully compiled the code.
2023-11-26 15:43:06,094 - INFO - Output written to bin/output.txt.
Empty file added Code Compiler/bin/output.txt
Empty file.
31 changes: 31 additions & 0 deletions Code Compiler/input/code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class FindGreatestNumber {
public static void main(String[] args) {
// Sample array
int[] numbers = {10, 5, 8, 20, 15};

// Find the greatest number
int greatestNumber = findGreatestNumber(numbers);

// Print the result
System.out.println("The greatest number is: " + greatestNumber);
}

// Method to find the greatest number in an array
public static int findGreatestNumber(int[] arr) {
if (arr == null || arr.length == 0) {
throw new IllegalArgumentException("Array is empty or null");
}

// Assume the first element is the greatest
int greatest = arr[0];

// Iterate through the array to find the greatest number
for (int i = 1; i < arr.length; i++) {
if (arr[i] > greatest) {
greatest = arr[i];
}
}

return greatest;
}
}
Empty file added Code Compiler/input/input.txt
Empty file.
77 changes: 77 additions & 0 deletions Code Compiler/input/language_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Ada
Algol 68
AWK
Bash Shell
BC
Befunge
Blockly
Brainf**k
C
C-99
CLISP
Clojure
COBOL
CoffeeScript
C++
C++ 14
C++ 17
C#
D
Dart
Elixir
Erlang
Factor
Falcon
Fantom
FASM
Forth
Fortran
FREE BASIC
F#
Assembler - GCC
GO Lang
Groovy
Hack
Haskell
Haxe
Icon
Intercal
Java
JBang
J Language
Kotlin
LOLCODE
Lua
OZ Mozart
Assembler - NASM
Nemerle
Nim
NodeJS
Objective C
Ocaml
Octave
Pascal
Perl
PHP
Picolisp
Pike
Prolog
Python 2
Python 3
R Language
Racket
Rhino JS
Ruby
RUST
Scala
Scheme
SmallTalk
SpiderMonkey
SQL
Swift
TCL
Unlambda
VB.Net
VERILOG
Whitespace
YaBasic
2 changes: 2 additions & 0 deletions Code Compiler/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
python-dotenv
Loading