From ae8050622af23ae77511fa7d3aa7e4a12e99ac46 Mon Sep 17 00:00:00 2001 From: lexara-prime-ai Date: Mon, 3 Jun 2024 11:13:08 +0000 Subject: [PATCH 1/3] Added logic to extract content from WsprSpot wrapper --- hyper/hyper/server.py | 58 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/hyper/hyper/server.py b/hyper/hyper/server.py index c94d170..5b3b2aa 100644 --- a/hyper/hyper/server.py +++ b/hyper/hyper/server.py @@ -3,10 +3,60 @@ import python_wrapper.python_wrapper -async def main(): - output = await python_wrapper.python_wrapper.get_wspr_spots("1", "JSON") - print("Output: ", output.get_data()) +class Server: + async def main(self): + output = await python_wrapper.python_wrapper.get_wspr_spots("10", "JSON") + data = output.get_data() + for record in data: + id_field = record['id'] + time_field = record['time'] + band_field = record['band'] + rx_sign_field = record['rx_sign'] + rx_lat_field = record['rx_lat'] + rx_lon_field = record['rx_lon'] + rx_loc_field = record['rx_loc'] + tx_sign_field = record['tx_sign'] + tx_lat_field = record['tx_lat'] + tx_lon_field = record['tx_lon'] + tx_loc_field = record['tx_loc'] + distance_field = record['distance'] + azimuth_field = record['azimuth'] + rx_azimuth_field = record['rx_azimuth'] + frequency_field = record['frequency'] + power_field = record['power'] + snr_field = record['snr'] + drift_field = record['drift'] + version_field = record['version'] + code_field = record['code'] + # Verify content. + print("ID:", id_field) + print("Time:", time_field) + print("Band:", band_field) + print("RX Sign:", rx_sign_field) + print("RX Lat:", rx_lat_field) + print("RX Lon:", rx_lon_field) + print("RX Loc:", rx_loc_field) + print("TX Sign:", tx_sign_field) + print("TX Lat:", tx_lat_field) + print("TX Lon:", tx_lon_field) + print("TX Loc:", tx_loc_field) + print("Distance:", distance_field) + print("Azimuth:", azimuth_field) + print("RX Azimuth:", rx_azimuth_field) + print("Frequency:", frequency_field) + print("Power:", power_field) + print("SNR:", snr_field) + print("Drift:", drift_field) + print("Version:", version_field) + print("Code:", code_field) + print("---") + + async def __call__(self): + await self.main() + + +server = Server() if __name__ == "__main__": - asyncio.run(main()) + asyncio.run(server()) From c8f716e7898c3e50a82c55a6b781128704507c0f Mon Sep 17 00:00:00 2001 From: lexara-prime-ai Date: Mon, 3 Jun 2024 18:03:29 +0000 Subject: [PATCH 2/3] Added logic to dump datato specified file path --- .gitignore | 3 ++- hyper/hyper/constants.py | 3 +++ hyper/hyper/server.py | 54 ++++++++++++++++++++++++++++++++++--- scripts/bash/python_deps.sh | 26 ++++++++++++++++++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 hyper/hyper/constants.py create mode 100755 scripts/bash/python_deps.sh diff --git a/.gitignore b/.gitignore index 8668e2e..53f10a5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ # Added by cargo /target -/**/hyper/hyper/__pycache__ \ No newline at end of file +/**/hyper/hyper/__pycache__ +/**/data \ No newline at end of file diff --git a/hyper/hyper/constants.py b/hyper/hyper/constants.py new file mode 100644 index 0000000..5589766 --- /dev/null +++ b/hyper/hyper/constants.py @@ -0,0 +1,3 @@ +class CONSTANTS: + FILE_PATH = './hyper/hyper/data' + FILE_NAME = 'wspr_spots.csv' \ No newline at end of file diff --git a/hyper/hyper/server.py b/hyper/hyper/server.py index 5b3b2aa..b3e9a6b 100644 --- a/hyper/hyper/server.py +++ b/hyper/hyper/server.py @@ -1,12 +1,57 @@ import asyncio +import csv +import os import python_wrapper.python_wrapper +import constants class Server: - async def main(self): - output = await python_wrapper.python_wrapper.get_wspr_spots("10", "JSON") + def __init__(self): + self.write_path = os.path.join( + constants.CONSTANTS.FILE_PATH, 'wspr_spot_data.csv') + + async def write_to_csv(self): + """ + Args: self. + return type: () + """ + output = await python_wrapper.python_wrapper.get_wspr_spots("100", "JSON") data = output.get_data() + + # Display data that's being fetched for [DEBUG] purposes. + await self.display_data(data) + + # Write data to csv. -> + write_path = self.write_path + print('\nWrite path: \n', write_path) + + # Check if directory exists. + if not os.path.exists(constants.CONSTANTS.FILE_PATH): + os.makedirs(constants.CONSTANTS.FILE_PATH) + + with open(write_path, mode='w', newline='') as file: + writer = csv.writer(file) + writer.writerow([ + 'ID', 'Time', 'Band', 'RX Sign', 'RX Lat', 'RX Lon', 'RX Loc', + 'TX Sign', 'TX Lat', 'TX Lon', 'TX Loc', 'Distance', 'Azimuth', + 'RX Azimuth', 'Frequency', 'Power', 'SNR', 'Drift', 'Version', 'Code' + ]) + + for record in data: + writer.writerow([ + record['id'], record['time'], record['band'], record['rx_sign'], + record['rx_lat'], record['rx_lon'], record['rx_loc'], record['tx_sign'], + record['tx_lat'], record['tx_lon'], record['tx_loc'], record['distance'], + record['azimuth'], record['rx_azimuth'], record['frequency'], + record['power'], record['snr'], record['drift'], record['version'], record['code'] + ]) + + async def display_data(self, data): + """ + Args: self, data -> WsprSpot dict. + return type: () + """ for record in data: id_field = record['id'] time_field = record['time'] @@ -30,6 +75,8 @@ async def main(self): code_field = record['code'] # Verify content. + print("\nFetching [ROW] >\n") + print("ID:", id_field) print("Time:", time_field) print("Band:", band_field) @@ -50,10 +97,9 @@ async def main(self): print("Drift:", drift_field) print("Version:", version_field) print("Code:", code_field) - print("---") async def __call__(self): - await self.main() + await self.write_to_csv() server = Server() diff --git a/scripts/bash/python_deps.sh b/scripts/bash/python_deps.sh new file mode 100755 index 0000000..e6f2ddc --- /dev/null +++ b/scripts/bash/python_deps.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Update the package list +echo "Updating package list..." +sudo apt-get update + +# Install pip if it is not already installed +echo "Checking for pip..." +if ! command -v pip &> /dev/null; then + echo "pip not found. Installing pip..." + sudo apt-get install -y python3-pip +else + echo "pip is already installed." +fi + +# Install mkdocs +echo "Installing mkdocs..." +pip install mkdocs + +# Verify installation +echo "Verifying mkdocs installation..." +if python3 -c "import mkdocs" &> /dev/null; then + echo "mkdocs successfully installed." +else + echo "Failed to install mkdocs." +fi From 5e97d0788b4a6abca806ab586d48b463cb246e09 Mon Sep 17 00:00:00 2001 From: lexara-prime-ai Date: Mon, 3 Jun 2024 20:32:18 +0000 Subject: [PATCH 3/3] Updated write path -> Switched to ./hyper/tableau/data --- hyper/hyper/constants.py | 2 +- hyper/hyper/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hyper/hyper/constants.py b/hyper/hyper/constants.py index 5589766..1343b13 100644 --- a/hyper/hyper/constants.py +++ b/hyper/hyper/constants.py @@ -1,3 +1,3 @@ class CONSTANTS: - FILE_PATH = './hyper/hyper/data' + FILE_PATH = './tableau/data' FILE_NAME = 'wspr_spots.csv' \ No newline at end of file diff --git a/hyper/hyper/server.py b/hyper/hyper/server.py index b3e9a6b..112606c 100644 --- a/hyper/hyper/server.py +++ b/hyper/hyper/server.py @@ -16,7 +16,7 @@ async def write_to_csv(self): Args: self. return type: () """ - output = await python_wrapper.python_wrapper.get_wspr_spots("100", "JSON") + output = await python_wrapper.python_wrapper.get_wspr_spots("10000", "JSON") data = output.get_data() # Display data that's being fetched for [DEBUG] purposes.