Skip to content
Snippets Groups Projects
Commit b8379d69 authored by Oliwer Mattsson's avatar Oliwer Mattsson :headphones:
Browse files

Uppdaterade search funktionen.

parent a2fb8428
No related branches found
No related tags found
No related merge requests found
#!/.venv/bin/python
# TODO
# Gör project_id dynamisk så att den uppdateras efter borttagning/addering av projekt.
# ---- IMPORTS ---- #
import os
import json
import pprint
import re
from operator import itemgetter
# ---- IMPORTS ---- #
def load():
with open('data.json', 'r', encoding='utf-8') as file:
data = json.load(file)
file.close()
return data
try:
with open('data.json', 'r', encoding='utf-8') as file:
data = json.load(file)
file.close()
return data
except:
return None
......@@ -49,8 +57,7 @@ def get_project_count(data):
# Get techniques from project by ID
def get_techniques(data, id):
return get_project(data,id)['techniques']
return get_project(data,id)['techniques'].sort()
# Gets all unique techniques from all projects ! COULD USE SOME FILTERING !
......@@ -67,8 +74,25 @@ def get_techniques_stats(data):
return techniques
# Fetches and sorts projects matching criteria from the specified list.
def search(data, sort_by='project_id', sort_order='desc', techniques=None, search=None, search_field=None):
results = []
# get it
for project in data['projects']:
results.append(project)
# sort it
sorted_list = sorted(results, key=itemgetter(sort_by))
# order it
if sort_order == 'asc': results.reverse()
def search():
# filter it (by techniques)
for project in sorted_list:
pass
pprint.pp(sorted_list)
pass
......@@ -85,15 +109,18 @@ def new_project(data):
# ---- COLLECT INFO ----
project_title = input("Project title: ")
project_id = get_project_count(data)
project_id = get_project_count(data)+1
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 ----
# lexicographical order sort aka alphabetical
techniques.sort()
new_project = {
"title": project_title,
"project_title": project_title,
"project_id": project_id,
"techniques": techniques,
"desc": description,
......@@ -115,6 +142,7 @@ def new_project(data):
save(data)
pass
def list_projects(data):
......@@ -151,7 +179,6 @@ def edit_project(data, id):
def delete_project(data):
pass
......@@ -205,11 +232,9 @@ def menu(data):
def main():
data = load()
menu(data)
search(data, 'project_id', 'desc')
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment