From 0ec30a968e39fadb68c688cbd40d6f7a002773ed Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 09:27:43 +0200 Subject: [PATCH 1/9] adds Dockerfile --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Dockerfile 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 . . From 9f9ad11c6e2d6152da2483018773818e4ec45851 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 09:28:14 +0200 Subject: [PATCH 2/9] .devcontainenr for VScode dev environment --- .devcontainer/devcontainer.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..b78a4c816 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// 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" + + // 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" +} From 3b1456b780cb4e1676af4eebc1f043d7db21dab5 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 09:31:37 +0200 Subject: [PATCH 3/9] solution for Hello --- README.md | 4 ++-- projects/Hello/my_hello.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 projects/Hello/my_hello.py diff --git a/README.md b/README.md index 238369a94..96ef047aa 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ If you are new to Github and open source then, visit [here.](https://towardsdata 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). @@ -93,7 +93,7 @@ If you are new to Github and open source then, visit [here.](https://towardsdata ## Contributors ✨ -SR No | Project | Author +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) 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") From 92e1264f4b8a104f581010a298d82c743a127665 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 09:53:48 +0200 Subject: [PATCH 4/9] changes to readme file --- .devcontainer/devcontainer.json | 9 ++- README.md | 98 --------------------------------- 2 files changed, 8 insertions(+), 99 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b78a4c816..46c794810 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,14 @@ "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. - "dockerFile": "../Dockerfile" + "dockerFile": "../Dockerfile", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ] + } + } // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], diff --git a/README.md b/README.md index 96ef047aa..d37e5042d 100644 --- a/README.md +++ b/README.md @@ -1,101 +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) From 09c572f1970f95a624ccd6e4ace6f7071e87df94 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 09:53:59 +0200 Subject: [PATCH 5/9] solution for json to csv converter --- projects/Convert_JSON_to_CSV/converter_toni.py | 14 ++++++++++++++ projects/Convert_JSON_to_CSV/output_toni.csv | 3 +++ 2 files changed, 17 insertions(+) create mode 100644 projects/Convert_JSON_to_CSV/converter_toni.py create mode 100644 projects/Convert_JSON_to_CSV/output_toni.csv 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..159a0989a --- /dev/null +++ b/projects/Convert_JSON_to_CSV/converter_toni.py @@ -0,0 +1,14 @@ +import json +import csv + +with open("input.json", "r") as f: + lines = f.readlines() + people = json.loads("".join(lines)) + +with open('output_toni.csv', 'w', newline='') as csvfile: + fieldnames = people[0].keys() + writer = csv.DictWriter(csvfile, fieldnames=fieldnames) + + writer.writeheader() + for person in people: + writer.writerow(person) 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 From 60aeb0f9f2791b0204ddacced7032166ea461872 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 09:57:26 +0200 Subject: [PATCH 6/9] refactors the code --- .../Convert_JSON_to_CSV/converter_toni.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/projects/Convert_JSON_to_CSV/converter_toni.py b/projects/Convert_JSON_to_CSV/converter_toni.py index 159a0989a..3c006c287 100644 --- a/projects/Convert_JSON_to_CSV/converter_toni.py +++ b/projects/Convert_JSON_to_CSV/converter_toni.py @@ -1,14 +1,22 @@ import json import csv -with open("input.json", "r") as f: - lines = f.readlines() - people = json.loads("".join(lines)) -with open('output_toni.csv', 'w', newline='') as csvfile: - fieldnames = people[0].keys() - writer = csv.DictWriter(csvfile, fieldnames=fieldnames) +def convert_json_to_csv(json_filename, csv_filename): + with open("input.json", "r") as f: + lines = f.readlines() + people = json.loads("".join(lines)) - writer.writeheader() - for person in people: - writer.writerow(person) + with open('output_toni.csv', 'w', newline='') as csvfile: + fieldnames = people[0].keys() + writer = csv.DictWriter(csvfile, 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) From 591c97355aadbdc8afbc7762e069f26c836a358a Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 10:10:40 +0200 Subject: [PATCH 7/9] refactor --- .../Convert_JSON_to_CSV/converter_toni.py | 17 +++++++------- projects/Convert_JSON_to_CSV/input.json | 22 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/projects/Convert_JSON_to_CSV/converter_toni.py b/projects/Convert_JSON_to_CSV/converter_toni.py index 3c006c287..c1b69fe51 100644 --- a/projects/Convert_JSON_to_CSV/converter_toni.py +++ b/projects/Convert_JSON_to_CSV/converter_toni.py @@ -3,20 +3,19 @@ def convert_json_to_csv(json_filename, csv_filename): - with open("input.json", "r") as f: - lines = f.readlines() - people = json.loads("".join(lines)) + with open(json_filename, "r") as f: + json_file = f.read() + people = json.loads(json_file) - with open('output_toni.csv', 'w', newline='') as csvfile: + with open(csv_filename, "w") as f: fieldnames = people[0].keys() - writer = csv.DictWriter(csvfile, fieldnames=fieldnames) - + 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' +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" + } +] From 7d6256f2e163b5dcafd28f47a7f63ca908872f20 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 10:29:03 +0200 Subject: [PATCH 8/9] solution to the random password generator --- README.md | 1 - .../toni_random_password_generator.py | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 projects/Random_password_generator/toni_random_password_generator.py diff --git a/README.md b/README.md index d37e5042d..63812c496 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -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/Random_password_generator/toni_random_password_generator.py b/projects/Random_password_generator/toni_random_password_generator.py new file mode 100644 index 000000000..ad2a735ad --- /dev/null +++ b/projects/Random_password_generator/toni_random_password_generator.py @@ -0,0 +1,28 @@ +import random +import string + + +def generate_random_number(): + try: + password_length = int(input("Length of the password: ")) + except ValueError as err: + print(f"You need to type numbers: {err}") + return + + res = [] + while len(res) < password_length: + if random.randint(0, 1): + idx = random.randint(0, len(string.ascii_letters)) + res.append(string.ascii_letters[idx]) + else: + if random.randint(0, 1): + idx = random.randint(0, len(string.digits)) + res.append(string.digits[idx]) + else: + idx = random.randint(0, len(string.punctuation)) + res.append(string.punctuation[idx]) + return "".join(res) + + +if __name__ == "__main__": + print(generate_random_number()) From a384c4bb3a0e02037261ff5f6c4b9d23298d71af Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 18 Sep 2022 10:40:03 +0200 Subject: [PATCH 9/9] refactor --- .../toni_random_password_generator.py | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/projects/Random_password_generator/toni_random_password_generator.py b/projects/Random_password_generator/toni_random_password_generator.py index ad2a735ad..35869679f 100644 --- a/projects/Random_password_generator/toni_random_password_generator.py +++ b/projects/Random_password_generator/toni_random_password_generator.py @@ -1,28 +1,39 @@ -import random import string +import random -def generate_random_number(): - try: - password_length = int(input("Length of the password: ")) - except ValueError as err: - print(f"You need to type numbers: {err}") - return +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): - idx = random.randint(0, len(string.ascii_letters)) - res.append(string.ascii_letters[idx]) + res.append(random_char()) else: if random.randint(0, 1): - idx = random.randint(0, len(string.digits)) - res.append(string.digits[idx]) + res.append(random_punctuation()) else: - idx = random.randint(0, len(string.punctuation)) - res.append(string.punctuation[idx]) + res.append(random_digit()) return "".join(res) if __name__ == "__main__": - print(generate_random_number()) + 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))