summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@turin.home>2022-01-30 14:01:55 +0000
committerroot <root@turin.home>2022-01-30 14:01:55 +0000
commitafdc48378489d1ce1183dfd720fd838074812a49 (patch)
tree2e4cb3663212694aa6fe64be35c9ecff575e30c7
parentb6698810b9ff40a2d91b71c61017667642db212a (diff)
Reformatting. Adding things to date.py
-rw-r--r--Makefile2
-rw-r--r--circular_queue.py3
-rw-r--r--date.py7
-rw-r--r--heating.py33
-rw-r--r--main.py8
-rw-r--r--queue-test.py5
-rw-r--r--static/style.css13
-rw-r--r--weather.py16
8 files changed, 65 insertions, 22 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..23fb4f7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+default:
+ black -l 70 *py
diff --git a/circular_queue.py b/circular_queue.py
index 6b36748..26f61a2 100644
--- a/circular_queue.py
+++ b/circular_queue.py
@@ -11,6 +11,7 @@ class circular_queue:
self.pointer += 1
if self.pointer >= self.size:
self.pointer = 0
+
def average(self):
value = 0
length = 0
@@ -20,4 +21,4 @@ class circular_queue:
length += 1
if length == 0:
return 0
- return value / length
+ return value / length
diff --git a/date.py b/date.py
index d04d76a..43aac8a 100644
--- a/date.py
+++ b/date.py
@@ -1,10 +1,13 @@
import time
from datetime import datetime
+
class date:
def __init__():
pass
+
def day():
- int(datetime.now().strftime('%Y%m%d'))
+ int(datetime.now().strftime("%Y%m%d"))
+
def time():
- int(datetime.now().strftime('%H%M%S'))
+ int(datetime.now().strftime("%H%M%S"))
diff --git a/heating.py b/heating.py
index 757f877..42401ad 100644
--- a/heating.py
+++ b/heating.py
@@ -69,9 +69,11 @@ class heating(ABC):
# overriding abstract methods from heating class
class rpi_heating(heating):
def __init__(self, db):
- # https://tutorials-raspberrypi.com/raspberry-pi-control-relay-switch-via-gpio/
+ # https://tutorials-raspberrypi.com/raspberry-pi-control-relay
+ # -switch-via-gpio/
# https://www.ics.com/blog/gpio-programming-using-sysfs-interface
- # https://medium.com/initial-state/how-to-build-a-raspberry-pi-temperature-monitor-8c2f70acaea9
+ # https://medium.com/initial-state/how-to-build-a-raspberry-
+ # pi-temperature-monitor-8c2f70acaea9
# run init from super class
super().__init__(db)
@@ -82,21 +84,36 @@ class rpi_heating(heating):
# setup GPIO for the relay
- os.system("echo {} >/sys/class/gpio/export".format(self.RELAY))
- os.system("echo out >/sys/class/gpio/gpio{}/direction".format(self.RELAY))
+ os.system(
+ "echo {} >/sys/class/gpio/export".format(self.RELAY)
+ )
+ os.system(
+ "echo out >/sys/class/gpio/gpio{}/direction".format(
+ self.RELAY
+ )
+ )
# file that the temperature gets written t
- self.sensor = "/sys/bus/w1/devices/{}/w1_slave".format(self.SENSORID)
+ self.sensor = "/sys/bus/w1/devices/{}/w1_slave".format(
+ self.SENSORID
+ )
def turn_on(self):
# turn the heating on by triggering the relay
- os.system("echo 1 >/sys/class/gpio/gpio{}/value".format(self.RELAY))
+ os.system(
+ "echo 1 >/sys/class/gpio/gpio{}/value".format(self.RELAY)
+ )
def turn_off(self):
# turn the heating off by triggering the relay
- os.system("echo 0 >/sys/class/gpio/gpio{}/value".format(self.RELAY))
+ os.system(
+ "echo 0 >/sys/class/gpio/gpio{}/value".format(self.RELAY)
+ )
def get_temperature(self):
with open(self.sensor, "r") as file:
data = file.read()
# parse temperature from file
- return float(data.split("\n")[1].split(" ")[9].split("=")[1]) / 1000
+ return (
+ float(data.split("\n")[1].split(" ")[9].split("=")[1])
+ / 1000
+ )
diff --git a/main.py b/main.py
index a74baaf..7cfa088 100644
--- a/main.py
+++ b/main.py
@@ -52,13 +52,13 @@ def index():
@app.route("/up")
def form():
boiler.up()
- return redirect(url_for('index'))
+ return redirect(url_for("index"))
@app.route("/down")
def activity():
boiler.down()
- return redirect(url_for('index'))
+ return redirect(url_for("index"))
@app.route("/export")
@@ -73,7 +73,9 @@ def export(opt):
elif opt == "pdf":
pass
else:
- return render_template("error.html", error="Invalid export type")
+ return render_template(
+ "error.html", error="Invalid export type"
+ )
def updater():
diff --git a/queue-test.py b/queue-test.py
index 131c2c5..b0ce02c 100644
--- a/queue-test.py
+++ b/queue-test.py
@@ -13,6 +13,7 @@ def test_queue_average_null():
a = circular_queue(50)
assert a.average() == 0
+
def test_queue_average_size():
a = circular_queue(50)
print(len(a.queue))
@@ -20,9 +21,9 @@ def test_queue_average_size():
print(len(a.queue))
assert len(a.queue) == 50
+
def test_queue_circle():
a = circular_queue(20)
- for i in range(0,2000):
+ for i in range(0, 2000):
a.add(1)
assert a.average() == 1
-
diff --git a/static/style.css b/static/style.css
index e69de29..68ebec7 100644
--- a/static/style.css
+++ b/static/style.css
@@ -0,0 +1,13 @@
+html {
+ line-height: 1.5;
+ font-family: monospace;
+ color: #1a1a1a;
+ background-color: #fdfdfd;
+}
+@media (prefers-color-scheme: dark){
+ body {color:white;background:black}
+ html {color:white;background:black}
+ a:link, a:visited { color: #aab9c1; }
+ a:hover, a:active { color: hotpink; } /* hotpink on hover */
+}
+
diff --git a/weather.py b/weather.py
index 1163dc2..c7276fe 100644
--- a/weather.py
+++ b/weather.py
@@ -24,11 +24,15 @@ class weather_met_no(weather):
# constant for api request when getting data
# uses Norweigen Meterological Institute api
# -- todo : reference
- self.CALL = "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat={}&lon={}".format(
- self.LOCATION[0], self.LOCATION[1]
+ self.CALL = (
+ "https://api.met.no/weatherapi/locationforecast/"
+ + "2.0/compact?lat={}&lon={}".format(
+ self.LOCATION[0], self.LOCATION[1]
+ )
)
# acceptable header for the API
- # https://stackoverflow.com/questions/10606133/sending-user-agent-using-requests-library-in-python
+ # https://stackoverflow.com/questions/10606133/
+ # sending-user-agent-using-requests-library-in-python
# https://api.met.no/doc/FAQ
self.HEADERS = {"User-Agent": "TopologicalMap"}
super.init(self)
@@ -36,9 +40,9 @@ class weather_met_no(weather):
def get_temperature(self):
# https://docs.python-requests.org/en/latest/
try:
- data = requests.get(self.CALL, headers=self.HEADERS).json()["properties"][
- "timeseries"
- ][0]["data"]
+ data = requests.get(
+ self.CALL, headers=self.HEADERS
+ ).json()["properties"]["timeseries"][0]["data"]
return data["instant"]["details"]["air_temperature"]
# data['next_1_hours']['summary']['symbol_code']
except: