diff --git a/.gitignore b/.gitignore index 358d7e9..65afb1f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .terraform *.tfstate .env +/**/.venv service_account.json garage.toml diff --git a/hyper/hyper/error_handling.py b/hyper/hyper/error_handling.py new file mode 100644 index 0000000..f6268ed --- /dev/null +++ b/hyper/hyper/error_handling.py @@ -0,0 +1,15 @@ +# Terminal colors. +CRED = "\033[91m" +CEND = "\033[0m" + + +class ErrorHandling: + def propagate_error(self, process_name: str, message: str): + print( + f""" + {CRED} An [ERROR] occured {CEND} + + Info: {message} + Process: {process_name} + """ + ) diff --git a/hyper/hyper/server.py b/hyper/hyper/server.py index 45b6e71..9b7676a 100644 --- a/hyper/hyper/server.py +++ b/hyper/hyper/server.py @@ -5,6 +5,7 @@ import constants import drive +import error_handling import python_wrapper.python_wrapper @@ -14,7 +15,23 @@ def __init__(self, interval, num_rows): self.write_path = os.path.join(constants.FILE_PATH, constants.FILE_NAME) self.interval = interval self.num_rows = num_rows + self.error_handling = error_handling.ErrorHandling() + # --------------------------------------------------- + """Fetch data from WSPR database via .""" + # --------------------------------------------------- + async def fetch_data(self): + try: + output = await python_wrapper.python_wrapper.get_wspr_spots( + self.num_rows, "JSON" + ) + return output + except Exception as e: + self.error_handling.propagate_error("fetch_data", f"{e}") + + # ---------------------------------------------- + """Write data to file asynchronously.""" + # ---------------------------------------------- async def write_to_csv(self): """ Args: self. @@ -22,9 +39,7 @@ async def write_to_csv(self): """ try: - output = await python_wrapper.python_wrapper.get_wspr_spots( - self.num_rows, "JSON" - ) + output = await self.fetch_data() data = output.get_data() # Display data that's being fetched for [DEBUG] purposes. @@ -94,7 +109,7 @@ async def write_to_csv(self): # Upload [output] file to Google Drive. drive.upload_to_drive(constants.FULL_PATH) except Exception as e: - print("An [ERROR] occurred: ", e) + self.error_handling.propagate_error("write_to_csv", f"{e}") async def display_data(self, data): """ diff --git a/object_storage/Dockerfile b/object_storage/Dockerfile new file mode 100644 index 0000000..45a4d58 --- /dev/null +++ b/object_storage/Dockerfile @@ -0,0 +1,2 @@ +FROM rust:latest + diff --git a/scripts/bash/python_deps.sh b/scripts/bash/python_deps.sh index d2dfbbd..51cab42 100755 --- a/scripts/bash/python_deps.sh +++ b/scripts/bash/python_deps.sh @@ -1,29 +1,49 @@ #!/bin/bash +# Terminal Colors. +NORMAL=$(tput sgr0) +UNDERLINE=$(tput smul) +RED=$(tput setaf 1) +BLUE=$(tput setaf 4) +GREEN=$(tput setaf 2) +# BLACK=$(tput setaf 0) +# YELLOW=$(tput setaf 3) +# LIME_YELLOW=$(tput setaf 190) +# POWDER_BLUE=$(tput setaf 153) +# MAGENTA=$(tput setaf 5) +# CYAN=$(tput setaf 6) +# WHITE=$(tput setaf 7) +# BRIGHT=$(tput bold) +# NORMAL=$(tput sgr0) +# REVERSE=$(tput smso) +# BLINK=$(tput blink) + +# Install [patchelf] +sudo apt-get -y install patchelf -y + # Check if pip is installed. if ! command -v pip &>/dev/null; then - echo "pip not found. Installing pip..." + echo "${BLUE}pip not found. Installing pip...${NORMAL}" sudo apt-get install -y python3-pip else - echo "pip is already installed." + echo "${GREEN}pip is already installed.${NORMAL}" fi - # Modules that will be installed/upgraded. modules=("modal" "mkdocs" "maturin" "patchelf" "tableauhyperapi" "google-api-python-client" "google-auth-httplib2" "google-auth-oauthlib") -echo "Installing dependencies: ${modules[*]}..." +echo "${BLUE}Installing dependencies: ${modules[*]}...${NORMAL}" pip install "${modules[@]}" --upgrade # Verify module installation. verify_installation() { local module=$1 local import_name=$2 - echo "Verifying ${module} installation..." + printf "\nVERIFYING %s INSTALLATION...\n" "${module}" if python3 -c "import ${import_name}" &>/dev/null; then - echo "${module} successfully installed." + printf "%s ${UNDERLINE}${GREEN}SUCCESSFULLY${NORMAL} INSTALLED.\n\n" "${module}" else - echo "Failed to install ${module}." + echo "${UNDERLINE}${RED}FAILED${NORMAL} TO INSTALL ${module}." fi } @@ -47,4 +67,4 @@ done # The [modules] array contains the names of all the modules to be installed. # The [dictionary] [module_import_map] maps module names to their respective import names. # The verify_installation function takes a module name and its import name as arguments, checks if the module can be imported, and prints the appropriate message. -# The script iterates over the module_import_map dictionary to verify the installation of each module using the verify_installation function. \ No newline at end of file +# The script iterates over the module_import_map dictionary to verify the installation of each module using the verify_installation function. diff --git a/src/services/prelude.rs b/src/services/prelude.rs index 1dcc2fa..8073900 100644 --- a/src/services/prelude.rs +++ b/src/services/prelude.rs @@ -1 +1 @@ -pub use crate::services::*; \ No newline at end of file +pub use crate::services::*; diff --git a/src/state/actions/mod.rs b/src/state/actions/mod.rs index 05bebc0..17c1b45 100644 --- a/src/state/actions/mod.rs +++ b/src/state/actions/mod.rs @@ -1 +1 @@ -pub mod db_actions; \ No newline at end of file +pub mod db_actions; diff --git a/src/state/effects/db_effects.rs b/src/state/effects/db_effects.rs index afabec4..89b4f63 100644 --- a/src/state/effects/db_effects.rs +++ b/src/state/effects/db_effects.rs @@ -26,11 +26,24 @@ impl ClickHouseClient { ClickHouseAction::Get => { println!("Fetching all records..."); - let query = "select * from wspr.rx where time > subtractHours(now(), 2) limit"; + /* + A is a growable buffer. Its purpose is to be modifiable. + Why would you pass around a if it's meant to be constant? + Remember that API should usually take a <&str> as argument, not a . + The right constant type is <&str>. – Denys Séguret + + Hence, + + const QUERY: &str = + "select * from wspr.rx where time > subtractHours(now(), 12) limit"; + */ + + const QUERY: &str = + "select * from wspr.rx where time > subtractHours(now(), 12) limit"; // Create [SERVICE] request. let result = data::DataService::GET_SPOT_DATA( - &query.to_string(), + &QUERY.to_string(), limit.to_string(), Some(result_format.to_string()), ) diff --git a/src/state/effects/mod.rs b/src/state/effects/mod.rs index c28dc45..9dfaa5a 100644 --- a/src/state/effects/mod.rs +++ b/src/state/effects/mod.rs @@ -1 +1 @@ -pub mod db_effects; \ No newline at end of file +pub mod db_effects; diff --git a/src/state/mod.rs b/src/state/mod.rs index 9fb8b82..b603797 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -1,6 +1,6 @@ pub mod actions; pub mod db_state; +pub mod effects; +pub mod models; pub mod prelude; pub mod reducers; -pub mod effects; -pub mod models; \ No newline at end of file diff --git a/src/state/models/mod.rs b/src/state/models/mod.rs index f969a12..334444a 100644 --- a/src/state/models/mod.rs +++ b/src/state/models/mod.rs @@ -1 +1 @@ -pub mod spot; \ No newline at end of file +pub mod spot; diff --git a/src/state/reducers/mod.rs b/src/state/reducers/mod.rs index 3882040..dbcd50e 100644 --- a/src/state/reducers/mod.rs +++ b/src/state/reducers/mod.rs @@ -1 +1 @@ -pub mod db_reducers; \ No newline at end of file +pub mod db_reducers;