Skip to content

Commit

Permalink
remove Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ARC-MX committed Jan 5, 2025
1 parent 4e3202c commit 4a6e6c6
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
inputs:
version:
description: 'version of this branch'
default: 'v1.6.3'
default: 'v1.6.4'
required: true
type: string
paths:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
else
TAG_ARCH=$ARCH
fi
docker buildx build --build-arg VERSION=${VERSION} --platform linux/${ARCH} -t ${DOCKER_IMAGE}-${TAG_ARCH}:latest -t ${DOCKER_IMAGE}-${TAG_ARCH}:${VERSION} -t ${DOCKER_IMAGE}:latest-${ARCH} -t ${DOCKER_IMAGE}:${VERSION}-${ARCH} --file Dockerfile-for-github-action --push .
docker buildx build --build-arg VERSION=${VERSION} --platform linux/${ARCH} -t ${DOCKER_IMAGE}-${TAG_ARCH}:latest -t ${DOCKER_IMAGE}-${TAG_ARCH}:${VERSION} --file Dockerfile-for-github-action --push .
done
- name: Log into Aliyun hub registry and push Docker image
Expand All @@ -62,5 +62,5 @@ jobs:
else
TAG_ARCH=$ARCH
fi
docker buildx build --build-arg VERSION=${VERSION} --platform linux/${ARCH} -t ${DOCKER_IMAGE}-${TAG_ARCH}:latest -t ${DOCKER_IMAGE}-${TAG_ARCH}:${VERSION} -t ${DOCKER_IMAGE}:latest-${ARCH} -t ${DOCKER_IMAGE}:${VERSION}-${ARCH} --file Dockerfile-for-github-action --push .
docker buildx build --build-arg VERSION=${VERSION} --platform linux/${ARCH} -t ${DOCKER_IMAGE}-${TAG_ARCH}:latest -t ${DOCKER_IMAGE}-${TAG_ARCH}:${VERSION} --file Dockerfile-for-github-action --push .
done
7 changes: 0 additions & 7 deletions Dockerfile

This file was deleted.

35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@

1. 在homeassistant以实体显示:

| 实体entity_id | 说明 |
| -------------------------------------- | --------------------------------------------------------------------- |
| sensor.last_electricity_usage_xxxx | 最近一天用电量,单位KWH、度。属性含present_date(查询电量代表的日期) |
| sensor.electricity_charge_balance_xxxx | 预付费显示电费余额,反之显示上月应交电费,单位元 |
| sensor.yearly_electricity_usage_xxxx | 今年总用电量,单位KWH、度。 |
| sensor.yearly_electricity_charge_xxxx | 今年总用电费用,单位元 |
| 实体entity_id | 说明 |
| -------------------------------------- | ----------------------------------------------------------------------- |
| sensor.last_electricity_usage_xxxx | 最近一天用电量,单位KWH、度。属性含present_date(查询电量代表的日期) |
| sensor.electricity_charge_balance_xxxx | 预付费显示电费余额,反之显示上月应交电费,单位元 |
| sensor.yearly_electricity_usage_xxxx | 今年总用电量,单位KWH、度。 |
| sensor.yearly_electricity_charge_xxxx | 今年总用电费用,单位元 |
| sensor.month_electricity_usage_xxxx | 最近一个月用电量,单位KWH、度。属性含present_date(查询电量代表的日期) |
| sensor.month_electricity_charge_xxxx | 上月总用电费用,单位元 属性含present_date(查询电量代表的日期) |
| sensor.month_electricity_charge_xxxx | 上月总用电费用,单位元 属性含present_date(查询电量代表的日期) |
2. 可选,近三十天每日用电量数据(SQLite数据库)
数据库表名为 daily+userid ,在项目路径下有个homeassistant.db 的数据库文件就是;
如需查询可以用
Expand Down Expand Up @@ -123,22 +123,11 @@ HASS_URL="http://localhost:8123/"
HASS_TOKEN="eyxxxxx"

## selenium运行参数
# 任务开始时间,24小时制,例如"07:00"则为每天早上7点执行,第一次启动程序如果时间晚于早上7点则会立即执行一次,每隔12小时执行一次。
# 任务开始时间,24小时制,例如"07:00则为每天早上7点执行,第一次启动程序如果时间晚于早上7点则会立即执行一次,每隔12小时执行一次。
JOB_START_TIME="07:00"
# 每次操作等待时间,推荐设定范围为[2,30],该值表示每次点击网页后所要等待数据加载的时间,如果出现“no such element”诸如此类的错误可适当调大该值,如果硬件性能较好可以适当调小该值
RETRY_WAIT_TIME_OFFSET_UNIT=15

## 其他默认参数
# 浏览器默认等待时间,秒。
DRIVER_IMPLICITY_WAIT_TIME=60
# 登录重试次数
RETRY_TIMES_LIMIT=5
# 登录超时时间,秒
LOGIN_EXPECTED_TIME=60
RETRY_WAIT_TIME_OFFSET_UNIT=10


## 日志级别
# 例如“DUBUG”可以查看出错情况
LOG_LEVEL="INFO"

## 记录的天数, 仅支持填写 7 或 30
# 国网原本可以记录 30 天,现在不开通智能缴费只能查询 7 天造成错误
Expand Down Expand Up @@ -395,11 +384,13 @@ type: vertical-stack
2024-07-03:新增每天定时执行两次,添加配置默认增加近 7 天每日电量写入数据, 可修改为 30 天。
2024-07-05:新增余额不足提醒功能。
2024-12-10:新增忽略指定用户ID的功能:针对一些用户拥有充电或者发电账户,可以使用 IGNORE_USER_ID 环境变量忽略特定的ID。
2025-01-05:新增Homeassistant Add-on部署方式。
TO-DO
- [X] 增加离线滑动验证码识别方案
- [X] 添加默认推送服务,电费余额不足提醒
- [ ] 。。。
- [X] 添加Homeassistant Add-on安装方式,在此感谢[Ami8834671](https://github.com/Ami8834671), [DuanXDong](https://github.com/DuanXDong)等小伙伴的idea和贡献
- [ ] 添加置Homeassistant integration
## **技术交流群**
Expand Down
6 changes: 0 additions & 6 deletions build.yaml

This file was deleted.

5 changes: 2 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "SGCC Electricity"
version: "v0.1.0"
version: "v1.6.4"
slug: "sgcc_electricity"
description: "获取国网电费数据的插件"
url: "https://github.com/ARC-MX/sgcc_electricity_new"
Expand All @@ -10,7 +10,7 @@ host_network: true
startup: application
boot: auto
init: false
# image: "registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity-{arch}"
image: "registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity-{arch}"
map:
- config:rw
options:
Expand All @@ -37,7 +37,6 @@ schema:
HASS_TOKEN: str
JOB_START_TIME: str
RETRY_WAIT_TIME_OFFSET_UNIT: int(2,30)
LOG_LEVEL: str
DATA_RETENTION_DAYS: int
RECHARGE_NOTIFY: bool
BALANCE: float
Expand Down
2 changes: 1 addition & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HASS_TOKEN="eyxxxxx"
## selenium运行参数
# 任务开始时间,24小时制,例如"07:00”则为每天早上7点执行,第一次启动程序如果时间晚于早上7点则会立即执行一次,每隔12小时执行一次。
JOB_START_TIME="07:00"
# 每次操作等待时间,如果硬件性能比较高,可以适当调小该值
# 每次操作等待时间,推荐设定范围为[2,30],该值表示每次点击网页后所要等待数据加载的时间,如果出现“no such element”诸如此类的错误可适当调大该值,如果硬件性能较好可以适当调小该值
RETRY_WAIT_TIME_OFFSET_UNIT=15


Expand Down
46 changes: 0 additions & 46 deletions run.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/data_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ def _save_user_data(self, user_id, balance, last_daily_date, last_daily_usage, d
self.insert_expand_data(dic)
dic = {'name': f"{month[index]}charge", 'value': f"{month_charge[index]}"}
self.insert_expand_data(dic)
logging.info(f"Get month power charge for {user_id} successfully, {month[index]} usage is {month_usage[index]} KWh, charge is {month_charge[index]} CNY.")
except Exception as e:
logging.debug(f"The electricity consumption of {month[index]} failed to save to the database, which may already exist: {str(e)}")
if month_charge:
Expand Down
33 changes: 20 additions & 13 deletions scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@ def main():
# 读取 .env 文件
import dotenv
dotenv.load_dotenv(verbose=True)
try:
PHONE_NUMBER = os.getenv("PHONE_NUMBER")
PASSWORD = os.getenv("PASSWORD")
HASS_URL = os.getenv("HASS_URL")
JOB_START_TIME = os.getenv("JOB_START_TIME","07:00" )
LOG_LEVEL = os.getenv("LOG_LEVEL","INFO")
VERSION = os.getenv("VERSION")
RETRY_TIMES_LIMIT = int(os.getenv("RETRY_TIMES_LIMIT", 5))
except Exception as e:
logging.error(f"Failing to read the .env file, the program will exit with an error message: {e}.")
sys.exit()
else:
if os.path.isfile('/data/options.json'):
with open('/data/options.json') as f:
options = json.load(f)
try:
Expand All @@ -38,6 +27,8 @@ def main():
LOG_LEVEL = options.get("LOG_LEVEL", "INFO")
VERSION = os.getenv("VERSION")
RETRY_TIMES_LIMIT = int(options.get("RETRY_TIMES_LIMIT", 5))

logger_init(LOG_LEVEL)
os.environ["HASS_URL"] = options.get("HASS_URL", "http://homeassistant.local:8123/")
os.environ["HASS_TOKEN"] = options.get("HASS_TOKEN", "")
os.environ["ENABLE_DATABASE_STORAGE"] = str(options.get("ENABLE_DATABASE_STORAGE", "false")).lower()
Expand All @@ -51,10 +42,26 @@ def main():
os.environ["RECHARGE_NOTIFY"] = str(options.get("RECHARGE_NOTIFY", "false")).lower()
os.environ["BALANCE"] = str(options.get("BALANCE", 5.0))
os.environ["PUSHPLUS_TOKEN"] = options.get("PUSHPLUS_TOKEN", "")
logging.info(f"当前以Homeassistant Add-on 形式运行.")
except Exception as e:
logging.error(f"Failing to read the options.json file, the program will exit with an error message: {e}.")
sys.exit()
logger_init(LOG_LEVEL)
else:
try:
PHONE_NUMBER = os.getenv("PHONE_NUMBER")
PASSWORD = os.getenv("PASSWORD")
HASS_URL = os.getenv("HASS_URL")
JOB_START_TIME = os.getenv("JOB_START_TIME","07:00" )
LOG_LEVEL = os.getenv("LOG_LEVEL","INFO")
VERSION = os.getenv("VERSION")
RETRY_TIMES_LIMIT = int(os.getenv("RETRY_TIMES_LIMIT", 5))

logger_init(LOG_LEVEL)
logging.info(f"The current run runs as a docker image.")
except Exception as e:
logging.error(f"Failing to read the .env file, the program will exit with an error message: {e}.")
sys.exit()

logging.info(f"The current repository version is {VERSION}, and the repository address is https://github.com/ARC-MX/sgcc_electricity_new.git")
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
logging.info(f"The current date is {current_datetime}.")
Expand Down

0 comments on commit 4a6e6c6

Please sign in to comment.