diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..46c794810 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-dockerfile +{ + "name": "Existing Dockerfile", + + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerFile": "../Dockerfile", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ] + } + } + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created - for example installing curl. + // "postCreateCommand": "apt-get update && apt-get install -y curl", + + // Uncomment when using a ptrace-based debugger like C++, Go, and Rust + // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. + // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], + + // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "vscode" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a5d9e25d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.10.7-bullseye + +RUN pip install ipython + +COPY . . diff --git a/README.md b/README.md index 238369a94..63812c496 100644 --- a/README.md +++ b/README.md @@ -1,102 +1,3 @@ - -[![forthebadge](https://forthebadge.com/images/badges/built-by-developers.svg)](https://forthebadge.com) -[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com) -[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](https://forthebadge.com) -[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com) - -# Python-Mini-Projects - -[![All Contributors](https://img.shields.io/github/contributors/Python-World/python-mini-projects)](#contributors-) -![Issues](https://img.shields.io/github/issues/Python-World/python-mini-projects) -![Pull Requests](https://img.shields.io/github/issues-pr/Python-World/python-mini-projects?) -![Forks](https://img.shields.io/github/forks/Python-World/python-mini-projects) -![Stars](https://img.shields.io/github/stars/Python-World/python-mini-projects) -![License](https://img.shields.io/github/license/Python-World/python-mini-projects) - -A collection of simple python mini projects to enhance your Python skills. - -If you want to learn about python, visit [here.](https://github.com/Python-World/Py-Resources) - -If you are new to Github and open source then, visit [here.](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6) - -## Steps To Follow - -- Select an issue and ask to be _assigned_ to it. -- Check existing scripts in the [projects](/projects/) directory. -- **Star** this repository. -- On the [python-mini-projects](https://github.com/Python-World/python-mini-projects) repo page, click the **Fork** button. -
-- **Clone** your forked repository to your local machine. This button will show you the URL to run. -
- - For example, run this command inside your terminal: - - ```bash - git clone https://github.com//python-mini-projects.git - ``` - - **Replace \!** - - Learn more about [forking](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) and [cloning a repo](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository). -- Before you make any changes, [keep your fork in sync](https://www.freecodecamp.org/news/how-to-sync-your-fork-with-the-original-git-repository/) to avoid merge conflicts: - - ```bash - git remote add upstream https://github.com/Python-World/python-mini-projects.git - git fetch upstream - git pull upstream master - git push - ``` - - Alternatively, GitHub also provides syncing now - click "Fetch upstream" at the top of your repo below "Code" button. - -- If you run into a **merge conflict**, you have to resolve the conflict. There are a lot of guides online, or you can try this one by [opensource.com](https://opensource.com/article/20/4/git-merge-conflict). - -- Checkout to development branch (*name your branch according to the issue name*). - - ```bash - git checkout -b - ``` - -- Create a folder in - [projects directory](https://github.com/Python-World/python-mini-projects/tree/master/projects) - according to issue name. -- Write your code and add to the respective folder in the projects directory, locally. -- Don't forget to add a `README.md` in your folder, according to the - [README_TEMPLATE.](https://github.com/Python-World/python-mini-projects/blob/master/README_TEMPLATE.md) -- Add the changes with `git add`, `git commit` ([write a good commit message](https://chris.beams.io/posts/git-commit/), if possible): - - ```bash - git add -A - git commit -m "" - ``` - -- Push the code _to your repository_. - - ```bash - git push origin - ``` - -- Go to the GitHub page of _your fork_, and **make a pull request**: - - ![pull request image](https://help.github.com/assets/images/help/pull_requests/choose-base-and-compare-branches.png) - - Read more about pull requests on the [GitHub help pages](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request). -- Now wait, until one of us *reviews your Pull Request*! If there are any conflicts, you will get a notification. - -## README Template for scripts - -[README Template](https://github.com/Python-World/python-mini-projects/blob/master/README_TEMPLATE.md) - -## Connect On Social media - -[Join WhatsApp group](https://chat.whatsapp.com/GlLTqQSbocLC23ntKU15O9) - -## Contributors ✨ - -SR No | Project | Author ---- | --- | --- -1 | [Hello World](https://github.com/Python-World/python-mini-projects/tree/master/projects/Hello) | [Ravi Chavare](https://github.com/chavarera) -2 | [JSON to CSV](https://github.com/Python-World/python-mini-projects/tree/master/projects/Convert_JSON_to_CSV)| [Murilo Pagliuso](https://github.com/DarkCeptor44) 3 | [Random Password Generator](https://github.com/Python-World/python-mini-projects/tree/master/projects/Random_password_generator) | [Mitesh](https://github.com/Mitesh2499) 4 | [Instagram Profile Info](https://github.com/Python-World/python-mini-projects/tree/master/projects/Instagram_profile) | [Ravi Chavare](https://github.com/chavarera) 5 | [Search string in Files](https://github.com/Python-World/python-mini-projects/tree/master/projects/String_search_from_multiple_files) | [Mitesh](https://github.com/Mitesh2499) diff --git a/projects/Convert_JSON_to_CSV/converter_toni.py b/projects/Convert_JSON_to_CSV/converter_toni.py new file mode 100644 index 000000000..c1b69fe51 --- /dev/null +++ b/projects/Convert_JSON_to_CSV/converter_toni.py @@ -0,0 +1,21 @@ +import json +import csv + + +def convert_json_to_csv(json_filename, csv_filename): + with open(json_filename, "r") as f: + json_file = f.read() + people = json.loads(json_file) + + with open(csv_filename, "w") as f: + fieldnames = people[0].keys() + writer = csv.DictWriter(f, fieldnames=fieldnames) + writer.writeheader() + for person in people: + writer.writerow(person) + + +if __name__ == "__main__": + json_filename = "input.json" + csv_filename = "output_toni.csv" + convert_json_to_csv(json_filename, csv_filename) diff --git a/projects/Convert_JSON_to_CSV/input.json b/projects/Convert_JSON_to_CSV/input.json index c3e66f1dd..c0d5bd7ed 100644 --- a/projects/Convert_JSON_to_CSV/input.json +++ b/projects/Convert_JSON_to_CSV/input.json @@ -1,12 +1,12 @@ [ - { - "Name": "Akash", - "age": 26, - "birthyear": "1994" - }, - { - "Name": "Abhay", - "age": 34, - "birthyear": "1986" - } -] \ No newline at end of file + { + "Name": "Akash", + "age": 26, + "birthyear": "1994" + }, + { + "Name": "Abhay", + "age": 34, + "birthyear": "1986" + } +] diff --git a/projects/Convert_JSON_to_CSV/output_toni.csv b/projects/Convert_JSON_to_CSV/output_toni.csv new file mode 100644 index 000000000..bcd8146bf --- /dev/null +++ b/projects/Convert_JSON_to_CSV/output_toni.csv @@ -0,0 +1,3 @@ +Name,age,birthyear +Akash,26,1994 +Abhay,34,1986 diff --git a/projects/Hello/my_hello.py b/projects/Hello/my_hello.py new file mode 100644 index 000000000..57dbdc966 --- /dev/null +++ b/projects/Hello/my_hello.py @@ -0,0 +1,2 @@ + +print("Hello Python World") diff --git a/projects/Random_password_generator/toni_random_password_generator.py b/projects/Random_password_generator/toni_random_password_generator.py new file mode 100644 index 000000000..35869679f --- /dev/null +++ b/projects/Random_password_generator/toni_random_password_generator.py @@ -0,0 +1,39 @@ +import string +import random + + +def random_char() -> string: + idx = random.randint(0, len(string.ascii_letters)-1) + return string.ascii_letters[idx] + + +def random_punctuation() -> string: + idx = random.randint(0, len(string.punctuation)-1) + return string.punctuation[idx] + + +def random_digit() -> string: + idx = random.randint(0, len(string.digits)-1) + return string.digits[idx] + + +def generate_random_int(password_length: int) -> string: + res = [] + while len(res) < password_length: + if random.randint(0, 1): + res.append(random_char()) + else: + if random.randint(0, 1): + res.append(random_punctuation()) + else: + res.append(random_digit()) + return "".join(res) + + +if __name__ == "__main__": + try: + password_length = int(input("Password length: ")) + except ValueError as e: + print(f"Input needs to be an integer: error: {e}") + + print(generate_random_int(password_length))