Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from avinashkranjan:master #12

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

Merged
pull merged 6 commits into Uncodedtech:master from avinashkranjan:master
May 11, 2021
Merged
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
48 changes: 40 additions & 8 deletions .github/pull_request_template.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ Please include a summary of the change and which issue is fixed. List any depend

## Fixes #(issue_no)

Replace `issue_no` with the issue number which is fixed in this PR

## Have you read the [Contributing Guidelines on Pull Requests](https://github.com/avinashkranjan/Amazing-Python-Scripts/blob/master/CONTRIBUTING.md)?

- [ ] Yes
- [ ] No
<!-- Replace `issue_no` with the issue number which is fixed in this PR -->

## Type of change

Expand All @@ -34,5 +29,42 @@ _Please delete options that are not relevant._
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have created a helpful and easy to understand `README.md`
- [ ] My documentation follows [`Template for README.md`](https://github.com/avinashkranjan/Amazing-Python-Scripts/blob/master/Template%20for%20README.md)
- [ ] My changes generate no new warnings
- [ ] I have added tests/screenshots(if any) that prove my fix is effective or that my feature works.
- [ ] I have added the project meta data in the PR template.
- [ ] I have created the ``requirements.txt`` file if needed.

## Project Metadata

`` If there is no-file/nothing to fill the below fields with, then type: none ``

`` Example: `` If no requirements.txt needed/present, then type none in ``Requirments``.

Category:
- [ ] Calculators
- [ ] AI/ML
- [ ] Scrappers
- [ ] Social_Media
- [ ] PDF
- [ ] Image_Processing
- [ ] Video_Processing
- [ ] Games
- [ ] Networking
- [ ] OS_Utilities
- [ ] Automation
- [ ] Cryptography
- [ ] Computer_Vision
- [ ] Fun
- [ ] Others

Title: \<write script title here\>

Folder: \<type the folder name that contains your script\>

Requirments: \<type the name of text file containing the required to install python packages, type None if no file required\>

Script: \<Enter the name of the ``.py`` file (The main entry point of the program)\>

Arguments: \<enter any arguments that the script needs but `-` separeted like: h-c-m\>

Contributor: \<Enter your Github handle/username without url\>

Description: \<Enter a one line description that describes your script. Also, explain the arguments usage here\>
119 changes: 119 additions & 0 deletions .github/scripts/Update_Database.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from github import Github
import json
import sys
import re

# Regex Patterns
category = r"- \[x\] (.+)"
name = r"Title: (.+)"
path = r"Folder: (.+)"
requirments_path = r"Requirments: (.+)"
entry = r"Script: (.+)"
arguments = r"Arguments: (.+)"
contributor = r"Contributor: (.+)"
description = r"Description: (.+)"


def add_script(category, name, path, entry, arguments, requirments_path, contributor, description, pa_token):
""" Add a Contributor script to database """
new_data = {category: {name: [path, entry, arguments, requirments_path, contributor, description]}}
data_store = read_data()

try:
# If category doesn't exist try will fail and except will ask to add a new category with the project
if data_store[category]: # Check for existing category or a new one
data_store[category].update(new_data[category]) # Add script
except:
data_store.update(new_data) # Add new category

# <----- This part is to avoid a single/double quotes error when trying to update the database with PyGithub ----->
with open("./Master Script/datastore.json", "w") as file:
json.dump(data_store, file)
print("Script added to database, pushing changes to repo...")

with open("./Master Script/datastore.json", "r") as file:
data_store = file.readlines()[0]

# <----- Github Login & Database Update ----->
git = Github(pa_token)
user_object = git.get_user()
print("[+] PyGithub Login Success!")

repo = git.get_repo("avinashkranjan/Amazing-Python-Scripts")
datastore_fileMaster = repo.get_contents("./Master Script/datastore.json", ref="master")
datastore_fileWebsite = repo.get_contents("./datastore.json", ref="gh-pages")

repo.update_file(datastore_fileMaster.path, "Updated datastore.json", data_store, datastore_fileMaster.sha, branch="master")
repo.update_file("./datastore.json", "Updated datastore.json", data_store, datastore_fileWebsite.sha, branch="gh-pages")
print("[+] Database Updated")


def read_data():
""" Loads datastore.json """
with open("./Master Script/datastore.json", "r") as file:
data = json.load(file)
return data


def extract_from_pr_body(pr_body, pa_token):
""" Manipulates the provided PR body and extracts the required information """
pr_body = pr_body.split("\n")
for element in pr_body:
pr_body[pr_body.index(element)] = element.rstrip("\r")

# A special case for contributors in gh-pages branch and other dependency PRs
try:
pr_body = pr_body[pr_body.index("## Project Metadata"):]
except:
sys.exit()

category_list = []
for text in pr_body:
# <----- Validate Category ----->
cat = re.match(category, text)
if cat is not None:
category_list.append(cat[1])
# <----- Validate Title ----->
if re.match(name, text) is not None:
title = re.match(name, text)[1]
# <----- Validate Folder ----->
if re.match(path, text) is not None:
folder = re.match(path, text)[1]
# <----- Validate requirments.txt ----->
if re.match(requirments_path, text) is not None:
requirements = re.match(requirments_path, text)[1]
# <----- Validate Script.py ----->
if re.match(entry, text) is not None:
script = re.match(entry, text)[1]
# <----- Validate Arguments ----->
if re.match(arguments, text) is not None:
argument = re.match(arguments, text)[1]
# <----- Validate Contribute ----->
if re.match(contributor, text) is not None:
user = re.match(contributor, text)[1]
# <----- Validate Description ----->
if re.match(description, text) is not None:
desc = re.match(description, text)[1]

# For GitHub Actions logging
print("<----- MetaData ----->")
print("Categories:", category_list)
print("Title:", title)
print("Path:", folder)
print("Requirements:", requirements)
print("Entry:", script)
print("Arguments:",argument)
print("Contributer:", user)
print("Description:", desc)
print("<----- ----- ----->")

# The loop is for scripts that will be added to multiple categories.
for cat in category_list:
add_script(cat, title, folder, script, argument, requirements, user, desc, pa_token)


# Start Checkpoint
if __name__ == "__main__":
# Get PR body and pass pa_token
data = sys.argv[1]
extract_from_pr_body(data, sys.argv[2])
30 changes: 30 additions & 0 deletions .github/workflows/database_auto_updater.yml
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python package

on:
pull_request:
# Will trigger on closed PRs
types: [closed]

jobs:
extract_and_update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.6
# Checks if PR is merged (subflag)
if: ${{ github.event.pull_request.merged == true }}
uses: actions/setup-python@v2
with:
python-version: '3.6'

- name: Run script
# Checks if PR is merged (subflag)
if: ${{ github.event.pull_request.merged == true }}
run: |
python -m pip install --upgrade pip
pip install PyGithub
python ./.github/scripts/Update_Database.py "$body" "$token"
env:
body: ${{ github.event.pull_request.body }}
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Master Script/datastore.json
View file Open in desktop

Large diffs are not rendered by default.

View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
parser = OptionParser()
parser.add_option("-a", "--add", action="store_true", dest="add", help="Goes straight to the add script phase")


# The database is automatically updated after the PR is merged.
# ONLY Use this function if you were asked to, to manually add projects to the database.
def add_script():
""" Add a Contributor script through a series of inputs """
print("Double check inputs before pressing enter. If one input is incorrect press CTRL-C and re-run the script")
Expand Down

AltStyle によって変換されたページ (->オリジナル) /