Skip to content

Commit

Permalink
update image OS
Browse files Browse the repository at this point in the history
  • Loading branch information
ARC-MX committed Dec 29, 2024
1 parent 9975f7a commit 2ae2061
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
inputs:
username:
description: 'version of this branch'
default: 'v1.6.0'
default: 'v1.6.1'
required: true
type: string
paths:
Expand Down
35 changes: 0 additions & 35 deletions Dockerfile

This file was deleted.

22 changes: 2 additions & 20 deletions Dockerfile-for-github-action
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM python:3.9.19-slim-bullseye as build
FROM python:3.11.11-slim-bookworm as build

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

ARG TARGETARCH
ARG VERSION
ENV VERSION=${VERSION}
ENV PYTHON_IN_DOCKER='PYTHON_IN_DOCKER'

COPY scripts/* /app/
WORKDIR /app
Expand All @@ -17,25 +18,6 @@ RUN apt-get --allow-releaseinfo-change update \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

# RUN cd /tmp \
# && python3 -m pip install --upgrade pip \
# && echo '#!/bin/bash\n \
# if [ "$TARGETARCH" = "arm" ]; then\n \
# cd /tmp\n \
# curl -O -L https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/numpy-1.23.5-cp39-cp39-linux_armv7l.whl\n \
# curl -v -o onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl https://github.com/nknytk/built-onnxruntime-for-raspberrypi-linux/blob/master/wheels/bullseye/onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl\n \
# PIP_ROOT_USER_ACTION=ignore pip3 install numpy-1.23.5-cp39-cp39-linux_armv7l.whl\n \
# PIP_ROOT_USER_ACTION=ignore pip3 install onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl\n \
# else\n \
# cd /tmp\n \
# PIP_ROOT_USER_ACTION=ignore pip3 install numpy==1.23.5 onnxruntime==1.17.3 \n \
# fi \n' > ./targetArch.sh \
# && bash ./targetArch.sh \
# && rm -rf /tmp/* \
# && pip cache purge \
# && rm -rf /var/lib/apt/lists/* \
# && rm -rf /var/log/*

COPY ./requirements.txt /tmp/requirements.txt

RUN cd /tmp \
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- CONTAINER_TIMEZONE=Asia/Shanghai
restart: unless-stopped
# volumes:
# - ./:/app/homeassistant.db # if you want to read homeassistant.db
# - ./:/data # if you want to read homeassistant.db, homeassistant.db is in the container at /data/
command: python3 main.py

networks:
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
requests==2.31.0
selenium==4.5.0
schedule==1.1.0
Pillow==9.2.0
undetected_chromedriver==3.4.7
onnxruntime==1.17.3
numpy==1.24.3
selenium==4.19.0
schedule==1.2.1
Pillow==10.1.0
undetected_chromedriver==3.5.4
onnxruntime==1.18.1
numpy==1.26.2
python-dotenv
python-dateutil
65 changes: 36 additions & 29 deletions scripts/data_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def connect_user_db(self, user_id):
try:
# 创建数据库
DB_NAME = os.getenv("DB_NAME", "homeassistant.db")
if 'PYTHON_IN_DOCKER' in os.environ:
DB_NAME = "/data/" + DB_NAME
self.connect = sqlite3.connect(DB_NAME)
self.connect.cursor()
logging.info(f"Database of {DB_NAME} created successfully.")
Expand All @@ -174,17 +176,20 @@ def connect_user_db(self, user_id):
# 如果表已存在,则不会创建
except sqlite3.Error as e:
logging.debug(f"Create db or Table error:{e}")
finally:
return self.connect
return False
return True

def insert_data(self, data:dict):
# 创建索引
try:
sql = f"INSERT OR REPLACE INTO {self.table_name} VALUES(strftime('%Y-%m-%d','{data['date']}'),{data['usage']});"
self.connect.execute(sql)
self.connect.commit()
except BaseException as e:
logging.debug(f"Data update failed: {e}")
if self.connect is None:
logging.error("Database connection is not established.")
return
# 创建索引
try:
sql = f"INSERT OR REPLACE INTO {self.table_name} VALUES(strftime('%Y-%m-%d','{data['date']}'),{data['usage']});"
self.connect.execute(sql)
self.connect.commit()
except BaseException as e:
logging.debug(f"Data update failed: {e}")

def _get_webdriver(self):
chrome_options = Options()
Expand Down Expand Up @@ -216,7 +221,7 @@ def _login(self, driver, phone_code = False):
self._click_button(driver, By.XPATH, '//*[@id="login_box"]/div[1]/div[1]/div[3]/span')
input_elements = driver.find_elements(By.CLASS_NAME, "el-input__inner")
input_elements[2].send_keys(self._username)
logging.info(f"input_elements username : {self._username}.\r")
logging.info(f"input_elements username : {self._username}\r")
self._click_button(driver, By.XPATH, '//*[@id="login_box"]/div[2]/div[2]/form/div[1]/div[2]/div[2]/div/a')
code = input("Input your phone verification code: ")
input_elements[3].send_keys(code)
Expand All @@ -231,9 +236,9 @@ def _login(self, driver, phone_code = False):
# input username and password
input_elements = driver.find_elements(By.CLASS_NAME, "el-input__inner")
input_elements[0].send_keys(self._username)
logging.info(f"input_elements username : {self._username}.\r")
logging.info(f"input_elements username : {self._username}\r")
input_elements[1].send_keys(self._password)
logging.info(f"input_elements password : {self._password}.\r")
logging.info(f"input_elements password : {self._password}\r")

# click login button
self._click_button(driver, By.CLASS_NAME, "el-button.el-button--primary")
Expand Down Expand Up @@ -540,23 +545,25 @@ def save_daily_usage_data(self, driver, user_id):
"//*[@id='pane-second']/div[2]/div[2]/div[1]/div[3]/table/tbody/tr") # 用电量值列表

# 连接数据库集合
self.connect_user_db(user_id)

# 将用电量保存为字典
for i in days_element:
day = i.find_element(By.XPATH, "td[1]/div").text
usage = i.find_element(By.XPATH, "td[2]/div").text
if usage != "":
dic = {'date': day, 'usage': float(usage)}
# 插入到数据库
try:
self.insert_data(dic)
logging.info(f"The electricity consumption of {usage}KWh on {day} has been successfully deposited into the database")
except Exception as e:
logging.debug(f"The electricity consumption of {day} failed to save to the database, which may already exist: {str(e)}")
else:
logging.info(f"The electricity consumption of {usage} get nothing")
self.connect.close()
if self.connect_user_db(user_id):
# 将用电量保存为字典
for i in days_element:
day = i.find_element(By.XPATH, "td[1]/div").text
usage = i.find_element(By.XPATH, "td[2]/div").text
if usage != "":
dic = {'date': day, 'usage': float(usage)}
# 插入到数据库
try:
self.insert_data(dic)
logging.info(f"The electricity consumption of {usage}KWh on {day} has been successfully deposited into the database")
except Exception as e:
logging.debug(f"The electricity consumption of {day} failed to save to the database, which may already exist: {str(e)}")
else:
logging.info(f"The electricity consumption of {usage} get nothing")
self.connect.close()
else:
logging.info("The database creation failed and the data was not written correctly.")
return

if __name__ == "__main__":
with open("bg.jpg", "rb") as f:
Expand Down
84 changes: 0 additions & 84 deletions test.yaml

This file was deleted.

0 comments on commit 2ae2061

Please sign in to comment.