Skip to content
Snippets Groups Projects
Commit 775d197a authored by Ankan's avatar Ankan
Browse files

gjorde klart projects men behövde ändra data.py

parent 6f40bd56
No related branches found
No related tags found
No related merge requests found
Showing
with 635 additions and 92 deletions
File added
<#
.Synopsis
Activate a Python virtual environment for the current PowerShell session.
.Description
Pushes the python executable for a virtual environment to the front of the
$Env:PATH environment variable and sets the prompt to signify that you are
in a Python virtual environment. Makes use of the command line switches as
well as the `pyvenv.cfg` file values present in the virtual environment.
.Parameter VenvDir
Path to the directory that contains the virtual environment to activate. The
default value for this is the parent of the directory that the Activate.ps1
script is located within.
.Parameter Prompt
The prompt prefix to display when this virtual environment is activated. By
default, this prompt is the name of the virtual environment folder (VenvDir)
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
.Example
Activate.ps1
Activates the Python virtual environment that contains the Activate.ps1 script.
.Example
Activate.ps1 -Verbose
Activates the Python virtual environment that contains the Activate.ps1 script,
and shows extra information about the activation as it executes.
.Example
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
Activates the Python virtual environment located in the specified location.
.Example
Activate.ps1 -Prompt "MyPython"
Activates the Python virtual environment that contains the Activate.ps1 script,
and prefixes the current prompt with the specified string (surrounded in
parentheses) while the virtual environment is active.
.Notes
On Windows, it may be required to enable this Activate.ps1 script by setting the
execution policy for the user. You can do this by issuing the following PowerShell
command:
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
For more information on Execution Policies:
https://go.microsoft.com/fwlink/?LinkID=135170
#>
Param(
[Parameter(Mandatory = $false)]
[String]
$VenvDir,
[Parameter(Mandatory = $false)]
[String]
$Prompt
)
<# Function declarations --------------------------------------------------- #>
<#
.Synopsis
Remove all shell session elements added by the Activate script, including the
addition of the virtual environment's Python executable from the beginning of
the PATH variable.
.Parameter NonDestructive
If present, do not remove this function from the global namespace for the
session.
#>
function global:deactivate ([switch]$NonDestructive) {
# Revert to original values
# The prior prompt:
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
}
# The prior PYTHONHOME:
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
}
# The prior PATH:
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
}
# Just remove the VIRTUAL_ENV altogether:
if (Test-Path -Path Env:VIRTUAL_ENV) {
Remove-Item -Path env:VIRTUAL_ENV
}
# Just remove VIRTUAL_ENV_PROMPT altogether.
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
}
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
}
# Leave deactivate function in the global namespace if requested:
if (-not $NonDestructive) {
Remove-Item -Path function:deactivate
}
}
<#
.Description
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
given folder, and returns them in a map.
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
two strings separated by `=` (with any amount of whitespace surrounding the =)
then it is considered a `key = value` line. The left hand string is the key,
the right hand is the value.
If the value starts with a `'` or a `"` then the first and last character is
stripped from the value before being captured.
.Parameter ConfigDir
Path to the directory that contains the `pyvenv.cfg` file.
#>
function Get-PyVenvConfig(
[String]
$ConfigDir
) {
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
# An empty map will be returned if no config file is found.
$pyvenvConfig = @{ }
if ($pyvenvConfigPath) {
Write-Verbose "File exists, parse `key = value` lines"
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
$pyvenvConfigContent | ForEach-Object {
$keyval = $PSItem -split "\s*=\s*", 2
if ($keyval[0] -and $keyval[1]) {
$val = $keyval[1]
# Remove extraneous quotations around a string value.
if ("'""".Contains($val.Substring(0, 1))) {
$val = $val.Substring(1, $val.Length - 2)
}
$pyvenvConfig[$keyval[0]] = $val
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
}
}
}
return $pyvenvConfig
}
<# Begin Activate script --------------------------------------------------- #>
# Determine the containing directory of this script
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$VenvExecDir = Get-Item -Path $VenvExecPath
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
# Set values required in priority: CmdLine, ConfigFile, Default
# First, get the location of the virtual environment, it might not be
# VenvExecDir if specified on the command line.
if ($VenvDir) {
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
}
else {
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
Write-Verbose "VenvDir=$VenvDir"
}
# Next, read the `pyvenv.cfg` file to determine any required value such
# as `prompt`.
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
# Next, set the prompt from the command line, or the config file, or
# just use the name of the virtual environment folder.
if ($Prompt) {
Write-Verbose "Prompt specified as argument, using '$Prompt'"
}
else {
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
$Prompt = $pyvenvCfg['prompt'];
}
else {
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
$Prompt = Split-Path -Path $venvDir -Leaf
}
}
Write-Verbose "Prompt = '$Prompt'"
Write-Verbose "VenvDir='$VenvDir'"
# Deactivate any currently active virtual environment, but leave the
# deactivate function in place.
deactivate -nondestructive
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
# that there is an activated venv.
$env:VIRTUAL_ENV = $VenvDir
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
Write-Verbose "Setting prompt to '$Prompt'"
# Set the prompt to include the env name
# Make sure _OLD_VIRTUAL_PROMPT is global
function global:_OLD_VIRTUAL_PROMPT { "" }
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
function global:prompt {
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
_OLD_VIRTUAL_PROMPT
}
$env:VIRTUAL_ENV_PROMPT = $Prompt
}
# Clear PYTHONHOME
if (Test-Path -Path Env:PYTHONHOME) {
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
Remove-Item -Path Env:PYTHONHOME
}
# Add the venv to the PATH
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
# This file must be used with "source bin/activate" *from bash*
# You cannot run it directly
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
unset VIRTUAL_ENV_PROMPT
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
# on Windows, a path can contain colons and backslashes and has to be converted:
if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
# transform D:\path\to\venv to /d/path/to/venv on MSYS
# and to /cygdrive/d/path/to/venv on Cygwin
export VIRTUAL_ENV=$(cygpath "/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio")
else
# use the path as-is
export VIRTUAL_ENV="/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio"
fi
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(MyPortfolio) ${PS1:-}"
export PS1
VIRTUAL_ENV_PROMPT="(MyPortfolio) "
export VIRTUAL_ENV_PROMPT
fi
# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <davidedb@gmail.com>.
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
# Unset irrelevant variables.
deactivate nondestructive
setenv VIRTUAL_ENV "/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio"
set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
set _OLD_VIRTUAL_PROMPT="$prompt"
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
set prompt = "(MyPortfolio) $prompt"
setenv VIRTUAL_ENV_PROMPT "(MyPortfolio) "
endif
alias pydoc python -m pydoc
rehash
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
# (https://fishshell.com/). You cannot run it directly.
function deactivate -d "Exit virtual environment and return to normal shell environment"
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
set -gx PATH $_OLD_VIRTUAL_PATH
set -e _OLD_VIRTUAL_PATH
end
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -e _OLD_VIRTUAL_PYTHONHOME
end
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
set -e _OLD_FISH_PROMPT_OVERRIDE
# prevents error when using nested fish instances (Issue #93858)
if functions -q _old_fish_prompt
functions -e fish_prompt
functions -c _old_fish_prompt fish_prompt
functions -e _old_fish_prompt
end
end
set -e VIRTUAL_ENV
set -e VIRTUAL_ENV_PROMPT
if test "$argv[1]" != "nondestructive"
# Self-destruct!
functions -e deactivate
end
end
# Unset irrelevant variables.
deactivate nondestructive
set -gx VIRTUAL_ENV "/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio"
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
# Unset PYTHONHOME if set.
if set -q PYTHONHOME
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# fish uses a function instead of an env var to generate the prompt.
# Save the current fish_prompt function as the function _old_fish_prompt.
functions -c fish_prompt _old_fish_prompt
# With the original prompt function renamed, we can override with our own.
function fish_prompt
# Save the return status of the last command.
set -l old_status $status
# Output the venv prompt; color taken from the blue of the Python logo.
printf "%s%s%s" (set_color 4B8BBE) "(MyPortfolio) " (set_color normal)
# Restore the return status of the previous command.
echo "exit $old_status" | .
# Output the original/"old" prompt.
_old_fish_prompt
end
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
set -gx VIRTUAL_ENV_PROMPT "(MyPortfolio) "
end
#!/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from flask.cli import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/home/ankan/skola-main/tdp-003/egna-datormiljoen/MyPortfolio/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
python3
\ No newline at end of file
/usr/bin/python3
\ No newline at end of file
python3
\ No newline at end of file
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
# Gör project_id dynamisk så att den uppdateras efter borttagning/addering av projekt. # Gör project_id dynamisk så att den uppdateras efter borttagning/addering av projekt.
# ---- IMPORTS ---- # # ---- IMPORTS ---- #
import os import os
import json import json
...@@ -16,9 +14,7 @@ from operator import itemgetter ...@@ -16,9 +14,7 @@ from operator import itemgetter
# ---- IMPORTS ---- # # ---- IMPORTS ---- #
def load(filename): def load(filename):
try: try:
with open(filename, 'r', encoding='utf-8') as file: with open(filename, 'r', encoding='utf-8') as file:
data = json.load(file) data = json.load(file)
...@@ -29,18 +25,14 @@ def load(filename): ...@@ -29,18 +25,14 @@ def load(filename):
return None return None
def save(data): def save(data):
with open('data.json', 'w', encoding='utf-8') as file: with open('data.json', 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4) json.dump(data, file, ensure_ascii=False, indent=4)
file.close() file.close()
# Reload data # Reload data
load() load()
# Get project count # Get project count
...@@ -48,19 +40,15 @@ def get_project_count(data): ...@@ -48,19 +40,15 @@ def get_project_count(data):
return len(data) return len(data)
# Get project by ID # Get project by ID
def get_project(data, id): def get_project(data, id):
for n in range(0, get_project_count(data)): for n in range(0, get_project_count(data)):
if data[n]['project_id'] == id: if data[n]['project_id'] == id:
return data[n] return data[n]
# Get all unique techniques from project # Get all unique techniques from project
def get_techniques(data): def get_techniques(data):
techniques = [] techniques = []
for project in data: for project in data:
for tech in project['techniques_used']: for tech in project['techniques_used']:
...@@ -68,14 +56,12 @@ def get_techniques(data): ...@@ -68,14 +56,12 @@ def get_techniques(data):
techniques.append(tech) techniques.append(tech)
techniques.sort() techniques.sort()
return techniques
return techniques
# Gets all unique techniques from all projects ! COULD USE SOME FILTERING ! # Gets all unique techniques from all projects ! COULD USE SOME FILTERING !
def get_technique_stats(data): def get_technique_stats(data):
technique_list = get_techniques(data) technique_list = get_techniques(data)
technique_stats = {} technique_stats = {}
current_techniques = [] current_techniques = []
...@@ -83,21 +69,17 @@ def get_technique_stats(data): ...@@ -83,21 +69,17 @@ def get_technique_stats(data):
for technique in technique_list: for technique in technique_list:
for project in data: for project in data:
if technique in project['techniques_used']: if technique in project['techniques_used']:
current_techniques.append({'id' : project['project_id'], 'name' : project['project_name']}) current_techniques.append({'id': project['project_id'], 'name': project['project_name']})
technique_stats.update({technique : current_techniques.copy()}) technique_stats.update({technique: current_techniques.copy()})
current_techniques.clear() current_techniques.clear()
return technique_stats return technique_stats
# Fetches and sorts projects matching criteria from the specified list. # 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): def search(data, sort_by='start_date', sort_order='desc', techniques=None, search=None, search_fields=None):
if isinstance(search, str):
if type(search) == str:
search = search.lower() search = search.lower()
results = [] results = []
...@@ -107,88 +89,78 @@ def search(data, sort_by='start_date', sort_order='desc', techniques=None, searc ...@@ -107,88 +89,78 @@ def search(data, sort_by='start_date', sort_order='desc', techniques=None, searc
# sort it # sort it
results = sorted(results, key=itemgetter(sort_by)) results = sorted(results, key=itemgetter(sort_by))
# order it # order it
if sort_order == 'desc': results.reverse() if sort_order == 'desc':
results.reverse()
# filter it (by techniques) # filter it (by techniques)
if techniques != None: if techniques is not None:
for technique in get_techniques(data): for technique in get_techniques(data):
for project in results: for project in results:
if all(n in project['techniques_used'] for n in techniques): if all(n in project['techniques_used'] for n in techniques):
pass pass
else: else:
results.pop(results.index(project)) results.pop(results.index(project))
# search for it # search for it
if search != None: if search is not None:
search_results = [] search_results = []
for project in results: for project in results:
if search_fields is not None and search_fields != "" and search != "":
if search_fields != None and search_fields != "" and search != "":
for field in search_fields: for field in search_fields:
substring = project[field] substring = project[field]
if type(substring) == str: # Check type before calling lower()
if isinstance(substring, str):
substring = substring.lower() substring = substring.lower()
if substring.find(search) != -1: if substring.find(search) != -1:
search_results.append(project) search_results.append(project)
break break
if type(substring) == int: elif isinstance(substring, int):
if str(substring).find(search) != -1: if str(substring).find(search) != -1:
search_results.append(project) search_results.append(project)
break break
if type(substring) == list: elif isinstance(substring, list):
for subsubstring in substring: for subsubstring in substring:
if type(subsubstring) == str: if isinstance(subsubstring, str):
if subsubstring.find(search) != -1: if subsubstring.lower().find(search) != -1:
search_results.append(project) search_results.append(project)
break break
if type(subsubstring) == int: elif isinstance(subsubstring, int):
if str(subsubstring).find(search) != -1: if str(subsubstring).find(search) != -1:
search_results.append(project) search_results.append(project)
break break
elif search_fields == "": elif search_fields == "":
results.clear() results.clear()
break break
else: else:
for substring in list(project.values()): for substring in list(project.values()):
substring = substring.lower() # Check type before calling lower()
print(type(substring)) if isinstance(substring, str):
if type(substring) == str: if substring.lower().find(search) != -1:
if substring.find(search) != -1:
search_results.append(project) search_results.append(project)
break break
if type(substring) == int: elif isinstance(substring, int):
if str(substring).find(search) != -1: if str(substring).find(search) != -1:
search_results.append(project) search_results.append(project)
break break
if type(substring) == list: elif isinstance(substring, list):
for subsubstring in substring: for subsubstring in substring:
if type(subsubstring) == str: if isinstance(subsubstring, str):
if subsubstring.find(search) != -1: if subsubstring.lower().find(search) != -1:
search_results.append(project) search_results.append(project)
break break
if type(subsubstring) == int: elif isinstance(subsubstring, int):
if str(subsubstring).find(search) != -1: if str(subsubstring).find(search) != -1:
search_results.append(project) search_results.append(project)
break break
results = search_results results = search_results
#pprint.pp(results)
return results
return results
def cls(): def cls():
...@@ -196,14 +168,12 @@ def cls(): ...@@ -196,14 +168,12 @@ def cls():
pass pass
def new_project(data): def new_project(data):
cls() cls()
# ---- COLLECT INFO ---- # ---- COLLECT INFO ----
project_title = input("Project title: ") project_title = input("Project title: ")
project_id = get_project_count(data)+1 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(",") 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: ") description = input("Provide a description of your project: ")
url = input("Provide a link to the source code/demo of your project: ") url = input("Provide a link to the source code/demo of your project: ")
...@@ -212,32 +182,29 @@ def new_project(data): ...@@ -212,32 +182,29 @@ def new_project(data):
# lexicographical order sort aka alphabetical # lexicographical order sort aka alphabetical
techniques.sort() techniques.sort()
new_project = { new_project = {
"project_name": project_title, "project_name": project_title,
"project_id": project_id, "project_id": project_id,
"used_techniques": techniques, "used_techniques": techniques,
"long_description": description, "long_description": description,
"img_url": img_url, "img_url": img_url,
"url": url "url": url
} }
cls() cls()
print("\n\nProject preview:\n") print("\n\nProject preview:\n")
pprint.pp(new_project) pprint.pp(new_project)
option = int(input("\n1: Create\n2: Cancel\n> ")) option = int(input("\n1: Create\n2: Cancel\n> "))
if option == 1: if option == 1:
data.append(new_project) data.append(new_project)
save(data) save(data)
pass pass
def list_projects(data): def list_projects(data):
cls() cls()
...@@ -246,46 +213,37 @@ def list_projects(data): ...@@ -246,46 +213,37 @@ def list_projects(data):
print("\n") print("\n")
def edit_project(data, id): def edit_project(data, id):
while True: while True:
if id > get_project_count(data) or id < 0: if id > get_project_count(data) or id < 0:
print("Project ID doesn't exist.\n") print("Project ID doesn't exist.\n")
id = int(input("Project_ID to edit: ")) id = int(input("Project_ID to edit: "))
else: else:
cls() cls()
project = get_project(data, id) project = get_project(data, id)
project.pop('project_id') # Project ID shouldn't be changed project.pop('project_id') # Project ID shouldn't be changed
print(f"Editing project: {project['title']}\n") print(f"Editing project: {project['title']}\n")
pprint.pp(project) pprint.pp(project)
print("") print("")
for field in enumerate(project): for field in enumerate(project):
print(f"{field[0]}: {field[1]}") print(f"{field[0]}: {field[1]}")
input("\nField to edit: ") input("\nField to edit: ")
def delete_project(data): def delete_project(data):
pass pass
def menu(data): def menu(data):
menu_items = ["Add new project", "List projects", "Edit existing project", "Delete project", "Quit"] menu_items = ["Add new project", "List projects", "Edit existing project", "Delete project", "Quit"]
menu_index = 0 menu_index = 0
while True: while True:
cls() cls()
titular = r""" titular = r"""
____ _ __ _ _ ____ _ __ _ _
| _ \ ___ _ __ | |_ / _| ___ | | (_) ___ | _ \ ___ _ __ | |_ / _| ___ | | (_) ___
...@@ -297,7 +255,7 @@ def menu(data): ...@@ -297,7 +255,7 @@ def menu(data):
print(titular) print(titular)
for i in menu_items: for i in menu_items:
print(f"{menu_items.index(i)+1}: {i}") print(f"{menu_items.index(i) + 1}: {i}")
try: try:
option = int(input(f"> ")) option = int(input(f"> "))
...@@ -317,17 +275,11 @@ def menu(data): ...@@ -317,17 +275,11 @@ def menu(data):
break break
except: except:
print("") print("")
def main(): def main():
data = load('MyPortfolio/data.json') data = load('MyPortfolio/data.json')
if __name__ == "__main__": if __name__ == "__main__":
main() main()
pip
Copyright 2010 Pallets
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Metadata-Version: 2.1
Name: MarkupSafe
Version: 3.0.1
Summary: Safely add untrusted strings to HTML/XML markup.
Maintainer-email: Pallets <contact@palletsprojects.com>
License: Copyright 2010 Pallets
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Project-URL: Donate, https://palletsprojects.com/donate
Project-URL: Documentation, https://markupsafe.palletsprojects.com/
Project-URL: Changes, https://markupsafe.palletsprojects.com/changes/
Project-URL: Source, https://github.com/pallets/markupsafe/
Project-URL: Chat, https://discord.gg/pallets
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Text Processing :: Markup :: HTML
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.txt
# MarkupSafe
MarkupSafe implements a text object that escapes characters so it is
safe to use in HTML and XML. Characters that have special meanings are
replaced so that they display as the actual characters. This mitigates
injection attacks, meaning untrusted user input can safely be displayed
on a page.
## Examples
```pycon
>>> from markupsafe import Markup, escape
>>> # escape replaces special characters and wraps in Markup
>>> escape("<script>alert(document.cookie);</script>")
Markup('&lt;script&gt;alert(document.cookie);&lt;/script&gt;')
>>> # wrap in Markup to mark text "safe" and prevent escaping
>>> Markup("<strong>Hello</strong>")
Markup('<strong>hello</strong>')
>>> escape(Markup("<strong>Hello</strong>"))
Markup('<strong>hello</strong>')
>>> # Markup is a str subclass
>>> # methods and operators escape their arguments
>>> template = Markup("Hello <em>{name}</em>")
>>> template.format(name='"World"')
Markup('Hello <em>&#34;World&#34;</em>')
```
## Donate
The Pallets organization develops and supports MarkupSafe and other
popular packages. In order to grow the community of contributors and
users, and allow the maintainers to devote more time to the projects,
[please donate today][].
[please donate today]: https://palletsprojects.com/donate
MarkupSafe-3.0.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
MarkupSafe-3.0.1.dist-info/LICENSE.txt,sha256=SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o,1475
MarkupSafe-3.0.1.dist-info/METADATA,sha256=wGwihiqdL2I8R2A5A829_C-xNqpIln1plgzTSqwNflY,3975
MarkupSafe-3.0.1.dist-info/RECORD,,
MarkupSafe-3.0.1.dist-info/WHEEL,sha256=7B4nnId14TToQHuAKpxbDLCJbNciqBsV-mvXE2hVLJc,151
MarkupSafe-3.0.1.dist-info/top_level.txt,sha256=qy0Plje5IJuvsCBjejJyhDCjEAdcDLK_2agVcex8Z6U,11
markupsafe/__init__.py,sha256=sr-U6_27DfaSrj5jnHYxWN-pvhM27sjlDplMDPZKm7k,13214
markupsafe/__pycache__/__init__.cpython-312.pyc,,
markupsafe/__pycache__/_native.cpython-312.pyc,,
markupsafe/_native.py,sha256=hSLs8Jmz5aqayuengJJ3kdT5PwNpBWpKrmQSdipndC8,210
markupsafe/_speedups.c,sha256=75yiBvklVsTr_3EL3vH0tpjdBH2QaQ2JH8pg6WER8X8,4154
markupsafe/_speedups.cpython-312-x86_64-linux-gnu.so,sha256=3Rl01ODAVUyJaZFC3BiH6kp1lPnhwLTjh5iJWU-AlaY,44536
markupsafe/_speedups.pyi,sha256=ENd1bYe7gbBUf2ywyYWOGUpnXOHNJ-cgTNqetlW8h5k,41
markupsafe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
Wheel-Version: 1.0
Generator: setuptools (75.1.0)
Root-Is-Purelib: false
Tag: cp312-cp312-manylinux_2_17_x86_64
Tag: cp312-cp312-manylinux2014_x86_64
markupsafe
pip
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