Giter VIP home page Giter VIP logo

sgcc_electricity_new's Introduction

**重要说明:**原作者@renhai-lab 已于2023年10将项目归档,原仓库不再更新。这个版本是在原仓库基础上更新的。在此向原作者表达谢意和致敬。验证码识别已经从最开始的在线商业API替换成离线神经网络检测版本,请使用本仓库的同学点个小星星,或者打赏鼓励。

添加微信通知后,我想这基本上就是这个插件的最终形态了,docker镜像压缩到300MB,后续可能只会在网站变动或者出问题才会更新,再次感谢大家的Star。

支付宝&微信 打赏码

⚡️国家电网电力获取

Docker Image CI Image Size Docker Pull

mini-graph-card mini-graph-card

本应用可以帮助你将国网的电费、用电量数据接入homeassistant,实现实时追踪家庭用电量情况;并且可以将每日用电量保存到数据库,历史有迹可循。具体提供两类数据:

  1. 在homeassistant以实体显示:

    实体entity_id 说明
    sensor.last_electricity_usage 最近一天用电量,单位KWH、度。属性含present_date(查询电量代表的日期)
    sensor.electricity_charge_balance 预付费显示电费余额,反之显示上月应交电费,单位元
    sensor.yearly_electricity_usage 今年总用电量,单位KWH、度。
    sensor.yearly_electricity_charge 今年总用电费用,单位元
    sensor.month_electricity_usage 最近一天用电量,单位KWH、度。属性含present_date(查询电量代表的日期)
    sensor.month_electricity_charge 上月总用电费用,单位元 属性含present_date(查询电量代表的日期)
  2. 可选,近三十天每日用电量数据(SQLite数据库) 数据库表名为 daily+userid ,在项目路径下有个homeassistant.db 的数据库文件就是; 如需查询可以用

    "SELECT * FROM dailyxxxxxxxx;"
    

    得到如下结果:

mini-graph-card

## 一、适用范围
  1. 适用于除南方电网覆盖省份外的用户。即除广东、广西、云南、贵州、海南等省份的用户外,均可使用本应用获取电力、电费数据。
  2. 不管是通过哪种哪种安装的homeassistant,只要可以运行python,有约1G硬盘空间和500M运行内存,都可以采用本仓库部署。

本镜像支持架构:

  • linux/amd64:适用于 x86-64(amd64)架构的 Linux 系统,例如windows电脑。
  • linux/arm64:适用于 ARMv8 架构的 Linux 系统,例如树莓派3+,N1盒子等。
  • linux/armv7,暂不提供 ARMv7 架构的 Linux 系统,例如树莓派2,玩客云等,主要原因是onnx-runtime没有armv7版本的库,用户可以参考 https://github.com/nknytk/built-onnxruntime-for-raspberrypi-linux.git自行安装库然后编译docker镜像。

二、实现流程

通过python的selenium包获取国家电网的数据,通过homeassistant的提供的REST API将采用POST请求将实体状态更新到homeassistant。

国家电网添加了滑动验证码登录验证,我这边最早采取了调用商业API的方式,现在已经更新成了离线方案。利用Yolov3神经网络识别验证码,请大家放心使用。

三、安装

1)注册国家电网账户

首先要注册国家电网账户,绑定电表,并且可以手动查询电量

注册网址:https://www.95598.cn/osgweb/login

2)docker镜像部署,速度快

  1. 安装docker和homeassistant,Homeassistant极简安装法
  2. 克隆仓库
git clone https://github.com/ARC-MX/sgcc_electricity_new.git
# 如果github网络环境不好的话可以使用国内镜像,完全同步的,个人推荐使用国内镜像
# git clone https://gitee.com/ARC-MX/sgcc_electricity_new.git
cd sgcc_electricity_new
  1. 创建环境变量文件
cp example.env .env
vim .env

参考以下文件编写.env文件

### 以下项都需要修改
## 国网登录信息
# 修改为自己的登录账号
PHONE_NUMBER="xxx" 
# 修改为自己的登录密码
PASSWORD="xxxx" 

# SQLite 数据库配置
# or False 不启用数据库储存每日用电量数据。
ENABLE_DATABASE_STORAGE=True
# 数据库名,默认为homeassistant
DB_NAME="homeassistant.db"
# COLLECTION_NAME默认为electricity_daily_usage_{国网用户id},不支持修改。

## homeassistant配置
# 改为你的localhost为你的homeassistant地址
HASS_URL="http://localhost:8123/" 
# homeassistant的长期令牌
HASS_TOKEN="eyxxxxx"

## selenium运行参数
# 任务开始时间,24小时制,例如"07:00"则为每天早上7点执行,第一次启动程序如果时间晚于早上7点则会立即执行一次,每隔12小时执行一次。
JOB_START_TIME="07:00"

## 其他默认参数
# 浏览器默认等待时间,秒。
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 天造成错误
DATA_RETENTION_DAYS=7

## 余额提醒
# 是否缴费提醒
RECHARGE_NOTIFY=Flase
# 余额
BALANCE=5.0
# pushplus token 如果有多个就用","分隔,","之间不要有空格,单个就不要有","
PUSHPLUS_TOKEN=xxxxxxx,xxxxxxx,xxxxxxx
  1. 运行

我已经优化了镜像环境,将镜像的地址配置为阿里云,如果要使用docker hub的源可以将docker-compose.yml中 image: registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity:latest 改为 arcw/sgcc_electricity:latest

docker compose up --build 
# 或者后台运行
docker compose up -d --build
  1. 更新容器及其代码
docker compose down # 删除容器
docker compose pull # 更新镜像
git pull --tags origin master:master	#更新代码,代码不在容器中,所以要手动更新
docker compose up # 重新运行
  1. 运行成功应该显示如下日志:
2024-06-06 16:00:43  [INFO    ] ---- 程序开始,当前仓库版本为1.x.x,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-06 16:00:43  [INFO    ] ---- enable_database_storage为false,不会储存到数据库
2024-06-06 16:00:43  [INFO    ] ---- 当前登录的用户名为: xxxxxx,homeassistant地址为http://192.168.1.xx:8123/,程序将在每天00:00执行
2024-06-06 16:00:43  [INFO    ] ---- 此次为首次运行,等待时间(FIRST_SLEEP_TIME)为10秒,可在.env中设置
2024-06-06 16:00:59  [INFO    ] ---- Webdriver initialized.
2024-06-06 16:01:20  [INFO    ] ---- Click login button.
2024-06-06 16:01:20  [INFO    ] ---- Get electricity canvas image successfully.
2024-06-06 16:01:20  [INFO    ] ---- Image CaptCHA distance is xxx.
2024-06-06 16:01:25  [INFO    ] ---- Login successfully on https://www.95598.cn/osgweb/login
2024-06-06 16:01:33  [INFO    ] ---- 将获取1户数据,user_id: ['xxxxxxx']
2024-06-06 16:01:42  [INFO    ] ---- Get electricity charge balance for xxxxxxx successfully, balance is xxx CNY.
2024-06-06 16:01:51  [INFO    ] ---- Get year power usage for xxxxxxx successfully, usage is xxx kwh
2024-06-06 16:01:51  [INFO    ] ---- Get year power charge for xxxxxxx successfully, yealrly charge is xxx CNY
2024-06-06 16:01:55  [INFO    ] ---- Get month power charge for xxxxxxx successfully, 01 月 usage is xxx KWh, charge is xxx CNY.
2024-06-06 16:01:55  [INFO    ] ---- Get month power charge for xxxxxxx successfully, 02 月 usage is xxx KWh, charge is xxx CNY.
2024-06-06 16:01:55  [INFO    ] ---- Get month power charge for xxxxxxx successfully, 2024-03-01-2024-03-31 usage is xxx KWh, charge is xxx CNY.
2024-06-06 16:01:55  [INFO    ] ---- Get month power charge for xxxxxxx successfully, 2024-04-01-2024-04-30 usage is xxx KWh, charge is xxx CNY.
2024-06-06 16:01:59  [INFO    ] ---- Get daily power consumption for xxxxxxx successfully, , 2024-06-05 usage is xxx kwh.
2024-06-06 16:02:07  [INFO    ] ---- Webdriver quit after fetching data successfully.
2024-06-06 16:02:07  [INFO    ] ---- 浏览器已退出

四、配置与使用

1)第一次运行需要创建并填写.env文件,按文件说明进行填写。

2)(可选)修改实体

填写homeassistant的配置文件

由于采用REST API方式创建sensor,没有做实体注册,无法在webui里编辑。如果需要,你可以在configuration.yaml下增加如下配置后重启HA,这样你就可在webUI编辑对应的实体了,这样含有_entity后缀的实体就可以进行修改了。

  • 如果你有一个户号,参照以下配置:

Example configuration.yaml entry

文件中只能有一个template

template:
  - trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: sensor.electricity_charge_balance
    sensor:
      - name: electricity_charge_balance_entity
        unique_id: electricity_charge_balance_entity
        state: "{{ states('sensor.electricity_charge_balance') }}"
        state_class: total
        unit_of_measurement: "CNY"
        device_class: monetary

  - trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: sensor.last_electricity_usage
    sensor:
      - name: last_electricity_usage_entity
        unique_id: last_electricity_usage_entity
        state: "{{ states('sensor.last_electricity_usage') }}"
        attributes:
          present_date: "{{ state_attr('sensor.last_electricity_usage', 'present_date') }}"
          last_updated: "{{ state_attr('sensor.last_electricity_usage', 'last_updated') }}"
        state_class: total_increasing
        unit_of_measurement: "kWh"
        device_class: energy

  - trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: sensor.month_electricity_usage
    sensor:
      - name: month_electricity_usage_entity
        unique_id: month_electricity_usage_entity
        state: "{{ states('sensor.month_electricity_usage') }}"
        attributes:
          present_date: "{{ state_attr('sensor.month_electricity_usage', 'present_date') }}"
          last_updated: "{{ state_attr('sensor.month_electricity_usage', 'month_updated') }}"
        state_class: total_increasing
        unit_of_measurement: "kWh"
        device_class: energy

  - trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: sensor.month_electricity_charge
    sensor:
      - name: month_electricity_charge_entity
        unique_id: month_electricity_charge_entity
        state: "{{ states('sensor.month_electricity_charge') }}"
        attributes:
          present_date: "{{ state_attr('sensor.month_electricity_charge', 'present_date') }}"
          last_updated: "{{ state_attr('sensor.month_electricity_charge', 'month_updated') }}"
        state_class: total_increasing
        unit_of_measurement: "CNY"
        device_class: monetary

  - trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: sensor.yearly_electricity_usage
    sensor:
      - name: yearly_electricity_usage_entity
        unique_id: yearly_electricity_usage_entity
        state: "{{ states('sensor.yearly_electricity_usage') }}"
        state_class: total_increasing
        unit_of_measurement: "kWh"
        device_class: energy

  - trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: sensor.yearly_electricity_charge
    sensor:
      - name: yearly_electricity_charge_entity
        unique_id: yearly_electricity_charge_entity
        state: "{{ states('sensor.yearly_electricity_charge') }}"
        state_class: total_increasing
        unit_of_measurement: "CNY"
        device_class: monetary

如果你有多个户号,每个户号参照configuration.yaml配置。

  • **注:如果你有一个户号,在HA里就是以上实体名;**如果你有多个户号,实体名称还要加 “_户号”后缀,举例:sensor.last_electricity_usage_1234567890

❗️<u>进行自定义操作之后,请使用带entity的实体。比如使用sensor.last_electricity_usage_entity_1234567890而不是sensor.last_electricity_usage_1234567890。</u>

3)(可选)ha内数据展示

结合mini-graph-card](https://github.com/kalkih/mini-graph-card) 和mushroom实现效果:

image-20230731111757106.png

type: custom:mini-graph-card
entities:
  - entity: sensor.last_electricity_usage_entity
    name: 国网每日用电量
    aggregate_func: first
    show_state: true
    show_points: true
group_by: date
hour24: true
hours_to_show: 240

4)(可选)配合用电阶梯,实现实时电价。

image-20230729172257731

具体操作:

修改homeassistant.yml文件然后重启或重载配置文件,注意当前阶梯中的sensor.yearly_electricity_usage_entity要根据你的实际情况修改:

# 文件中只能有一个sensor
sensor:
  # 实时电价
  - platform: template #平台名称
    sensors: #传感器列表
      real_time_electricity_price: #实体名称:只能用小写,下划线
        unique_id: "real_time_electricity_price" #UID(必须)
        friendly_name:  '实时电价' #在前端显示的传感器昵称(可选)
        unit_of_measurement: "CNY/kWh" #传感器数值的单位(可选)
        icon_template: mdi:currency-jpy #默认图标
        value_template: > #定义一个获取传感器状态的模板(必须)下面的6和22是指6点和22点,"1""2""3"是指阶梯123,6个价格分别是3个阶梯的峰谷价格
          {% if now().strftime("%H")| int >= 6 and now().strftime("%H")|int < 22 and states("sensor.current_ladder")=="1" %}
            0.617
          {%elif now().strftime("%H")| int >= 6 and now().strftime("%H")|int < 22 and states("sensor.current_ladder")=="2" %}
            0.677
          {%elif now().strftime("%H")| int >= 6 and now().strftime("%H")|int < 22 and states("sensor.current_ladder")=="3" %}
            0.977
          {% elif states("sensor.current_ladder")=="1" %}
            0.307
          {% elif states("sensor.current_ladder")=="2" %}
            0.337
          {% elif states("sensor.current_ladder")=="3" %}
            0.487
          {% endif %}

# 当前阶梯
  - platform: template
    sensors:
      current_ladder:
        unique_id: "current_ladder"
        friendly_name:  '当前阶梯'
        unit_of_measurement: ""
        icon_template: mdi:elevation-rise
        value_template: > #这里是上海的三个阶梯数值,第2阶梯3120,第三阶梯4800
          {% if states("sensor.yearly_electricity_usage_entity") | float <= 3120 %}
          1
          {% elif states("sensor.yearly_electricity_usage_entity") | float >3120 and states("sensor.yearly_electricity_usage_entity") | float <= 4800 %}
          2
          {% else %}
          3
          {% endif %}

可以在能源面板进行配置,对可以统计电量的设备实现分阶梯计算用电量。

tip:打开ha>仪表盘>能源>添加用电数据>实时电价实体-选择real_time_electricity_price。

image-20230731111953612.png

5)电量通知

更新电费余额不足提醒,在.env里设置提醒余额。目前我是用pushplus的方案,注册pushplus然后,获取token,通知给谁就让谁注册并将token填到.env中

写在最后

当前作者:https://github.com/ARC-MX/sgcc_electricity_new

原作者:https://github.com/louisslee/sgcc_electricity,原始README_origin.md

我的自定义部分包括:

增加的部分:

  • 增加近30天每日电量写入数据库(默认mongodb),其他数据库请自行配置。
  • 将间歇执行设置为定时执行: JOB_START_TIME,24小时制,例如"07:00”则为每天早上7点执行,第一次启动程序立即执行一次, 每12小时执行一次
  • 给last_daily_usage增加present_date,用来确定更新的是哪一天的电量。一般查询的日期会晚一到两天。
  • 对configuration.yaml中自定义实体部分修改。

重要修改通知

2024-06-13:SQLite替换MongoDB,原因是python自带SQLite3,不需要额外安装,也不再需要MongoDB镜像。 2024-07-03:新增每天定时执行两次,添加配置默认增加近 7 天每日电量写入数据, 可修改为 30 天。 2024-07-05:新增余额不足提醒功能。 TO-DO

  • 增加离线滑动验证码识别方案
  • 添加默认推送服务,电费余额不足提醒
  • 。。。

sgcc_electricity_new's People

Contributors

arc-mx avatar tuisku-l avatar houoop avatar nicodess avatar bdingtech avatar

Stargazers

千石 avatar rlw avatar Tyrael Wang avatar 0 avatar  avatar bb chen avatar meeia avatar howel52 avatar  avatar  avatar Wallen Han avatar Richard He avatar TZMSky avatar superqun avatar Chriskuei avatar Hi-我是嘉骏 avatar JimmeYoumu avatar  avatar Hekatos Noir avatar  avatar  avatar AoThen avatar  avatar  avatar  avatar  avatar  avatar  avatar 番茄是水果 avatar  avatar cloverstd avatar  avatar yuzhimou avatar TESTrepository avatar lzwang avatar  avatar Cat911 avatar Neeil avatar tangye avatar haichang avatar  avatar  avatar dooooooge avatar Z avatar lbx2000 avatar halftop avatar  avatar  avatar HUANGBANGJING avatar 柯大师 avatar fliaping avatar fanhua avatar  avatar  avatar  avatar Xuan avatar Darren avatar  avatar  avatar Meigetu Nya avatar  avatar  avatar 孙善明 avatar  avatar chobits avatar Jianguo Wu avatar TinK avatar  avatar  avatar  avatar Shijia Zhang avatar  avatar  avatar Len avatar  avatar Earl avatar  avatar Felix avatar  avatar  avatar  avatar Yifan Guo avatar Satella Poi avatar  avatar Tang avatar Martin Huang avatar 暮森屿 avatar  avatar  avatar  avatar  avatar EGOISTK21 avatar Haven avatar  avatar  avatar YangLe avatar Zichuan Ma avatar  avatar minirplus avatar  avatar

Watchers

 avatar  avatar 装傻充愣 avatar

sgcc_electricity_new's Issues

能源面板问题

照抄了模版配置能源面板报错,last_electricity_usage_entity实体的状态类别虽然是 measurement,但缺少 last_reset 参数,能源面板没有数据传入,把state_class从measurement改为total_increasing,不再报错,也有数据了,但只有一个数据,如图。哪里错了?
IMG_0366

运行报错

运行环境:x86; Ikuai OS; Docker version 18.09.9
创建代码:
docker run -d
--env-file /etc/disk/1544065b-4f97-4283-809d-e7f29a0aeedd/Config/Docker/sgcc_electricity/config.env
--name sgcc_electricity
--network doc_docker_lan
-v /etc/disk/1544065b-4f97-4283-809d-e7f29a0aeedd/Config/Docker/sgcc_electricity/scripts:/app
-e SET_CONTAINER_TIMEZONE=true
-e CONTAINER_TIMEZONE=Asia/Shanghai
--restart unless-stopped
registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity:latest
python3 main.py
报错代码:If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 57, in
raise import_capi_exception
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
ImportError
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 57, in
raise import_capi_exception
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
ImportError
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 57, in
raise import_capi_exception
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
ImportError

能否增加按月计算的阶梯电价

有的地区的阶梯电价是按月来的而不是按年,每个月都会重置,目前的方法无法简单地将年电量实体替换成月电量来实现,因为月电量统计的是上个月的用电量。是否会考虑新增类似年用电量那样的实时累计的本月用电量实体?

创建容器后可以运行但日志报错

ERROR:root:Failing to read the .env file, the program will exit with an error message: float() argument must be a string or a number, not 'NoneType'.

似乎无法正确读取.env文件

多账户数据获取问题

感谢大佬的镜像。

我账号下有两个账号,其中一个是光伏账号。程序在拉取光伏账号的时候报错,具体错误如下

2024-06-09 10:01:54  [ERROR   ] ---- Get year power usage for xxxxx failed, pass
2024-06-09 10:01:54  [ERROR   ] ---- Get year power charge for xxxxxx failed, pass
2024-06-09 10:03:04  [ERROR   ] ---- Get month power usage for xxxxx failed, pass
2024-06-09 10:04:15  [ERROR   ] ---- Webdriver quit abnormly, reason: cannot unpack non-iterable NoneType object. 5 retry times left.

错误与 #4 类似。

像我这种在多账户的情况下,能否在.env中指定拉取某一个账号?

谢谢。

运行报错

大佬 麻烦看下是什么问题, x86的 机器, 有注册国网账号,账号里也只 绑定了一个户号。日志如下:
2024-06-06 15:03:08 [INFO ] ---- 此次为首次运行,等待时间(FIRST_SLEEP_TIME)为10秒,可在.env中设置
2024-06-06 15:03:18 [INFO ] ---- patching driver executable /usr/bin/chromedriver
2024-06-06 15:03:29 [INFO ] ---- Webdriver initialized.
Traceback (most recent call last):
File "/app/data_fetcher.py", line 245, in fetch
return self._fetch()
File "/app/data_fetcher.py", line 268, in _fetch
if self._login(driver):
File "/app/data_fetcher.py", line 306, in _login
driver.find_element(By.CLASS_NAME, "user").click()
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 856, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
2024-06-06 15:04:42 [ERROR ] ---- Webdriver quit abnormly, reason: Message: no such element: Unable to locate element: {"method":"css selector","selector":".user"}
(Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x563f83e82233
#1 0x563f83b4c0fe
#2 0x563f83b95ba6
#3 0x563f83b95cc1
#4 0x563f83be3204
#5 0x563f83bc344d
#6 0x563f83be0680
#7 0x563f83bc31a3
#8 0x563f83b8813e
#9 0x563f83b89712
#10 0x563f83e57534
#11 0x563f83e5a759
#12 0x563f83e5a238
#13 0x563f83e5ac05
#14 0x563f83e49abf
#15 0x563f83e5af8e
#16 0x563f83e33c86
#17 0x563f83e733e5
#18 0x563f83e735cb
#19 0x563f83e817bf
#20 0x7f2920f3dea7 start_thread
. 5 retry times left.
2024-06-06 15:04:42 [ERROR ] ---- state-refresh task failed, reason is cannot unpack non-iterable NoneType object
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".user"}
(Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x563f83e82233
#1 0x563f83b4c0fe
#2 0x563f83b95ba6
#3 0x563f83b95cc1
#4 0x563f83be3204
#5 0x563f83bc344d
#6 0x563f83be0680
#7 0x563f83bc31a3
#8 0x563f83b8813e
#9 0x563f83b89712
#10 0x563f83e57534
#11 0x563f83e5a759
#12 0x563f83e5a238
#13 0x563f83e5ac05
#14 0x563f83e49abf
#15 0x563f83e5af8e
#16 0x563f83e33c86
#17 0x563f83e733e5
#18 0x563f83e735cb
#19 0x563f83e817bf
#20 0x7f2920f3dea7 start_thread

Traceback (most recent call last):
File "/app/main.py", line 57, in run_task
user_id_list, balance_list, last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = data_fetcher.fetch()
TypeError: cannot unpack non-iterable NoneType object

新版NumPy报错

sgcc_electricity |
sgcc_electricity | A module that was compiled using NumPy 1.x cannot be run in
sgcc_electricity | NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
sgcc_electricity | versions of NumPy, modules must be compiled with NumPy 2.0.
sgcc_electricity | Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
sgcc_electricity |
sgcc_electricity | If you are a user of the module, the easiest solution will be to
sgcc_electricity | downgrade to 'numpy<2' or try to upgrade the affected module.
sgcc_electricity | We expect that some modules will need time to support NumPy 2.
sgcc_electricity |
sgcc_electricity | Traceback (most recent call last): File "/app/main.py", line 13, in
sgcc_electricity | from data_fetcher import DataFetcher
sgcc_electricity | File "/app/data_fetcher.py", line 29, in
sgcc_electricity | from onnx import ONNX
sgcc_electricity | File "/app/onnx.py", line 4, in
sgcc_electricity | import onnxruntime
sgcc_electricity | File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
sgcc_electricity | from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
sgcc_electricity | File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
sgcc_electricity | from .onnxruntime_pybind11_state import * # noqa
sgcc_electricity | AttributeError: _ARRAY_API not found
sgcc_electricity | Traceback (most recent call last):
sgcc_electricity | File "/app/main.py", line 13, in
sgcc_electricity | from data_fetcher import DataFetcher
sgcc_electricity | File "/app/data_fetcher.py", line 29, in
sgcc_electricity | from onnx import ONNX
sgcc_electricity | File "/app/onnx.py", line 4, in
sgcc_electricity | import onnxruntime
sgcc_electricity | File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 57, in
sgcc_electricity | raise import_capi_exception
sgcc_electricity | File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
sgcc_electricity | from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
sgcc_electricity | File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
sgcc_electricity | from .onnxruntime_pybind11_state import * # noqa
sgcc_electricity | ImportError
sgcc_electricity exited with code 0

运行NoneType报错

麻烦大佬帮忙再看下这个报错

2024/06/04 14:29:52 | stderr | TypeError: cannot unpack non-iterable NoneType object
2024/06/04 14:29:52 | stderr | user_id_list, balance_list, last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = data_fetcher.fetch()
2024/06/04 14:29:52 | stderr | File "/app/main.py", line 57, in run_task
2024/06/04 14:29:52 | stderr | Traceback (most recent call last):
2024/06/04 14:29:52 | stderr | TypeError: 'NoneType' object is not subscriptable
2024/06/04 14:29:52 | stdout | 2024-06-04 14:29:52  [ERROR   ] ---- state-refresh task failed, reason is cannot unpack non-iterable NoneType object
2024/06/04 14:29:52 | stdout | 2024-06-04 14:29:52  [ERROR   ] ---- Webdriver quit abnormly, reason: 'NoneType' object is not subscriptable. 5 retry times left.
2024/06/04 14:29:52 | stderr | month_list.append(month[-1])
2024/06/04 14:29:52 | stderr | File "/app/data_fetcher.py", line 430, in _get_other_data
2024/06/04 14:29:52 | stderr | last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list  = self._get_other_data(driver, user_id_list)
2024/06/04 14:29:52 | stderr | File "/app/data_fetcher.py", line 272, in _fetch
2024/06/04 14:29:52 | stderr | return self._fetch()
2024/06/04 14:29:52 | stderr | File "/app/data_fetcher.py", line 243, in fetch

95598登录一直报错

具体错误如下,也设置的是7日,账号密码控制台也试过了,是正确的
image

docker-compose部署问题

docker-compose部署
拉取镜像后启动,日志报错
python3: can't open file '/app/main.py': [Errno 2] No such file or directory

还需要把scripts下文件放到挂载目录下?是否能优化下?

状态刷新失败

024-06-28 10:44:59  [INFO    ] ---- 程序开始,当前仓库版本为1.4.1,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-28 10:44:59  [INFO    ] ---- chromium-driver version is 120

...

2024-06-28 10:46:53  [INFO    ] ---- 将获取2户数据,user_id: ['<user_id_1>', '<user_id_2>']
...
2024-06-28 10:48:08  [INFO    ] ---- Get month power charge for <user_id_1> successfully, 2024-03-01-2024-03-31 usage is 58 KWh, charge is 24.89 CNY.
2024-06-28 10:48:08  [INFO    ] ---- Get month power charge for <user_id_1> successfully, 2024-04-01-2024-04-30 usage is 55 KWh, charge is 23.77 CNY.
2024-06-28 10:48:08  [INFO    ] ---- Get month power charge for <user_id_1> successfully, 2024-05-01-2024-05-31 usage is 54 KWh, charge is 23.47 CNY.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='pane-second']/div[1]/div/label[2]/span[1]"}
  (Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x55e55c864233 <unknown>
#1 0x55e55c52e0fe <unknown>
#2 0x55e55c577ba6 <unknown>
#3 0x55e55c577cc1 <unknown>
#4 0x55e55c5c5204 <unknown>
#5 0x55e55c5a544d <unknown>
#6 0x55e55c5c2680 <unknown>
#7 0x55e55c5a51a3 <unknown>
#8 0x55e55c56a13e <unknown>
#9 0x55e55c56b712 <unknown>
#10 0x55e55c839534 <unknown>
#11 0x55e55c83c759 <unknown>
#12 0x55e55c83c238 <unknown>
#13 0x55e55c83cc05 <unknown>
#14 0x55e55c82babf <unknown>
#15 0x55e55c83cf8e <unknown>
#16 0x55e55c815c86 <unknown>
#17 0x55e55c8553e5 <unknown>
#18 0x55e55c8555cb <unknown>
#19 0x55e55c8637bf <unknown>
#20 0x7f212ddccea7 start_thread


#3 0x55e55c577cc1 <unknown>
#4 0x55e55c5c5204 <unknown>
#5 0x55e55c5a544d <unknown>
#6 0x55e55c5c2680 <unknown>
#7 0x55e55c5a51a3 <unknown>
#8 0x55e55c56a13e <unknown>
#9 0x55e55c56b712 <unknown>
#10 0x55e55c839534 <unknown>
#11 0x55e55c83c759 <unknown>
#12 0x55e55c83c238 <unknown>
#13 0x55e55c83cc05 <unknown>
#14 0x55e55c82babf <unknown>
#15 0x55e55c83cf8e <unknown>
#16 0x55e55c815c86 <unknown>
#17 0x55e55c8553e5 <unknown>
#18 0x55e55c8555cb <unknown>
#19 0x55e55c8637bf <unknown>
#20 0x7f212ddccea7 start_thread
. 5 retry times left.
2024-06-28 10:49:18  [ERROR   ] ---- state-refresh task failed, reason is cannot unpack non-iterable NoneType object
Traceback (most recent call last):
  File "/app/main.py", line 57, in run_task
    user_id_list, balance_list, last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = data_fetcher.fetch()
TypeError: cannot unpack non-iterable NoneType object
^CTraceback (most recent call last):
  File "/app/main.py", line 90, in <module>
    main()
  File "/app/main.py", line 52, in main
    time.sleep(1)

运行报错

大佬,这个报错是怎么回事啊?

date | stream | content -- | -- | -- 2024/06/04 11:13:17 | stderr |   2024/06/04 11:13:17 | stderr | onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from ./captcha.onnx failed:/onnxruntime_src/onnxruntime/core/graph/model.cc:111 onnxruntime::Model::Model(onnx::ModelProto&&, const PathString&, const IOnnxRuntimeOpSchemaRegistryList*, const onnxruntime::logging::Logger&) Unknown model file format version. 2024/06/04 11:13:17 | stderr | sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model) 2024/06/04 11:13:17 | stderr | File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 310, in _create_inference_session 2024/06/04 11:13:17 | stderr | self._create_inference_session(providers, provider_options, disabled_optimizers) 2024/06/04 11:13:17 | stderr | File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 283, in __init__ 2024/06/04 11:13:17 | stderr | self.onnx_session = onnxruntime.InferenceSession(onnx_file_name) 2024/06/04 11:13:17 | stderr | File "/app/onnx.py", line 16, in __init__ 2024/06/04 11:13:17 | stderr | self.onnx = ONNX("./captcha.onnx") 2024/06/04 11:13:17 | stderr | File "/app/data_fetcher.py", line 167, in __init__ 2024/06/04 11:13:17 | stderr | fetcher = DataFetcher(PHONE_NUMBER, PASSWORD) 2024/06/04 11:13:17 | stderr | File "/app/main.py", line 37, in main 2024/06/04 11:13:17 | stderr | main() 2024/06/04 11:13:17 | stderr | File "/app/main.py", line 90, in  2024/06/04 11:13:17 | stderr | Traceback (most recent call last): 2024/06/04 11:13:16 | stdout | 2024-06-04 11:13:16  [INFO    ] ---- 程序开始,当前仓库版本为1.3.3,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git

docker找不到镜像

✘ app Error manifest for renhai/sgcc_electricity:latest not found: manifest unknown: manifest unknown

V1.4.2编译启动报错

麻烦大佬看下:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last): File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "/app/main.py", line 13, in
from data_fetcher import DataFetcher
File "/app/data_fetcher.py", line 29, in
from onnx import ONNX
File "/app/onnx.py", line 4, in
import onnxruntime
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 57, in
raise import_capi_exception
File "/usr/local/lib/python3.9/site-packages/onnxruntime/init.py", line 23, in
from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401
File "/usr/local/lib/python3.9/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in
from .onnxruntime_pybind11_state import * # noqa
ImportError

运行时报错

运行时报如下错误:
sgcc_electricity | 2024-07-07 17:51:48 [INFO ] ---- The current repository version is v1.5.0, and the repository

address is https://github.com/ARC-MX/sgcc_electricity_new.git
sgcc_electricity | 2024-07-07 17:51:48.681349512 [E:onnxruntime:Default, env.cc:254 ThreadMain] pthread_setaffinity_np

failed for thread: 14, index: 2, mask: {6, 7, }, error code: 22 error msg: Invalid argument. Specify the number of threads

explicitly so the affinity is not set.
sgcc_electricity | 2024-07-07 17:51:48.681456788 [E:onnxruntime:Default, env.cc:254 ThreadMain] pthread_setaffinity_np

failed for thread: 15, index: 3, mask: {8, 9, }, error code: 22 error msg: Invalid argument. Specify the number of threads

explicitly so the affinity is not set.
sgcc_electricity | 2024-07-07 17:51:48.688967032 [E:onnxruntime:Default, env.cc:254 ThreadMain] pthread_setaffinity_np

failed for thread: 16, index: 4, mask: {10, 11, }, error code: 22 error msg: Invalid argument. Specify the number of

threads explicitly so the affinity is not set.

然后进行登录并获取到几个月的用电数据,再报如下错误:
Traceback (most recent call last):
File "/app/data_fetcher.py", line 244, in fetch
return self._fetch()
File "/app/data_fetcher.py", line 279, in _fetch
last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = self._get_other_data(driver, user_id_list)
File "/app/data_fetcher.py", line 427, in _get_other_data
self.save_usage_data(driver, user_id_list[i - 1])
File "/app/data_fetcher.py", line 558, in save_usage_data
self._click_button(driver, By.XPATH, "//[@id='pane-second']/div[1]/div/label[2]/span[1]")
File "/app/data_fetcher.py", line 594, in _click_button
click_element = driver.find_element(button_search_type, button_search_key)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 856, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//
[@id='pane-second']/div[1]/div/label[2]/span[1]"}
(Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x560a17bee233
#1 0x560a178b80fe
#2 0x560a17901ba6
#3 0x560a17901cc1
#4 0x560a1794f204
#5 0x560a1792f44d
#6 0x560a1794c680
#7 0x560a1792f1a3
#8 0x560a178f413e
#9 0x560a178f5712
#10 0x560a17bc3534
#11 0x560a17bc6759
#12 0x560a17bc6238
#13 0x560a17bc6c05
#14 0x560a17bb5abf
#15 0x560a17bc6f8e
#16 0x560a17b9fc86
#17 0x560a17bdf3e5
#18 0x560a17bdf5cb
#19 0x560a17bed7bf
#20 0x7f0780bc0ea7 start_thread

Traceback (most recent call last):
File "/app/main.py", line 61, in run_task
user_id_list, balance_list, last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = data_fetcher.fetch()
TypeError: cannot unpack non-iterable NoneType object
2024-07-07 18:33:37 [ERROR ] ---- Webdriver quit abnormly, reason: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='pane-second']/div[1]/div/label[2]/span[1]"}
(Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x560a17bee233
#1 0x560a178b80fe
#2 0x560a17901ba6
#3 0x560a17901cc1
#4 0x560a1794f204
#5 0x560a1792f44d
#6 0x560a1794c680
#7 0x560a1792f1a3
#8 0x560a178f413e
#9 0x560a178f5712
#10 0x560a17bc3534
#11 0x560a17bc6759
#12 0x560a17bc6238
#13 0x560a17bc6c05
#14 0x560a17bb5abf
#15 0x560a17bc6f8e
#16 0x560a17b9fc86
#17 0x560a17bdf3e5
#18 0x560a17bdf5cb
#19 0x560a17bed7bf
#20 0x7f0780bc0ea7 start_thread
. 5 retry times left.
2024-07-07 18:33:37 [ERROR ] ---- state-refresh task failed, reason is cannot unpack non-iterable NoneType object

我的运行环境为:proxmox 虚拟环境下的lxc容器中安装debian11

验证码滑块拖动一直报错

日志如下:

sgcc_electricity  | 2024-07-08 18:12:54  [INFO    ] ---- Sliding CAPTCHA recognition failed and reloaded.
sgcc_electricity  | 2024-07-08 18:13:14  [INFO    ] ---- Get electricity canvas image successfully.
sgcc_electricity  | 2024-07-08 18:13:14  [INFO    ] ---- Image CaptCHA distance is 199.
sgcc_electricity  | 2024-07-08 18:13:25  [INFO    ] ---- Sliding CAPTCHA recognition failed and reloaded.
sgcc_electricity  | 2024-07-08 18:13:45  [INFO    ] ---- Get electricity canvas image successfully.
sgcc_electricity  | 2024-07-08 18:13:45  [INFO    ] ---- Image CaptCHA distance is 251.
sgcc_electricity  | 2024-07-08 18:13:56  [INFO    ] ---- Sliding CAPTCHA recognition failed and reloaded.
sgcc_electricity  | 2024-07-08 18:14:16  [INFO    ] ---- Get electricity canvas image successfully.

麻烦大佬看一下,谢谢

大佬 看看这是什么情况

4-08-08 15:15:52 [ERROR ] ---- Login failed, maybe caused by Sliding CAPTCHA recognition failed
Traceback (most recent call last):
File "/app/data_fetcher.py", line 244, in fetch
return self._fetch()
File "/app/data_fetcher.py", line 267, in _fetch
if self._login(driver):
File "/app/data_fetcher.py", line 358, in _login
raise Exception(
Exception: Login failed, maybe caused by 1.incorrect phone_number and password, please double check. or 2. network, please mnodify LOGIN_EXPECTED_TIME in .env and run docker compose up --build.
2024-08-08 15:15:52 [ERROR ] ---- Webdriver quit abnormly, reason: Login failed, maybe caused by 1.incorrect phone_number and password, please double check. or 2. network, please mnodify LOGIN_EXPECTED_TIME in .env and run docker compose up --build.. 5 retry times left.
2024-08-08 15:15:52 [ERROR ] ---- state-refresh task failed, reason is cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "/app/main.py", line 61, in run_task
user_id_list, balance_list, last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = data_fetcher.fetch()
TypeError: cannot unpack non-iterable NoneType object

好像没有用到在线识别的API

由于国家电网添加了滑动验证码登录验证,我这边采取了调用商业API的方式,没时间找靠谱的离线方案,(ddddocr识别准确率太低),如果后续找到靠谱的离线方案速度还可以的话我会考虑更新,暂时先这样吧。 在线验证API的注册地址http://www.ttshitu.com/user/soft.html,注册推荐码: [c611f7018fc74aa3b75c30584108c5c6 价格也不贵2块钱基本够大半年了。

docker打包优化探讨

尝试把script打包到docker镜像,这样就不需要pull源码才能运行
想了解下不把script打包到镜像的原因
另外一个就是我打出来的镜像有1.3G,大出你打的包不少

按照示例添加实体报错

编辑/homeassistant/configuration.yaml文件,重启报错 Invalid config for 'template' at configuration.yaml, line 63: required key 'platform' not provided,
当前版本Core:2024.6.3
Supervisor:2024.06.0
Operating System:12.4
Frontend:20240610.1

日志卡在此次为首次运行

### 麻烦大佬看下 谢谢
chrome和chromedriver都装了

himycoco@himycoco:~/sgcc_electricity_new$ sudo docker logs -f sgcc_electricity
[sudo] password for himycoco:
2024-06-19 00:06:36 [INFO ] ---- 程序开始,当前仓库版本为1.4.1,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-19 00:06:36 [INFO ] ---- chromium-driver version is 120
2024-06-19 00:06:36 [DEBUG ] ---- enable_database_storage为true,将会储存到数据库
2024-06-19 00:06:36 [INFO ] ---- 当前登录的用户名为: 18357147789,homeassistant地址为http://192.168.123.22:8123/,程序将在每天17:00执行
2024-06-19 00:06:36 [INFO ] ---- 此次为首次运行,当前时间早于 JOB_START_TIME: 17:00,17:00再执行!
2024-06-19 00:10:43 [INFO ] ---- 程序开始,当前仓库版本为1.4.1,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-19 00:10:43 [INFO ] ---- chromium-driver version is 120
2024-06-19 00:10:43 [DEBUG ] ---- enable_database_storage为true,将会储存到数据库
2024-06-19 00:10:43 [INFO ] ---- 当前登录的用户名为: 18357147789,homeassistant地址为http://192.168.123.22:8123/,程序将在每天17:00执行
2024-06-19 00:10:43 [INFO ] ---- 此次为首次运行,当前时间早于 JOB_START_TIME: 17:00,17:00再执行!
2024-06-19 00:12:40 [INFO ] ---- 程序开始,当前仓库版本为1.4.1,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-19 00:12:41 [INFO ] ---- chromium-driver version is 120
2024-06-19 00:12:41 [DEBUG ] ---- enable_database_storage为true,将会储存到数据库
2024-06-19 00:12:41 [INFO ] ---- 当前登录的用户名为: 18357147789,homeassistant地址为http://192.168.123.22:8123/,程序将在每天17:00执行
2024-06-19 00:12:41 [INFO ] ---- 此次为首次运行,当前时间早于 JOB_START_TIME: 17:00,17:00再执行!
2024-06-19 00:23:20 [INFO ] ---- 程序开始,当前仓库版本为1.4.1,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-19 00:23:21 [INFO ] ---- chromium-driver version is 120
2024-06-19 00:23:21 [DEBUG ] ---- enable_database_storage为true,将会储存到数据库
2024-06-19 00:23:21 [INFO ] ---- 当前登录的用户名为: 18357147789,homeassistant地址为http://192.168.123.22:8123/,程序将在每天17:00执行
2024-06-19 00:23:21 [INFO ] ---- 此次为首次运行,当前时间早于 JOB_START_TIME: 17:00,17:00再执行!

获取30天用电量的时候报错

麻烦大佬看一下哈:

root@docker:~/sgcc_electricity_new# docker logs -f sgcc_electricity 
2024-06-11 00:47:45  [INFO    ] ---- 程序开始,当前仓库版本为1.3.3,仓库地址为https://github.com/ARC-MX/sgcc_electricity_new.git
2024-06-11 00:47:45  [INFO    ] ---- chromium-driver version is 120
2024-06-11 00:47:45  [INFO    ] ---- MongoDB connection test successful
2024-06-11 00:47:45  [INFO    ] ---- 当前登录的用户名为: {{手机号}},homeassistant地址为http://192.168.2.3:8123/,程序将在每天00:00执行
2024-06-11 00:47:45  [INFO    ] ---- 此次为首次运行,等待时间(FIRST_SLEEP_TIME)为10秒,可在.env中设置
2024-06-11 00:47:55  [INFO    ] ---- patching driver executable /usr/bin/chromedriver
2024-06-11 00:48:06  [INFO    ] ---- Webdriver initialized.
2024-06-11 00:48:07  [INFO    ] ---- Open LOGIN_URL:https://www.95598.cn/osgweb/login
2024-06-11 00:48:17  [INFO    ] ---- find_element 'user'.
2024-06-11 00:48:28  [INFO    ] ---- input_elements username : {{手机号}}
2024-06-11 00:48:28  [INFO    ] ---- input_elements password : {{密码}}
2024-06-11 00:48:28  [INFO    ] ---- Click the Agree option.
2024-06-11 00:48:58  [INFO    ] ---- Click login button.
2024-06-11 00:48:58  [INFO    ] ---- Get electricity canvas image successfully.
2024-06-11 00:48:58  [INFO    ] ---- Image CaptCHA distance is 275.
2024-06-11 00:49:09  [INFO    ] ---- Login successfully on https://www.95598.cn/osgweb/login
2024-06-11 00:49:29  [INFO    ] ---- 将获取1户数据,user_id: ['{{户号}}']
2024-06-11 00:49:51  [INFO    ] ---- Get electricity charge balance for {{户号}} successfully, balance is 216.04 CNY.
2024-06-11 00:50:13  [INFO    ] ---- Get year power usage for {{户号}} successfully, usage is 2167 kwh
2024-06-11 00:50:13  [INFO    ] ---- Get year power charge for {{户号}} successfully, yealrly charge is 1159.9 CNY
2024-06-11 00:50:23  [INFO    ] ---- Get month power charge for {{户号}} successfully, 2024-01-01-2024-01-31 usage is 457 KWh, charge is 248.32 CNY.
2024-06-11 00:50:23  [INFO    ] ---- Get month power charge for {{户号}} successfully, 2024-02-01-2024-02-29 usage is 375 KWh, charge is 194.11 CNY.
2024-06-11 00:50:23  [INFO    ] ---- Get month power charge for {{户号}} successfully, 2024-03-01-2024-03-31 usage is 469 KWh, charge is 257.9 CNY.
2024-06-11 00:50:23  [INFO    ] ---- Get month power charge for {{户号}} successfully, 2024-04-01-2024-04-30 usage is 451 KWh, charge is 243.53 CNY.
2024-06-11 00:50:23  [INFO    ] ---- Get month power charge for {{户号}} successfully, 2024-05-01-2024-05-31 usage is 415 KWh, charge is 216.04 CNY.
2024-06-11 00:51:34  [ERROR   ] ---- Webdriver quit abnormly, reason: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='pane-second']/div[1]/div/label[2]/span[1]"}
  (Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x5dd4fb711233 <unknown>
#1 0x5dd4fb3db0fe <unknown>
#2 0x5dd4fb424ba6 <unknown>
#3 0x5dd4fb424cc1 <unknown>
#4 0x5dd4fb472204 <unknown>
#5 0x5dd4fb45244d <unknown>
#6 0x5dd4fb46f680 <unknown>
#7 0x5dd4fb4521a3 <unknown>
#8 0x5dd4fb41713e <unknown>
#9 0x5dd4fb418712 <unknown>
#10 0x5dd4fb6e6534 <unknown>
#11 0x5dd4fb6e9759 <unknown>
#12 0x5dd4fb6e9238 <unknown>
#13 0x5dd4fb6e9c05 <unknown>
#14 0x5dd4fb6d8abf <unknown>
#15 0x5dd4fb6e9f8e <unknown>
#16 0x5dd4fb6c2c86 <unknown>
#17 0x5dd4fb7023e5 <unknown>
#18 0x5dd4fb7025cb <unknown>
#19 0x5dd4fb7107bf <unknown>
#20 0x72030cb31ea7 start_thread
. 5 retry times left.
2024-06-11 00:51:34  [ERROR   ] ---- state-refresh task failed, reason is cannot unpack non-iterable NoneType object
Traceback (most recent call last):
  File "/app/data_fetcher.py", line 254, in fetch
    return self._fetch()
  File "/app/data_fetcher.py", line 287, in _fetch
    last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list  = self._get_other_data(driver, user_id_list)
  File "/app/data_fetcher.py", line 438, in _get_other_data
    self.save_30_days_usage(driver, user_id_list[i - 1])
  File "/app/data_fetcher.py", line 561, in save_30_days_usage
    self._click_button(driver, By.XPATH, "//*[@id='pane-second']/div[1]/div/label[2]/span[1]")
  File "/app/data_fetcher.py", line 590, in _click_button
    click_element = driver.find_element(button_search_type, button_search_key)
  File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 856, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='pane-second']/div[1]/div/label[2]/span[1]"}
  (Session info: chrome=120.0.6099.224)
Stacktrace:
#0 0x5dd4fb711233 <unknown>
#1 0x5dd4fb3db0fe <unknown>
#2 0x5dd4fb424ba6 <unknown>
#3 0x5dd4fb424cc1 <unknown>
#4 0x5dd4fb472204 <unknown>
#5 0x5dd4fb45244d <unknown>
#6 0x5dd4fb46f680 <unknown>
#7 0x5dd4fb4521a3 <unknown>
#8 0x5dd4fb41713e <unknown>
#9 0x5dd4fb418712 <unknown>
#10 0x5dd4fb6e6534 <unknown>
#11 0x5dd4fb6e9759 <unknown>
#12 0x5dd4fb6e9238 <unknown>
#13 0x5dd4fb6e9c05 <unknown>
#14 0x5dd4fb6d8abf <unknown>
#15 0x5dd4fb6e9f8e <unknown>
#16 0x5dd4fb6c2c86 <unknown>
#17 0x5dd4fb7023e5 <unknown>
#18 0x5dd4fb7025cb <unknown>
#19 0x5dd4fb7107bf <unknown>
#20 0x72030cb31ea7 start_thread

Traceback (most recent call last):
  File "/app/main.py", line 57, in run_task
    user_id_list, balance_list, last_daily_date_list, last_daily_usage_list, yearly_charge_list, yearly_usage_list, month_list, month_usage_list, month_charge_list = data_fetcher.fetch()
TypeError: cannot unpack non-iterable NoneType object

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.