summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--ipqr.pngbin0 -> 394 bytes
-rw-r--r--ipqr.py6
-rw-r--r--main.py10
-rw-r--r--requirements.txt3
-rw-r--r--settings.json8
-rw-r--r--settings.py14
-rw-r--r--weather.py53
8 files changed, 60 insertions, 37 deletions
diff --git a/README.md b/README.md
index 6740481..01d8c1b 100644
--- a/README.md
+++ b/README.md
@@ -11,8 +11,7 @@ interface with the
[adafruit thermal printer used](https://www.adafruit.com/product/600).
## TODO
-- Better line formatting
-- Switch to Adafruit Thermal print library
+- Timer for the main function
- Stock Tracker
- Better error handling
- Test print page with ip address
diff --git a/ipqr.png b/ipqr.png
new file mode 100644
index 0000000..29e2582
--- /dev/null
+++ b/ipqr.png
Binary files differ
diff --git a/ipqr.py b/ipqr.py
index 33a4f94..27e522c 100644
--- a/ipqr.py
+++ b/ipqr.py
@@ -2,7 +2,7 @@ import pyqrcode
import socket
-def getIpAdress():
+def getIpAddress():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ipaddress = s.getsockname()[0]
@@ -10,7 +10,7 @@ def getIpAdress():
def getQrCode():
- ip = str(getIpAdress())
+ ip = f"http://{str(getIpAddress())}"
url = pyqrcode.create(ip)
- url.png('ipqr.png', scale=6) \ No newline at end of file
+ url.png('ipqr.png', scale=6)
diff --git a/main.py b/main.py
index 61f9374..f041408 100644
--- a/main.py
+++ b/main.py
@@ -2,9 +2,9 @@ from cal import getEventsFromCal
from natDay import getNationalDay
from news import getHeadlines
from quote import getQuote
-from weather import getForecast
+from weather import getHourlyForecast, getDetailedForecast
import datetime
-from settings import modules, general
+from settings import modules, general, lineWidth
from time import sleep
from Adafruit_Thermal import *
import textwrap
@@ -12,14 +12,14 @@ import textwrap
name = general["name"]
today = datetime.date.today().strftime("%A %m-%d-%Y")
printer = Adafruit_Thermal("/dev/ttyS0", 19200, timeout=5)
-lineWidth = 32
output = ["The Morning Paper:", f"Good Morning {name}, Today is {today}"]
mods = {
"quote": getQuote(),
"national day": getNationalDay(),
- "weather": getForecast(),
+ "Detailed": getDetailedForecast(),
+ "Hourly": getHourlyForecast(),
"calendar": getEventsFromCal(),
"news": getHeadlines()
}
@@ -33,11 +33,11 @@ def main():
printer.println(textwrap.fill(line, lineWidth))
printer.feed(1)
+
printer.wake()
printer.setSize('M')
sleep(10)
-
for line in output:
printer.println(textwrap.fill(line, lineWidth))
try:
diff --git a/requirements.txt b/requirements.txt
index 9482120..be6cf5a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,4 +4,5 @@ requests~=2.28.1
drawing~=0.0.3
setuptools~=56.0.0
Adafruit-Thermal
-recurring-ical-events \ No newline at end of file
+recurring-ical-events
+Pillow \ No newline at end of file
diff --git a/settings.json b/settings.json
index 47baca9..c934968 100644
--- a/settings.json
+++ b/settings.json
@@ -10,8 +10,6 @@
"gridY": 86,
"WFO": "PHI",
"Units": "si",
- "Detailed": 1,
- "Hourly": 1,
"Hours": 24
},
"news": {
@@ -20,11 +18,13 @@
"modules": {
"quote": 1,
"national day": 1,
- "weather": 1,
+ "Detailed": 1,
+ "Hourly": 1,
"calendar": 1,
"news": 0
},
"general": {
- "name": "Jacob"
+ "name": "Jacob",
+ "Line Width": 32
}
} \ No newline at end of file
diff --git a/settings.py b/settings.py
index 5e92981..af93b33 100644
--- a/settings.py
+++ b/settings.py
@@ -1,4 +1,8 @@
import json
+from main import printer
+from ipqr import getQrCode
+from PIL import Image
+from textwrap import fill
settingsJSON = open('settings.json')
@@ -9,7 +13,17 @@ weather = settings["weather"]
news = settings["news"]
modules = settings["modules"]
general = settings["general"]
+lineWidth = settings["general"]["Line Width"]
settingsJSON.close()
+def printSettingsPage():
+ printer.println("Settings")
+ try:
+ getQrCode()
+ qr = Image.open(r"ipqr.png")
+ printer.println(fill("Scan the QR Code below to access settings", lineWidth))
+ printer.printImage(qr)
+ except:
+ printer.println("No Network Connection")
diff --git a/weather.py b/weather.py
index 5996f77..45b9f41 100644
--- a/weather.py
+++ b/weather.py
@@ -8,44 +8,53 @@ gridX = weather["gridX"]
gridY = weather["gridY"]
wfo = weather["WFO"]
units = weather["Units"] # either si or us
-hourly = weather["Hourly"]
-detailed = weather["Detailed"]
hours = weather["Hours"]
-def getForecast():
+def getHourlyForecast():
output = []
- dayForecastUrl = f"https://api.weather.gov/gridpoints/{wfo}/{gridX},{gridY}/forecast?units={units}"
+
hourlyForecastUrl = f"https://api.weather.gov/gridpoints/{wfo}/{gridX},{gridY}/forecast/hourly?units={units}"
- dayResp = requests.get(dayForecastUrl)
hourResp = requests.get(hourlyForecastUrl)
- while (dayResp.status_code != 200) and (hourResp.status_code != 200):
- dayResp = requests.get(dayForecastUrl)
+ while hourResp.status_code != 200:
hourResp = requests.get(hourlyForecastUrl)
sleep(10)
- dayData = json.loads(dayResp.text)
hourData = json.loads(hourResp.text)
- dayPeriods = dayData["properties"]["periods"]
hourPeriods = hourData["properties"]["periods"]
+ output.append(f"{hours} Hour Forecast")
+ for i in range(hours):
+ forecast = hourPeriods[i]
+ sTime = datetime.strptime(forecast["startTime"], "%Y-%m-%dT%H:%M:%S%z")
+ formatTime = sTime.strftime("%m-%d %H:%M")
+ temp = str(forecast["temperature"]) + "°" + forecast["temperatureUnit"] + " " + forecast["shortForecast"]
+ hourlyForecast = f"{formatTime}: {temp}"
+ output.append(hourlyForecast)
+
+ return output
+
+
+def getDetailedForecast():
+ output = []
+
+ dayForecastUrl = f"https://api.weather.gov/gridpoints/{wfo}/{gridX},{gridY}/forecast?units={units}"
+ dayResp = requests.get(dayForecastUrl)
+
+ while dayResp.status_code != 200:
+ dayResp = requests.get(dayForecastUrl)
+ sleep(10)
+
+ dayData = json.loads(dayResp.text)
+ dayPeriods = dayData["properties"]["periods"]
+
todayFor = dayPeriods[0]
tonightFor = dayPeriods[1]
- if detailed:
- output.append("Today's Forecast: " + todayFor["detailedForecast"])
- output.append("\nTonight's Forecast: " + tonightFor["detailedForecast"] + "\n")
-
- if hourly:
- output.append(f"{hours} Hour Forecast")
- for i in range(hours):
- forecast = hourPeriods[i]
- sTime = datetime.strptime(forecast["startTime"], "%Y-%m-%dT%H:%M:%S%z")
- formatTime = sTime.strftime("%m-%d %H:%M")
- temp = str(forecast["temperature"]) + "°" + forecast["temperatureUnit"] + " " + forecast["shortForecast"]
- hourlyForecast = f"{formatTime}: {temp}"
- output.append(hourlyForecast)
+ output.append("Today's Forecast: " + todayFor["detailedForecast"])
+ output.append("\nTonight's Forecast: " + tonightFor["detailedForecast"] + "\n")
+
return output