From 2aafca6db449c27ed2fcb85478c164fbd9769f09 Mon Sep 17 00:00:00 2001
From: olima957 <olima957@student.liu.se>
Date: Tue, 22 Oct 2024 21:40:42 +0200
Subject: [PATCH] TEST2

---
 MyPortfolio/data.py           | 285 ----------------------------------
 MyPortfolio/myFlaskProject.py |  59 -------
 2 files changed, 344 deletions(-)
 delete mode 100644 MyPortfolio/data.py
 delete mode 100644 MyPortfolio/myFlaskProject.py

diff --git a/MyPortfolio/data.py b/MyPortfolio/data.py
deleted file mode 100644
index 318064d..0000000
--- a/MyPortfolio/data.py
+++ /dev/null
@@ -1,285 +0,0 @@
-#!/.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
-import unicodedata
-from operator import itemgetter
-# ---- IMPORTS ---- #
-
-
-def load(filename):
-    try:
-        with open(filename, 'r', encoding='utf-8') as file:
-            data = json.load(file)
-
-        file.close()
-        return data
-    except:
-        return None
-
-
-def save(data):
-    with open('data.json', 'w', encoding='utf-8') as file:
-        json.dump(data, file, ensure_ascii=False, indent=4)
-
-    file.close()
-
-    # Reload data
-    load()
-
-
-# Get project count
-def get_project_count(data):
-    return len(data)
-
-
-# Get project by ID
-def get_project(data, id):
-    for n in range(0, get_project_count(data)):
-        if data[n]['project_id'] == id:
-            return data[n]
-
-
-# Get all unique techniques from project
-def get_techniques(data):
-    techniques = []
-    for project in data:
-        for tech in project['techniques_used']:
-            if tech not in techniques:
-                techniques.append(tech)
-
-    techniques.sort()
-
-    return techniques
-
-
-# Gets all unique techniques from all projects ! COULD USE SOME FILTERING !
-def get_technique_stats(data):
-    technique_list = get_techniques(data)
-    technique_stats = {}
-    current_techniques = []
-
-    for technique in technique_list:
-        for project in data:
-            if technique in project['techniques_used']:
-                current_techniques.append({'id': project['project_id'], 'name': project['project_name']})
-
-        technique_stats.update({technique: current_techniques.copy()})
-        current_techniques.clear()
-
-    return technique_stats
-
-
-# Fetches and sorts projects matching criteria from the specified list.
-def search(data, sort_by='start_date', sort_order='desc', techniques=None, search=None, search_fields=None):
-    if isinstance(search, str):
-        search = search.lower()
-
-    results = []
-    # get it
-    for project in data:
-        results.append(project)
-
-    # sort it
-    results = sorted(results, key=itemgetter(sort_by))
-
-    # order it
-    if sort_order == 'desc':
-        results.reverse()
-
-    # filter it (by techniques)
-    if techniques is not None:
-        for technique in get_techniques(data):
-            for project in results:
-                if all(n in project['techniques_used'] for n in techniques):
-                    pass
-                else:
-                    results.pop(results.index(project))
-
-    # search for it
-    if search is not None:
-        search_results = []
-
-        for project in results:
-            if search_fields is not None and search_fields != "" and search != "" and search_fields != ['None']:
-                for field in search_fields:
-                    substring = project[field]
-                    # Check type before calling lower()
-                    if isinstance(substring, str):
-                        substring = substring.lower()
-                        if substring.find(search) != -1:
-                            search_results.append(project)
-                            break
-                    elif isinstance(substring, int):
-                        if str(substring).find(search) != -1:
-                            search_results.append(project)
-                            break
-                    elif isinstance(substring, list):
-                        for subsubstring in substring:
-                            if isinstance(subsubstring, str):
-                                if subsubstring.lower().find(search) != -1:
-                                    search_results.append(project)
-                                    break
-                            elif isinstance(subsubstring, int):
-                                if str(subsubstring).find(search) != -1:
-                                    search_results.append(project)
-                                    break
-
-            elif search_fields == "":
-                results.clear()
-                break
-
-            else:
-                for substring in list(project.values()):
-                    # Check type before calling lower()
-                    if isinstance(substring, str):
-                        if substring.lower().find(search) != -1:
-                            search_results.append(project)
-                            break
-                    elif isinstance(substring, int):
-                        if str(substring).find(search) != -1:
-                            search_results.append(project)
-                            break
-                    elif isinstance(substring, list):
-                        for subsubstring in substring:
-                            if isinstance(subsubstring, str):
-                                if subsubstring.lower().find(search) != -1:
-                                    search_results.append(project)
-                                    break
-                            elif isinstance(subsubstring, int):
-                                if str(subsubstring).find(search) != -1:
-                                    search_results.append(project)
-                                    break
-
-        results = search_results
-
-    return results
-
-
-def cls():
-    os.system('cls' if os.name == 'nt' else 'clear')
-    pass
-
-
-def new_project(data):
-    cls()
-
-    # ---- COLLECT INFO ----
-    project_title = input("Project title: ")
-    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 = {
-        "project_name": project_title,
-        "project_id": project_id,
-        "used_techniques": techniques,
-        "long_description": 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.append(new_project)
-        save(data)
-
-        pass
-
-
-def list_projects(data):
-    cls()
-    for project in data:
-        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()
-            elif option == 3:
-                list_projects(data)
-                edit_project(data, int(input("Project_ID to edit: ")))
-            elif option == 4:
-                delete_project(data, int(input("Project_ID to delete: ")))
-            elif option == 5:
-                cls()
-                break
-        except:
-            print("")
-
-
-def main():
-    data = load('MyPortfolio/data.json')
-
-
-if __name__ == "__main__":
-    main()
diff --git a/MyPortfolio/myFlaskProject.py b/MyPortfolio/myFlaskProject.py
deleted file mode 100644
index d8dc77f..0000000
--- a/MyPortfolio/myFlaskProject.py
+++ /dev/null
@@ -1,59 +0,0 @@
-from flask import Flask, render_template, request
-from data import *
-
-app = Flask(__name__, template_folder='./templates')
-
-data = load('data.json')
-
-@app.route("/")
-def index():
-    return render_template('index.html')
-
-@app.route("/list", methods=['GET', 'POST'])
-def list():
-    search_query = request.form.get('search', '')
-    sort_by = request.form.get('sort_by', 'start_date')
-    sort_order = request.form.get('sort_order', 'desc')
-
-    filtered_projects = search(load('data.json'), sort_by=sort_by, sort_order=sort_order, search=search_query)
-    return render_template('list.html', 
-                           projects=filtered_projects, 
-                           search_query=search_query, 
-                           sort_by=sort_by, 
-                           sort_order=sort_order)
-
-@app.route("/project/<int:project_id>")
-def project_details(project_id):
-    project = get_project(load('data.json'), project_id)
-    if project:
-        return render_template('project_details.html', project=project)
-    else:
-        return "404: Project not found", 404
-    
-@app.route("/techniques", methods=['GET', 'POST'])
-def techniques():
-
-    techniques = get_technique_stats(load('data.json'))
-
-    search_query = request.form.get('search', '')
-    sort_by = request.form.get('sort_by', 'start_date')
-    sort_order = request.form.get('sort_order', 'desc')
-    search_field = request.form.getlist('search_field', None)
-    techniques_search = request.form.getlist('technique')
-
-    print(f"Searching for: ", search_query)
-    print(search_field)
-
-    filtered_projects = search(load('data.json'), sort_by=sort_by, sort_order=sort_order, techniques=techniques_search, search=search_query, search_fields=search_field)
-
-    return render_template('techniques.html',
-                           techniques = techniques,
-                           techniques_search = techniques_search,
-                           projects=filtered_projects, 
-                           search_query=search_query, 
-                           sort_by=sort_by, 
-                           sort_order=sort_order,
-                           search_field=search_field)
-
-if __name__ == "__main__":
-    app.run(debug=True)
-- 
GitLab