diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | __pycache__/Adafruit_Thermal.cpython-39.pyc | bin | 0 -> 15579 bytes | |||
| -rw-r--r-- | __pycache__/ipqr.cpython-39.pyc | bin | 0 -> 627 bytes | |||
| -rw-r--r-- | __pycache__/settings.cpython-39.pyc | bin | 378 -> 415 bytes | |||
| -rw-r--r-- | __pycache__/weather.cpython-39.pyc | bin | 1604 -> 1756 bytes | |||
| -rw-r--r-- | ipqr.py | 15 | ||||
| -rw-r--r-- | main.py | 46 | ||||
| -rw-r--r-- | news.py | 26 | ||||
| -rw-r--r-- | weather.py | 61 |
9 files changed, 74 insertions, 76 deletions
@@ -16,7 +16,7 @@ interface with the - Better error handling - Test print page with ip address - Web interface for settings - - Settings print out with qr code to ip address + ~~- Settings print out with qr code to ip address~~ - Fix the Phantom j ## Parts diff --git a/__pycache__/Adafruit_Thermal.cpython-39.pyc b/__pycache__/Adafruit_Thermal.cpython-39.pyc Binary files differnew file mode 100644 index 0000000..4a5e00b --- /dev/null +++ b/__pycache__/Adafruit_Thermal.cpython-39.pyc diff --git a/__pycache__/ipqr.cpython-39.pyc b/__pycache__/ipqr.cpython-39.pyc Binary files differnew file mode 100644 index 0000000..b64b294 --- /dev/null +++ b/__pycache__/ipqr.cpython-39.pyc diff --git a/__pycache__/settings.cpython-39.pyc b/__pycache__/settings.cpython-39.pyc Binary files differindex 5dade3b..760b11a 100644 --- a/__pycache__/settings.cpython-39.pyc +++ b/__pycache__/settings.cpython-39.pyc diff --git a/__pycache__/weather.cpython-39.pyc b/__pycache__/weather.cpython-39.pyc Binary files differindex 8c751b5..13ed610 100644 --- a/__pycache__/weather.cpython-39.pyc +++ b/__pycache__/weather.cpython-39.pyc @@ -3,14 +3,13 @@ import socket def getIpAddress(): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(("8.8.8.8", 80)) - ipaddress = s.getsockname()[0] - return ipaddress + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("8.8.8.8", 80)) + ipaddress = s.getsockname()[0] + return ipaddress def getQrCode(): - ip = f"http://{str(getIpAddress())}" - url = pyqrcode.create(ip) - - url.png('ipqr.png', scale=6) + ip = f"http://{str(getIpAddress())}" + url = pyqrcode.create(ip) + url.png('ipqr.png', scale=6) @@ -17,32 +17,32 @@ printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) output = ["The Morning Paper:", f"Good Morning {name}, Today is {today}"] mods = { - "quote": getQuote(), - "national day": getNationalDay(), - "Detailed": getDetailedForecast(), - "Hourly": getHourlyForecast(), - "calendar": getEventsFromCal(), - "news": getHeadlines() + "quote": getQuote(), + "national day": getNationalDay(), + "Detailed": getDetailedForecast(), + "Hourly": getHourlyForecast(), + "calendar": getEventsFromCal(), + "news": getHeadlines() } def main(): - for module in modules: - if modules[module]: - for line in mods[module]: - line = line.replace("\n", "") - printer.println(fill(line, lineWidth)) - printer.feed(1) + for module in modules: + if modules[module]: + for line in mods[module]: + line = line.replace("\n", "") + printer.println(fill(line, lineWidth)) + printer.feed(1) def printSettingsPage(): - printer.println("Settings") - try: - getQrCode() - printer.println(fill("Scan the QR Code below to access settings", lineWidth)) - printer.printImage("ipqr.png") - except: - printer.println("No Network Connection") + printer.println("Settings") + try: + getQrCode() + printer.println(fill("Scan the QR Code below to access settings", lineWidth)) + printer.printImage("ipqr.png") + except: + printer.println("No Network Connection") printer.wake() @@ -50,12 +50,12 @@ printer.setSize('M') sleep(10) for line in output: - printer.println(fill(line, lineWidth)) + printer.println(fill(line, lineWidth)) try: - main() + main() except: - sleep(30) - main() + sleep(30) + main() printSettingsPage() @@ -10,21 +10,21 @@ url = f"https://newsapi.org/v2/top-headlines?country={countryCode}&apiKey={apiKe def getHeadlines(): - resp = requests.get(url) - while resp.status_code != 200: - resp = requests.get(url) - sleep(10) + resp = requests.get(url) + while resp.status_code != 200: + resp = requests.get(url) + sleep(10) - respData = json.loads(resp.text) + respData = json.loads(resp.text) - articles = respData["articles"] + articles = respData["articles"] - output = ["Top 5 Headlines in the US:"] + output = ["Top 5 Headlines in the US:"] - for i in range(5): - article = articles[i] - title = article["title"] - output.append(title) - output.append("\n") + for i in range(5): + article = articles[i] + title = article["title"] + output.append(title) + output.append("\n") - return output + return output @@ -12,49 +12,48 @@ hours = weather["Hours"] def getHourlyForecast(): - output = [] + output = [] + hourlyForecastUrl = f"https://api.weather.gov/gridpoints/{wfo}/{gridX},{gridY}/forecast/hourly?units={units}" - hourlyForecastUrl = f"https://api.weather.gov/gridpoints/{wfo}/{gridX},{gridY}/forecast/hourly?units={units}" + hourResp = requests.get(hourlyForecastUrl) - hourResp = requests.get(hourlyForecastUrl) + while hourResp.status_code != 200: + hourResp = requests.get(hourlyForecastUrl) + sleep(10) - while hourResp.status_code != 200: - hourResp = requests.get(hourlyForecastUrl) - sleep(10) + hourData = json.loads(hourResp.text) + hourPeriods = hourData["properties"]["periods"] - hourData = json.loads(hourResp.text) - 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) - 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 + return output def getDetailedForecast(): - output = [] + output = [] - dayForecastUrl = f"https://api.weather.gov/gridpoints/{wfo}/{gridX},{gridY}/forecast?units={units}" - dayResp = requests.get(dayForecastUrl) + 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) + while dayResp.status_code != 200: + dayResp = requests.get(dayForecastUrl) + sleep(10) - dayData = json.loads(dayResp.text) - dayPeriods = dayData["properties"]["periods"] + dayData = json.loads(dayResp.text) + dayPeriods = dayData["properties"]["periods"] - todayFor = dayPeriods[0] - tonightFor = dayPeriods[1] + todayFor = dayPeriods[0] + tonightFor = dayPeriods[1] - output.append("Today's Forecast: " + todayFor["detailedForecast"]) - output.append("\nTonight's Forecast: " + tonightFor["detailedForecast"] + "\n") + output.append("Today's Forecast: " + todayFor["detailedForecast"]) + output.append("\nTonight's Forecast: " + tonightFor["detailedForecast"] + "\n") - return output + return output |
