From 0db078dbe47572cd5c1ad4420ab63fc71381913b Mon Sep 17 00:00:00 2001 From: iRaven4522 Date: Mon, 20 Oct 2025 22:35:35 -0500 Subject: [PATCH] reorganization + multicast works on Linux! --- py2Lib/__init__.py => LFRecord.db | 0 README.md | 36 +----------------- main.py | 16 ++++---- radar/__init__.py | 1 + .../{RadarProcessor.py => imageProcessor.py} | 0 ...TWCRadarCollector.py => radarCollector.py} | 6 +-- ...TWCRadarProcessor.py => radarProcessor.py} | 3 +- ...CSatRadProcessor.py => satRadProcessor.py} | 0 recordGenerators/__init__.py | 1 + recordGenerators/achesAndPains.py | 8 ++-- recordGenerators/airQuality.py | 4 +- recordGenerators/airportDelays.py | 4 +- recordGenerators/alerts.py | 7 +++- recordGenerators/breathing.py | 4 +- recordGenerators/currentObservations.py | 5 +-- recordGenerators/dailyForecast.py | 4 +- recordGenerators/heatingAndCooling.py | 6 ++- recordGenerators/hourlyForecast.py | 4 +- recordGenerators/mosquitoActivity.py | 6 ++- recordGenerators/pollenForecast.py | 4 +- recordGenerators/tideForecast.py | 6 ++- recordGenerators/wateringNeeds.py | 6 ++- recordTasks.py | 6 +-- {records => util}/LFRecord.db | Bin util/__init__.py | 1 + util/{util.py => alphaSort.py} | 0 {py2Lib => util}/bit.py | 7 +++- {records => util}/lfRecord.py | 2 +- 28 files changed, 65 insertions(+), 82 deletions(-) rename py2Lib/__init__.py => LFRecord.db (100%) rename radar/{RadarProcessor.py => imageProcessor.py} (100%) rename radar/{TWCRadarCollector.py => radarCollector.py} (97%) rename radar/{TWCRadarProcessor.py => radarProcessor.py} (99%) rename radar/{TWCSatRadProcessor.py => satRadProcessor.py} (100%) rename {records => util}/LFRecord.db (100%) rename util/{util.py => alphaSort.py} (100%) rename {py2Lib => util}/bit.py (96%) rename {records => util}/lfRecord.py (96%) diff --git a/py2Lib/__init__.py b/LFRecord.db similarity index 100% rename from py2Lib/__init__.py rename to LFRecord.db diff --git a/README.md b/README.md index 96b6d51..46486d3 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,3 @@ -

IntelliStar 2 Message Encoder / Data Collector

+# py2Lib -# Requirements -* Properly set up interface for UDP. -* TWC API Key - -## Completed Records -- [X] Aches and Pains -- [X] Air Quality -- [X] Airport Delays + National Airport delays -- [X] Alerts *(BERecord)* -- [X] Breathing -- [X] Current Conditions -- [X] Daily Forecasts -- [X] Hourly Forecasts -- [X] Heating and Cooling -- [X] Mosquito Activity -- [X] Pollen Forecasts -- [X] Tide Station Forecasts -- [X] Watering Needs -- [ ] Marine Forecasts -- [ ] Traffic Forecasts **(API access missing)** - -# Usage instructions -1) Ensure that [Python is installed](https://www.python.org), or from your package repository (apt/winget). -2) [Download the code or git clone this URL] and unzip to the wanted directory. -3) Use command prompt to enter the directory of the scripts, then install package requirements:
-```pip install -r requirements.txt```
-4) Copy **config.example.json** to **config.json** and edit to your specific config. -4) Drop your unit's **MachineProductCfg.xml** file into the root of the script -5) Run ``py main.py`` - -### Attributions & Disclaimers -Air Quality reports are powered by Copernicus Atmosphere Monitoring Service Information 2022. -Neither the European Commission nor ECMWF is responsible for any use that may be made of the Copernicus Information or Data it contains. +A python implementation of i2Lib from the original i2MessageEncoder. \ No newline at end of file diff --git a/main.py b/main.py index a287fe1..05b00c3 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,7 @@ import asyncio, aiofiles from asyncio.log import logger from asyncore import loop -import logging,coloredlogs -from radar import TWCRadarCollector +import logging import os from datetime import datetime import recordTasks @@ -13,7 +12,6 @@ with open("config.json", "r") as file: cfg = json.load(file) l = logging.getLogger(__name__) -coloredlogs.install(logger=l) useRadarServer = cfg["useRadarServer"] @@ -33,9 +31,9 @@ async def createTemp(): os.mkdir('./.temp/output/satrad') # Create msgId file for bit.py - #async with aiofiles.open('./.temp/msgId.txt', 'w') as msgId: - #await msgId.write('694203') - #await msgId.close() + async with aiofiles.open('./.temp/msgId.txt', 'w') as msgId: + await msgId.write('694203') + await msgId.close() else: l.debug(".temp file exists") return @@ -44,8 +42,10 @@ async def createTemp(): async def main(): await createTemp() - mosaicTask = asyncio.create_task(recordTasks.updateMosaicTask()) - satradTask = asyncio.create_task(recordTasks.updateSatradTask()) + if useRadarServer: + mosaicTask = asyncio.create_task(recordTasks.updateMosaicTask()) + satradTask = asyncio.create_task(recordTasks.updateSatradTask()) + alertsTask = asyncio.create_task(recordTasks.alertsTask()) coTask = asyncio.create_task(recordTasks.coTask()) hfTask = asyncio.create_task(recordTasks.hfTask()) diff --git a/radar/__init__.py b/radar/__init__.py index e69de29..49af6cb 100644 --- a/radar/__init__.py +++ b/radar/__init__.py @@ -0,0 +1 @@ +# This file makes it to where the sys.path.append tomfoolery doesn't have to exist \ No newline at end of file diff --git a/radar/RadarProcessor.py b/radar/imageProcessor.py similarity index 100% rename from radar/RadarProcessor.py rename to radar/imageProcessor.py diff --git a/radar/TWCRadarCollector.py b/radar/radarCollector.py similarity index 97% rename from radar/TWCRadarCollector.py rename to radar/radarCollector.py index d4ed086..08adbed 100644 --- a/radar/TWCRadarCollector.py +++ b/radar/radarCollector.py @@ -1,11 +1,11 @@ import asyncio import aiohttp import aiofiles -import logging, coloredlogs -from py2Lib import bit +import logging from datetime import datetime from os import path, listdir, remove +import util.bit # Open the config file and make it accessible via "cfg" import json @@ -13,7 +13,6 @@ with open("config.json", "r") as file: cfg = json.load(file) l = logging.getLogger(__name__) -coloredlogs.install(level="DEBUG") async def getValidTimestamps(radarType:str) -> list: times = [] @@ -48,7 +47,6 @@ async def getValidTimestamps(radarType:str) -> list: return times async def downloadRadarFrames(radarType:str, timestamps: list) -> list: - url_root = None imagesToSend = [] if (radarType == "satrad"): diff --git a/radar/TWCRadarProcessor.py b/radar/radarProcessor.py similarity index 99% rename from radar/TWCRadarProcessor.py rename to radar/radarProcessor.py index 6ba685b..ad9c22a 100644 --- a/radar/TWCRadarProcessor.py +++ b/radar/radarProcessor.py @@ -7,7 +7,7 @@ import aiohttp import json import time as epochTime import requests -import logging,coloredlogs +import logging from os import path, mkdir, listdir, remove, cpu_count from shutil import rmtree @@ -19,7 +19,6 @@ from wand.color import Color radarType = "Radar-US" l = logging.getLogger(__name__) -coloredlogs.install() upperLeftX,upperLeftY,lowerRightX,lowerRightY = 0,0,0,0 xStart,xEnd,yStart,yEnd = 0,0,0,0 diff --git a/radar/TWCSatRadProcessor.py b/radar/satRadProcessor.py similarity index 100% rename from radar/TWCSatRadProcessor.py rename to radar/satRadProcessor.py diff --git a/recordGenerators/__init__.py b/recordGenerators/__init__.py index e69de29..49af6cb 100644 --- a/recordGenerators/__init__.py +++ b/recordGenerators/__init__.py @@ -0,0 +1 @@ +# This file makes it to where the sys.path.append tomfoolery doesn't have to exist \ No newline at end of file diff --git a/recordGenerators/achesAndPains.py b/recordGenerators/achesAndPains.py index 323c34b..4892055 100644 --- a/recordGenerators/achesAndPains.py +++ b/recordGenerators/achesAndPains.py @@ -1,14 +1,16 @@ import shutil import requests import logging,coloredlogs -import py2Lib.bit -import util.machineProductCfg as MPC -import records.lfRecord as LFR import gzip from os import remove import xml.dom.minidom import aiohttp, aiofiles, asyncio +import util.bit +import util.machineProductCfg as MPC +import util.lfRecord as LFR + + l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/airQuality.py b/recordGenerators/airQuality.py index 86520c9..f361b6e 100644 --- a/recordGenerators/airQuality.py +++ b/recordGenerators/airQuality.py @@ -9,9 +9,9 @@ import aiohttp, aiofiles, asyncio l = logging.getLogger(__name__) coloredlogs.install() -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR locationIds = [] zipCodes = [] diff --git a/recordGenerators/airportDelays.py b/recordGenerators/airportDelays.py index 2440ef9..542e7db 100644 --- a/recordGenerators/airportDelays.py +++ b/recordGenerators/airportDelays.py @@ -6,9 +6,9 @@ import xml.dom.minidom import logging,coloredlogs import aiohttp, aiofiles, asyncio -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/alerts.py b/recordGenerators/alerts.py index 3665af4..1fe5837 100644 --- a/recordGenerators/alerts.py +++ b/recordGenerators/alerts.py @@ -2,7 +2,6 @@ import requests import json import os from datetime import datetime,timedelta -from util.machineProductCfg import getAlertZones import time import pytz import xml.dom.minidom @@ -10,7 +9,11 @@ import shutil import gzip import logging,coloredlogs import aiohttp, aiofiles, asyncio -import py2Lib.bit + +import util.bit +import util.machineProductCfg as MPC +import util.lfRecord as LFR +from util.machineProductCfg import getAlertZones l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/breathing.py b/recordGenerators/breathing.py index 9dab8c1..c210000 100644 --- a/recordGenerators/breathing.py +++ b/recordGenerators/breathing.py @@ -7,9 +7,9 @@ import xml.dom.minidom import logging,coloredlogs import aiohttp, aiofiles, asyncio -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/currentObservations.py b/recordGenerators/currentObservations.py index d3d693e..f84d7c8 100644 --- a/recordGenerators/currentObservations.py +++ b/recordGenerators/currentObservations.py @@ -1,5 +1,4 @@ import requests -import py2Lib.bit as bit import gzip import uuid import os @@ -8,9 +7,9 @@ import xml.dom.minidom import logging,coloredlogs import aiohttp, aiofiles, asyncio -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/dailyForecast.py b/recordGenerators/dailyForecast.py index 41f1441..3fa36f5 100644 --- a/recordGenerators/dailyForecast.py +++ b/recordGenerators/dailyForecast.py @@ -7,9 +7,9 @@ import xml.dom.minidom import logging,coloredlogs import aiohttp, aiofiles, asyncio -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/heatingAndCooling.py b/recordGenerators/heatingAndCooling.py index 58f866a..710b7ae 100644 --- a/recordGenerators/heatingAndCooling.py +++ b/recordGenerators/heatingAndCooling.py @@ -1,9 +1,11 @@ import shutil import requests import logging,coloredlogs -import py2Lib.bit + +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR + import gzip from os import remove import xml.dom.minidom diff --git a/recordGenerators/hourlyForecast.py b/recordGenerators/hourlyForecast.py index 7cb3e48..56d9ecf 100644 --- a/recordGenerators/hourlyForecast.py +++ b/recordGenerators/hourlyForecast.py @@ -7,9 +7,9 @@ import xml.dom.minidom import logging,coloredlogs import aiohttp, aiofiles, asyncio, asyncio -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR l = logging.getLogger(__name__) coloredlogs.install() diff --git a/recordGenerators/mosquitoActivity.py b/recordGenerators/mosquitoActivity.py index 94b51e7..6dc7d9c 100644 --- a/recordGenerators/mosquitoActivity.py +++ b/recordGenerators/mosquitoActivity.py @@ -1,9 +1,11 @@ import shutil import requests import logging,coloredlogs -import py2Lib.bit + +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR + import gzip from os import remove import xml.dom.minidom diff --git a/recordGenerators/pollenForecast.py b/recordGenerators/pollenForecast.py index 3d28ca1..373d4a6 100644 --- a/recordGenerators/pollenForecast.py +++ b/recordGenerators/pollenForecast.py @@ -7,9 +7,9 @@ import xml.dom.minidom import logging, coloredlogs import aiohttp, aiofiles, asyncio -import py2Lib.bit +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR l = logging.getLogger(__name__) diff --git a/recordGenerators/tideForecast.py b/recordGenerators/tideForecast.py index 2756297..ccfe842 100644 --- a/recordGenerators/tideForecast.py +++ b/recordGenerators/tideForecast.py @@ -1,9 +1,11 @@ import shutil import logging,coloredlogs import datetime -import py2Lib.bit + +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR + import gzip from os import remove import xml.dom.minidom diff --git a/recordGenerators/wateringNeeds.py b/recordGenerators/wateringNeeds.py index cd44f4a..dbdbb9d 100644 --- a/recordGenerators/wateringNeeds.py +++ b/recordGenerators/wateringNeeds.py @@ -1,9 +1,11 @@ import shutil import requests import logging,coloredlogs -import py2Lib.bit + +import util.bit import util.machineProductCfg as MPC -import records.lfRecord as LFR +import util.lfRecord as LFR + import gzip from os import remove import xml.dom.minidom diff --git a/recordTasks.py b/recordTasks.py index 962adb8..3921e58 100644 --- a/recordTasks.py +++ b/recordTasks.py @@ -1,6 +1,6 @@ import asyncio from recordGenerators import alerts,currentObservations,hourlyForecast,dailyForecast, airQuality, airportDelays, achesAndPains, breathing, heatingAndCooling, mosquitoActivity, pollenForecast, tideForecast, wateringNeeds -from radar import TWCRadarCollector +from radar import radarCollector from datetime import datetime @@ -10,7 +10,7 @@ async def updateMosaicTask(): while True: # Mosaic intervals are 5+1 minutes, so instead of waiting 40 seconds and running "Datetime.now()" twice, We run it once and wait for 60. if datetime.now().minute in mosaicUpdateIntervals: - await TWCRadarCollector.collect("radarmosaic") + await radarCollector.collect("radarmosaic") await asyncio.sleep(1) async def updateSatradTask(): @@ -19,7 +19,7 @@ async def updateSatradTask(): while True: #Satrad intervals are 10+1 minutes, so instead of waiting 40 seconds and running "Datetime.now()" twice, We run it once and wait for 60. if datetime.now().minute in satradUpdateIntervals: - await TWCRadarCollector.collect("satrad") + await radarCollector.collect("satrad") await asyncio.sleep(1) diff --git a/records/LFRecord.db b/util/LFRecord.db similarity index 100% rename from records/LFRecord.db rename to util/LFRecord.db diff --git a/util/__init__.py b/util/__init__.py index e69de29..49af6cb 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -0,0 +1 @@ +# This file makes it to where the sys.path.append tomfoolery doesn't have to exist \ No newline at end of file diff --git a/util/util.py b/util/alphaSort.py similarity index 100% rename from util/util.py rename to util/alphaSort.py diff --git a/py2Lib/bit.py b/util/bit.py similarity index 96% rename from py2Lib/bit.py rename to util/bit.py index 334c636..0407f71 100644 --- a/py2Lib/bit.py +++ b/util/bit.py @@ -22,8 +22,10 @@ BUF_SIZE = 1396 MULTICAST_TTL = 2 -conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) -conn.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP,socket.inet_aton(MCAST_GRP)+socket.inet_aton(MCAST_IF)) +conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +conn.bind((MCAST_IF, 63216)) +# The below multicast socket options to bind to an interface/add a membership doesn't work on Linux systems. +# conn.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP,socket.inet_aton(MCAST_GRP)+socket.inet_aton(MCAST_IF)) test = b"This is a test" @@ -147,6 +149,7 @@ def sendCommand(command, Pri, msgNum = None): with open(msg_id_file, "r") as f: oMsgId = f.read() msgNum = int(oMsgId) + l.debug(f"Got message ID {msgNum}") f.close() nMsgNum = msgNum + 1 diff --git a/records/lfRecord.py b/util/lfRecord.py similarity index 96% rename from records/lfRecord.py rename to util/lfRecord.py index cd15b95..551db5b 100644 --- a/records/lfRecord.py +++ b/util/lfRecord.py @@ -1,7 +1,7 @@ import sqlite3 # Make a connection to the LFRecord database -con = sqlite3.connect("records/LFRecord.db") +con = sqlite3.connect("util/LFRecord.db") cur = con.cursor()