Newer
Older
#!/.venv/bin/python
# ---- IMPORTS ---- #
import os
with open('data.json', 'r', encoding='utf-8') as file:
data = json.load(file)
file.close()
return data
def save(data):
with open('data.json', 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4)
file.close()
# Update unique techniques if user added new ones to the file.
get_techniques_stats(data)
# Reload data
load()
# Get project by ID
def get_project(data, id):
for n in range(0, get_project_count(data)):
if data["projects"][n]["project_id"] == id:
return data["projects"][n]
# Get project count
def get_project_count(data):
return len(data["projects"])
# Get techniques from project by ID
return get_project(data,id)['techniques']
# Gets all unique techniques from all projects ! COULD USE SOME FILTERING !
for n in range(0, get_project_count(data)):
tech = get_techniques(data, n)
for t in tech:
if t not in techniques:
techniques.append(t)
return techniques
def search():
pass
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
pass
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def new_project(data):
cls()
# ---- COLLECT INFO ----
project_title = input("Project title: ")
project_id = get_project_count(data)
techniques = input("\nWhat techniques does your project use? Write them out in the following format: python, java, html, css\n\nTechniques: ").replace(" ", "").lower().split(",")
description = input("Provide a description of your project: ")
url = input("Provide a link to the source code/demo of your project: ")
img_url = input("Image source (ex: logo.jpg): ")
# ---- COLLECT INFO ----
new_project = {
"title": project_title,
"project_id": project_id,
"techniques": techniques,
"desc": description,
"img_url": img_url,
"url": url
}
cls()
print("\n\nProject preview:\n")
pprint.pp(new_project)
option = int(input("\n1: Create\n2: Cancel\n> "))
if option == 1:
data['projects'].append(new_project)
save(data)
pass
def list_projects(data):
cls()
for project in data['projects']:
pprint.pp(project)
print("\n")
def edit_project(data, id):
while True:
if id > get_project_count(data) or id < 0:
print("Project ID doesn't exist.\n")
id = int(input("Project_ID to edit: "))
else:
cls()
project = get_project(data, id)
project.pop('project_id') # Project ID shouldn't be changed
print(f"Editing project: {project['title']}\n")
pprint.pp(project)
print("")
for field in enumerate(project):
print(f"{field[0]}: {field[1]}")
input("\nField to edit: ")
def delete_project(data):
pass
def menu(data):
menu_items = ["Add new project", "List projects", "Edit existing project", "Delete project", "Quit"]
menu_index = 0
while True:
cls()
titular = r"""
____ _ __ _ _
| _ \ ___ _ __ | |_ / _| ___ | | (_) ___
| |_) | / _ \ | '__| | __| | |_ / _ \ | | | | / _ \
| __/ | (_) | | | | |_ | _| | (_) | | | _ | | | (_) |
|_| \___/ |_| \__| |_| \___/ |_| (_) |_| \___/
"""
print(titular)
for i in menu_items:
print(f"{menu_items.index(i)+1}: {i}")
try:
option = int(input(f"> "))
if option == 1:
new_project(data)
elif option == 2:
list_projects(data)
input()
list_projects(data)
edit_project(data, int(input("Project_ID to edit: ")))
delete_project(data, int(input("Project_ID to delete: ")))
elif option == 5:
cls()
break
except:
print("")
if __name__ == "__main__":
main()