Skip to content

Commit

Permalink
Merge pull request #35 from lexara-prime-ai/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lexara-prime-ai authored Jun 3, 2024
2 parents ff74683 + 5e97d07 commit 5097bc1
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
# Added by cargo

/target
/**/hyper/hyper/__pycache__
/**/hyper/hyper/__pycache__
/**/data
3 changes: 3 additions & 0 deletions hyper/hyper/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CONSTANTS:
FILE_PATH = './tableau/data'
FILE_NAME = 'wspr_spots.csv'
104 changes: 100 additions & 4 deletions hyper/hyper/server.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,108 @@
import asyncio
import csv
import os

import python_wrapper.python_wrapper
import constants


async def main():
output = await python_wrapper.python_wrapper.get_wspr_spots("1", "JSON")
print("Output: ", output.get_data())
class Server:
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("10000", "JSON")
data = output.get_data()

# Display data that's being fetched for [DEBUG] purposes.
await self.display_data(data)

# Write data to csv. -> <wspr_spots.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']
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("\nFetching [ROW] >\n")

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)

async def __call__(self):
await self.write_to_csv()


server = Server()

if __name__ == "__main__":
asyncio.run(main())
asyncio.run(server())
26 changes: 26 additions & 0 deletions scripts/bash/python_deps.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5097bc1

Please sign in to comment.