Amazing-Python-Scripts
98 строк · 3.3 Кб
1from optparse import OptionParser2import json3import sys4import os5
6usage = """7<Script> [Options]
8
9[Options]
10-h, --help Show this help message and exit.
11-a, --add Goes straight to the add script phase
12"""
13# Load args
14parser = OptionParser()15parser.add_option("-a", "--add", action="store_true", dest="add",16help="Goes straight to the add script phase")17
18
19# The database is automatically updated after the PR is merged.
20# ONLY Use this function if you were asked to, to manually add projects to the database.
21def add_script():22""" Add a Contributor script through a series of inputs """23print("Double check inputs before pressing enter. If one input is incorrect press CTRL-C and re-run the script")24category = input("Enter What category does your script belongs to > ")25name = input("Enter script title > ")26path = input("Enter folder name that contains your script > ")27requirments_path = input("Enter requirements.txt path (else none) > ")28entry = input("Enter name of the file that runs the script > ")29arguments = input(30"Enter scripts arugments if needed ( '-' seperated + no whitespaces) (else none) > ")31contributor = input("Enter your GitHub username > ")32description = input("Enter a description for your script > ")33
34new_data = {category: {35name: [path, entry, arguments, requirments_path, contributor, description]}}36data_store = read_data()37
38try:39# If category doesn't exist try will fail and except will ask to add a new category with the project40# Check for existing category or a new one41if data_store[category]:42data_store[category].update(43new_data[category]) # Add script44except:45sure = "Y"46sure = input("A new category is about to be added. You sure? Y/n > ")47if sure.lower() == "y" or sure == "":48# Add new category49data_store.update(new_data)50else:51print(52"Data wasn't added please re-run the script and add the correct inputs.")53sys.exit(1)54
55with open("datastore.json", "w") as file:56json.dump(data_store, file)57print("Script added to database")58
59
60def read_data():61""" Loads datastore.json """62with open("datastore.json", "r") as file:63data = json.load(file)64return data65
66
67def check_data():68""" Validates that all projects exists in the datastore and prints out those are not in the DB """69data = read_data()70paths = []71for category in data:72for project in data[category]:73paths.append(data[category][project][0])74i = 075repo_dir = os.listdir("../")76ignore = [".deepsource.toml", ".git", ".github", ".gitignore",77"CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "LICENSE",78"README.md", "SCRIPTS.md", "script_updater.py",79"Template for README.md", "Master Script", ]80for element in repo_dir:81if (not element in paths) and (not element in ignore):82print(element)83i += 184
85print(f"Total of {i} non-added projects.")86
87
88# Start checkpoint
89if __name__ == "__main__":90(options, args) = parser.parse_args()91
92# Inputs93add = options.add94
95if add:96add_script()97# add_script()98check_data()99