'''
Author: Thund1r thund1r@foxmail.com
Date: 2022-09-22 14:31:16
LastEditTime: 2022-10-08 22:12:16
Description: ç–«æƒ…æ•°æ�®

Copyright (c) 2022 by Thund1r thund1r@foxmail.com, All Rights Reserved. 
'''
# -*- coding: utf8 -*-
import config
import requests


yqcity_list = config.get_list("yqcity")


# è�·å�–åŸ�å¸‚ç–«æƒ…æ•°æ�®
def get_yq(city_name):
    try:
        res = requests.get(
            f'https://covid.myquark.cn/quark/covid/data/index_data?format=json&method=Huoshenshan.ncov2022&city={city_name}').json()['data']
        if len(res['cityData']) == 0:
            res['cityData'] = res['provinceData']
        yq_res_list = [
            {"desc": "ğŸ¤’ æ–°å¢�ç¡®è¯Š/æ— ç—‡çŠ¶",
                "detail": str(res['cityData']["sure_new_loc"])+"/" + str(res['cityData']["sure_new_hid"])},
            {"desc": "ğŸ˜· ç�°æœ‰ç¡®è¯Š",
                "detail": res['cityData']["present"]},
            {"desc": "â›”ï¸� ä¸­/é«˜é£�é™©åŒº",
                "detail": str(res['cityData']["danger"]["1"]) + "/" + str(res['cityData']["danger"]["2"])}
        ]
        yq_tip_list = []
        yq_tip_list.append(f'ğŸ�¥ {city_name}ç–«æƒ…ï¼ˆ{(res["time"][4:])}ï¼‰')
        for item in yq_res_list:
            yq_tip_list.append(item['desc'] + "ï¼š" + str(item['detail']))
        yq_tip = '\n'.join(yq_tip_list)
        return yq_tip
    except Exception as e:
        print("è�·å�–ç–«æƒ…æ•°æ�®é”™è¯¯ï¼š", e)
        return None


# è�·å�–æ‰€æœ‰ç–«æƒ…æ•°æ�®
def get_map_yq():
    if yqcity_list:
        map_yq_tip = None
        yq_list = list(map(get_yq, yqcity_list))
        yq_list = list(filter(None, yq_list))
        if yq_list:
            map_yq_tip = "\n".join(yq_list)
        return map_yq_tip
    else:
        print("æ²¡æœ‰å¡«å†™ç–«æƒ…æ•°æ�®åŸ�å¸‚")
        return None
