# Source: https://gitee.com/yangro/ql/blob/main/mlxh.py
# Raw: https://gitee.com/yangro/ql/raw/main/mlxh.py
# Repo: yangro/ql
# Path: mlxh.py
# UploadedAt: 2023-10-25T14:45:53+08:00
# SHA256: 5d863612d6147c435470a7801efd3dc7ad576c3505c766bf914cec230640d636
# Category: web版/抓包
# Evidence: web/H5关键词 + cookie/token/header

# coding=utf-8
"""
每日8:30
cron: 0 30 8 * * ?
new Env("美丽西湖")
"""
import urllib
from urllib import parse
import requests
import notify
import time
import re
import random

import utils.tool as TOOL
import utils.getCookie as getCookie
import utils.markdownUtil as markdown

mak = markdown.markdown(['名称', '今日', '总值'])


# 获取文章ids
def getEssays(user):
    url = "https://mlxh.hangzhou.com.cn/wechat/jkhz/api/article_list?page=1"
    headers = {
        "Connection": "keep-alive",
        "Accept": "application/json, text/plain, */*",
        "X-XSRF-TOKEN": user['cookie'],
        "User-Agent": "Mozilla/5.0 (Linux; Android 11; Redmi K20 Pro Premium Edition Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.62 XWEB/2889 MMWEBSDK/20210902 Mobile Safari/537.36 MMWEBID/1742 MicroMessenger/8.0.15.2001(0x28000F41) Process/toolsmp WeChat/arm64 Weixin GPVersion/1 NetType/4G Language/zh_CN ABI/arm64",
        "X-Requested-With": "com.tencent.mm",
        "Sec-Fetch-Site": "same-origin",
        "Sec-Fetch-Mode": "cors",
        "Referer": "//mlxh.hangzhou.com.cn/mlxh/index.html",
        "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
    }
    res = requests.get(url=url, headers=headers)
    json = res.json()
    ids = []
    for text in json['data']['list']:
        if(text['is_read'] == False):
            ids.append(text['id'])
    return ids


# 阅读文章
def lookEssay(user):
    print()



# 签到
def signIn(user):
    global mak

    ids = getEssays(user)
    print(ids)

    print(user['name'] + "---> " + '{msg}\n')
    mak.add(['{昵称}', '{状态}'])

    print("-------------------------------------------\n")


def main():
    users = getCookie.GetQlEnvs().getCookies('MLXH_TOKEN')
    print("🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉\n")
    print("获取到: "+str(len(users))+" 个用户")
    print("-------------------------------------------")

    for user in users:
        signIn(user)

try:
    main()
except requests.exceptions.JSONDecodeError as e:
    print("josn err ---> "+e)
except Exception as e:
    print("未知异常")

print("🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉")

#notify.send("美丽西湖", msg)
