Skip to content

Commit

Permalink
Develop (#8)
Browse files Browse the repository at this point in the history
* Don't do this at home

* one more

* errors now display

* local usage and production

* error file

* trying more methods

* Source method

* source display

* source help

* Weather command

* bump version 0.0.4

* usd-ars pair

* paths

* postinst

* bump to 0.0.5
  • Loading branch information
jd-apprentice authored Jan 21, 2023
1 parent ebd2293 commit d5cfc34
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 68 deletions.
2 changes: 1 addition & 1 deletion DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: dbn-tools
Version: 0.0.4
Version: 0.0.5
Section: utils
Priority: optional
Architecture: all
Expand Down
3 changes: 2 additions & 1 deletion usr/bin/constants/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export descriptions=(
"8) Open ports - Displays a list of open network ports and their associated processes."
"9) Get weather - Display a table with the current weather of your location."
"10) Search for a file - Searches for a file by name or wildcard pattern."
"11) Exit - Exits the application."
"11) USR-ARS Pair - Ask the value of the USD Dolar against the argentine PESO"
"12) Exit - Exit the application"
)
15 changes: 14 additions & 1 deletion usr/bin/constants/menu-esp.sh
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
export menu_options_spanish=("1) Analizar uso del disco" "2) Eliminar archivos temporales" "3) Vaciar la papelera de reciclaje" "4) Desinstalar programa" "5) Información del sistema" "6) Uso de memoria" "7) Tiempo de actividad del sistema" "8) Puertos abiertos" "9) Clima actual" "10) Buscar archivo" "11) Salir")
export menu_options_spanish=(
"1) Analizar uso del disco"
"2) Eliminar archivos temporales"
"3) Vaciar la papelera de reciclaje"
"4) Desinstalar programa"
"5) Información del sistema"
"6) Uso de memoria"
"7) Tiempo de actividad del sistema"
"8) Puertos abiertos"
"9) Clima actual"
"10) Buscar archivo"
"11) Dolar a pesos"
"12) Salir"
)
15 changes: 14 additions & 1 deletion usr/bin/constants/menu.sh
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
export menu_options=("1) Analyze disk usage" "2) Delete temporary files" "3) Empty recycle bin" "4) Uninstall program" "5) System information" "6) Memory usage" "7) System uptime" "8) Open ports" "9) Get current weather" "10) Search for a file" "11) Exit")
export menu_options=(
"1) Analyze disk usage"
"2) Delete temporary files"
"3) Empty recycle bin"
"4) Uninstall program"
"5) System information"
"6) Memory usage"
"7) System uptime"
"8) Open ports"
"9) Get current weather"
"10) Search for a file"
"11) USD-ARS Pair"
"12) Exit"
)
19 changes: 7 additions & 12 deletions usr/bin/dbn-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
args=()
prompt="Enter an option: "

# Source functions
for file in $(find /usr/bin/functions/ -name '*.sh'); do
if [ -f "$file" ]; then
source "$file"
fi
done

# Source constants
for file in $(find /usr/bin/constants/ -name '*.sh'); do
if [ -f "$file" ]; then
source "$file"
fi
# Source files
for dir in '/usr/bin/functions/' '/usr/bin/constants/'; do
for file in $(find $dir -name '*.sh'); do
if [ -f "$file" ]; then
source "$file"
fi
done
done

# Iterate over all the arguments
Expand Down
18 changes: 17 additions & 1 deletion usr/bin/functions/display-menu-options.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!bin/bash

# Generate random color
random_color() {
color=$((RANDOM % 6 + 1))
case $color in
1) echo -ne "\e[31m" ;; # red
2) echo -ne "\e[32m" ;; # green
3) echo -ne "\e[33m" ;; # yellow
4) echo -ne "\e[34m" ;; # blue
5) echo -ne "\e[35m" ;; # purple
6) echo -ne "\e[36m" ;; # cyan
esac
}


# Display the menu options
function DisplayMenuOptions() {

Expand All @@ -15,9 +29,11 @@ function DisplayMenuOptions() {
echo "$menu_separator"

for i in "${!menu_options[@]}"; do
echo -e "\033[3$((i + 1))m${menu_options[$i]}\033[0m"
color=$(random_color)
echo -e "$color ${menu_options[$i]} \e[0m"
done


}

export -f DisplayMenuOptions
58 changes: 7 additions & 51 deletions usr/bin/functions/read-prompt.sh
Original file line number Diff line number Diff line change
@@ -1,62 +1,18 @@
#!bin/bash

function ReadPrompt() {
# Order is based on usr/bin/constants/menu.sh file, if you are going to edit something from here, edit it there too
options=(DiskUsage DeleteTemporary EmptyRecycleBin UninstallPackage SystemInfo MemoryUsage Uptime OpenPorts GetWeather FindFile "usr/bin/functions/usd-ars.py" exit)

# Read the user's option
read -p "$prompt" option

# Perform the action corresponding to the chosen option
case $option in
1)

DiskUsage
;;
2)

DeleteTemporary
;;
3)

EmptyRecycleBin
;;
4)

UninstallPackage
;;
5)

SystemInfo
;;
6)

MemoryUsage
;;
7)

Uptime
;;
8)

OpenPorts
;;
9)

GetWeather
;;
10)

FindFile
;;
11)

# Exit the application
exit
;;
*)

# Invalid argument
if [[ $option -le ${#options[@]} && $option -gt 0 ]]; then
${options[$option-1]}
else
echo "Invalid option"
;;
esac
fi
}

export -f ReadPrompt
38 changes: 38 additions & 0 deletions usr/bin/functions/usd-ars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

# Imports
import requests

# Constants
arrData = []
dolarAPI = "https://api.bluelytics.com.ar/v2/latest"
sackEmoji = "💰 "
arsLabel = " ARS"

# Get data from the api
def getData(url):
response = requests.get(url)
data = response.json()
arrData.append(data["oficial"])
arrData.append(data["blue"])
arrData.append(data["oficial_euro"])
arrData.append(data["blue_euro"])

# Function to print the table
def print_table(data):
col_widths = [max(len(str(item)) for item in col) for col in zip(*data)]
for row in data:
print(" ".join(str(item).ljust(col_widths[i]) for i, item in enumerate(row)))

# Main function
def main():
getData(dolarAPI)
table_data = [["💱 Currency", "💸 Value"],
["💵 Official", sackEmoji + str(arrData[0]["value_avg"]) + arsLabel],
["💵 Blue", sackEmoji + str(arrData[1]["value_avg"]) + arsLabel],
["💶 Official_Euro", sackEmoji + str(arrData[2]["value_avg"]) + arsLabel],
["💶 Blue_Euro", sackEmoji + str(arrData[3]["value_avg"]) + arsLabel]]
print_table(table_data)

# Init application
main()
Empty file modified usr/bin/functions/weather.sh
100644 → 100755
Empty file.

0 comments on commit d5cfc34

Please sign in to comment.