From b2e6cdde266260a525ef80147dacbcd2ada3a985 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Mon, 31 Oct 2022 15:17:09 -0400 Subject: Better organization of code --- __pycache__/Adafruit_Thermal.cpython-310.pyc | Bin 0 -> 15299 bytes __pycache__/cal.cpython-310.pyc | Bin 0 -> 1333 bytes __pycache__/ipqr.cpython-310.pyc | Bin 0 -> 630 bytes __pycache__/natDay.cpython-310.pyc | Bin 0 -> 666 bytes __pycache__/news.cpython-310.pyc | Bin 0 -> 851 bytes __pycache__/quote.cpython-310.pyc | Bin 0 -> 603 bytes __pycache__/settings.cpython-310.pyc | Bin 0 -> 557 bytes __pycache__/weather.cpython-310.pyc | Bin 0 -> 1807 bytes cal.py | 3 ++- main.py | 6 +++++- news.py | 3 ++- settings.py | 18 +++++++++--------- weather.py | 3 ++- 13 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 __pycache__/Adafruit_Thermal.cpython-310.pyc create mode 100644 __pycache__/cal.cpython-310.pyc create mode 100644 __pycache__/ipqr.cpython-310.pyc create mode 100644 __pycache__/natDay.cpython-310.pyc create mode 100644 __pycache__/news.cpython-310.pyc create mode 100644 __pycache__/quote.cpython-310.pyc create mode 100644 __pycache__/settings.cpython-310.pyc create mode 100644 __pycache__/weather.cpython-310.pyc diff --git a/__pycache__/Adafruit_Thermal.cpython-310.pyc b/__pycache__/Adafruit_Thermal.cpython-310.pyc new file mode 100644 index 0000000..e5d720c Binary files /dev/null and b/__pycache__/Adafruit_Thermal.cpython-310.pyc differ diff --git a/__pycache__/cal.cpython-310.pyc b/__pycache__/cal.cpython-310.pyc new file mode 100644 index 0000000..14ff64d Binary files /dev/null and b/__pycache__/cal.cpython-310.pyc differ diff --git a/__pycache__/ipqr.cpython-310.pyc b/__pycache__/ipqr.cpython-310.pyc new file mode 100644 index 0000000..7a37ec8 Binary files /dev/null and b/__pycache__/ipqr.cpython-310.pyc differ diff --git a/__pycache__/natDay.cpython-310.pyc b/__pycache__/natDay.cpython-310.pyc new file mode 100644 index 0000000..cff9b88 Binary files /dev/null and b/__pycache__/natDay.cpython-310.pyc differ diff --git a/__pycache__/news.cpython-310.pyc b/__pycache__/news.cpython-310.pyc new file mode 100644 index 0000000..16bec00 Binary files /dev/null and b/__pycache__/news.cpython-310.pyc differ diff --git a/__pycache__/quote.cpython-310.pyc b/__pycache__/quote.cpython-310.pyc new file mode 100644 index 0000000..adcd0a8 Binary files /dev/null and b/__pycache__/quote.cpython-310.pyc differ diff --git a/__pycache__/settings.cpython-310.pyc b/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..78b5539 Binary files /dev/null and b/__pycache__/settings.cpython-310.pyc differ diff --git a/__pycache__/weather.cpython-310.pyc b/__pycache__/weather.cpython-310.pyc new file mode 100644 index 0000000..c9460a8 Binary files /dev/null and b/__pycache__/weather.cpython-310.pyc differ diff --git a/cal.py b/cal.py index 4f32465..348fa32 100644 --- a/cal.py +++ b/cal.py @@ -2,8 +2,9 @@ import icalendar import recurring_ical_events import urllib.request import datetime -from settings import calendars +from settings import getSettings +calendars = getSettings("calendars") today = datetime.date.today() output = [] diff --git a/main.py b/main.py index 6df9aef..4d2f61c 100644 --- a/main.py +++ b/main.py @@ -4,13 +4,17 @@ from news import getHeadlines from quote import getQuote from weather import getHourlyForecast, getDetailedForecast import datetime -from settings import modules, general, lineWidth +from settings import getSettings from time import sleep from Adafruit_Thermal import * from textwrap import fill from ipqr import getQrCode +general = getSettings("general") +modules = getSettings("modules") + name = general["name"] +lineWidth = general["Line Width"] today = datetime.date.today().strftime("%A %m-%d-%Y") printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) diff --git a/news.py b/news.py index e9afeab..cdec011 100644 --- a/news.py +++ b/news.py @@ -1,8 +1,9 @@ import requests import json from time import sleep -from settings import news +from settings import getSettings +news = getSettings("news") apiKey = news["apikey"] countryCode = news["country"] diff --git a/settings.py b/settings.py index c5ed5c7..e94dbe2 100644 --- a/settings.py +++ b/settings.py @@ -1,14 +1,14 @@ import json +from logging import exception -settingsJSON = open('settings.json') +def getSettings(settingSection): + try: + settingsJSON = open("settings.json", "r") + except FileNotFoundError: + exception("settings.json not found make sure it exists in this folder") -settings = json.load(settingsJSON) + settings = json.load(settingsJSON) + settingsJSON.close() -calendars = settings["calendars"] -weather = settings["weather"] -news = settings["news"] -modules = settings["modules"] -general = settings["general"] -lineWidth = settings["general"]["Line Width"] + return settings[settingSection] -settingsJSON.close() diff --git a/weather.py b/weather.py index 72323fc..76af11a 100644 --- a/weather.py +++ b/weather.py @@ -2,8 +2,9 @@ import requests import json from time import sleep from datetime import datetime -from settings import weather +from settings import getSettings +weather = getSettings("weather") gridX = weather["gridX"] gridY = weather["gridY"] wfo = weather["WFO"] -- cgit v1.2.3