2024年11月24日星期日 上午2:14:50

国家电网电费的API方案 接入ha

8 个月 前
#29612 引用
https://bbs.hassbian.com/thread-21918-1-1.html


原作者 (deleted)
https://github.com/louisslee/sgcc_electricity

平替
帮助你将国网的电费、用电量数据接入homeassistant
https://github.com/renhai-lab/sgcc_electricity



other
https://osg-static.sgcc.com.cn/app/download/index.html
0
8 个月 前
#29613 引用
https://www.95598.cn/osgweb/index

国网更新了,验证码改成了滑条了
0
8 个月 前
#29614 引用
[url]源码地址:https://github.com/okatu-loli/Electricity-Tracker[/url]
0
8 个月 前
#29615 引用


def run(pw: Playwright, nop: str, nom: int) -> None:
    browser = pw.firefox.launch(headless=True)
    context = browser.new_context(viewport={'width': 1920, 'height': 1080})
    page = context.new_page()

    page.goto("https://www.95598.cn/osgweb/login")
    page.locator(".user").click()
    page.get_by_placeholder("请输入用户名/手机号/邮箱").fill(username)
    page.get_by_placeholder("请输入密码").fill(password)
    page.locator(".code-mask").screenshot(path="yzm.png")
    # el-dropdown-menu__item
    with open("yzm.png", 'rb') as f:
        img_bytes = f.read()
    res = ocr.classification(img_bytes)
    print("图形验证码:", res)

    page.get_by_role("textbox", name="请输入验证码").fill(res)
    page.get_by_role("button", name="登录").click()

    page.get_by_role("button", name="切换用户 ").click()

    count = page.locator(".el-dropdown-menu__item").count()
    print("数量 %s", count)

    output = ""
    if count <= 1:
        number, amount = get_data(page)
        output += f"{number}:{amount}"
    else:
        for i in range(count):
            page.locator(".el-dropdown-menu__item").nth(i).click()
            time.sleep(2)
            page.get_by_role("button", name="切换用户 ").click()
            number, amount = get_data(page)
            output += f"{number}:{amount}"
            if i < count - 1:
                output += ";"
    # 将电费保存到文件
    save_amount_to_file(output)

    page.close()
    context.close()
    browser.close()

def get_data(page):
    while page.locator(".cff8").get_by_text('元').inner_text(timeout=5000)[:-1] == "--":
        time.sleep(1)
    amount = float(page.locator(".cff8").get_by_text('元').inner_text()[:-1])
    user_no = page.get_by_text("用电户号").inner_text()
    number = re.findall(r'\d+', user_no)[0]
    print(f"用户户号:{number}")
    print(f"今日电费:{amount}")
    return number, amount




https://bbs.hassbian.com/forum.php?mod=redirect&goto=findpost&ptid=21918&pid=542309
0
7 个月 前
#31947 引用
homeassistant接入国家电网电费余额(failure)
https://www.zyx.company/1790.html


https://www.zyx.company/1871.html
0