From fc496845f27292fc4fa467ea2db9d68f0370f1e3 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Sat, 1 Oct 2022 11:10:24 -0400 Subject: Forced Pycharm to use Tabs instead of Spaces --- README.md | 2 +- __pycache__/Adafruit_Thermal.cpython-39.pyc | Bin 0 -> 15579 bytes __pycache__/ipqr.cpython-39.pyc | Bin 0 -> 627 bytes __pycache__/settings.cpython-39.pyc | Bin 378 -> 415 bytes __pycache__/weather.cpython-39.pyc | Bin 1604 -> 1756 bytes ipqr.py | 15 ++++--- main.py | 46 ++++++++++----------- news.py | 26 ++++++------ weather.py | 61 ++++++++++++++-------------- 9 files changed, 74 insertions(+), 76 deletions(-) create mode 100644 __pycache__/Adafruit_Thermal.cpython-39.pyc create mode 100644 __pycache__/ipqr.cpython-39.pyc diff --git a/README.md b/README.md index 7468a79..496ddb0 100644 --- a/README.md +++ b/README.md @@ -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 new file mode 100644 index 0000000..4a5e00b Binary files /dev/null and b/__pycache__/Adafruit_Thermal.cpython-39.pyc differ diff --git a/__pycache__/ipqr.cpython-39.pyc b/__pycache__/ipqr.cpython-39.pyc new file mode 100644 index 0000000..b64b294 Binary files /dev/null and b/__pycache__/ipqr.cpython-39.pyc differ diff --git a/__pycache__/settings.cpython-39.pyc b/__pycache__/settings.cpython-39.pyc index 5dade3b..760b11a 100644 Binary files a/__pycache__/settings.cpython-39.pyc and b/__pycache__/settings.cpython-39.pyc differ diff --git a/__pycache__/weather.cpython-39.pyc b/__pycache__/weather.cpython-39.pyc index 8c751b5..13ed610 100644 Binary files a/__pycache__/weather.cpython-39.pyc and b/__pycache__/weather.cpython-39.pyc differ diff --git a/ipqr.py b/ipqr.py index 27e522c..2e8b253 100644 --- a/ipqr.py +++ b/ipqr.py @@ -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) diff --git a/main.py b/main.py index b3abe87..6df9aef 100644 --- a/main.py +++ b/main.py @@ -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() diff --git a/news.py b/news.py index 28bb374..6c486c5 100644 --- a/news.py +++ b/news.py @@ -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 diff --git a/weather.py b/weather.py index 45b9f41..72323fc 100644 --- a/weather.py +++ b/weather.py @@ -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 -- cgit v1.2.3