cykablyat 发表于 2022-3-14 22:29

【初学练手】使用python获取风险城市

最近想知道全国有哪些城市是有风险地区的 但网上找到的会把具体地区也显示出来,看着太多了,于是自己动手写(gai)一个,因为本人是三天打鱼两天晒网的python菜鸡,所以代码写的很烂 各位还请多多指教。另外官方的数据接口做了加密,以我的水平那肯定是破不了的,所以解密方法参考(zhaoban)了论坛里@cflying大佬在帖子 疫情等级查里发的的方法。import requests
import time
import hashlib


def main():
    url_ = "http://103.66.32.242:8005/zwfwMovePortal/interface/interfaceJson"
    timestamp_ = str(time.time())[:10]
    no256sign = str(timestamp_) + "23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA" + "123456789abcdefg" + str(timestamp_)
    signature = hashlib.sha256(no256sign.encode('utf-8')).hexdigest().upper()

    data_ ={"appId": "NcApplication",
    "key": "3C502C97ABDA40D0A60FBEE50FAAD1DA",
    "nonceHeader": "123456789abcdefg",
    "paasHeader": "zdww",
    "signatureHeader": signature,
    "timestampHeader": str(timestamp_)}

    no256smt_sig = str(timestamp_) + "fTN2pfuisxTavbTuYVSsNJHetwq5bJvCQkjjtiLM2dCratiA"+str(timestamp_)
    smt_sig = hashlib.sha256(no256smt_sig.encode('utf-8')).hexdigest().upper()


    headers_ = {'x-wif-nonce': 'QkjjtiLM2dCratiA',
    'x-wif-paasid': 'smt-application',
    'x-wif-signature': smt_sig,
    'x-wif-timestamp': str(timestamp_),
    'Content-Type':"application/json; charset=UTF-8",
    }
    getedthings = requests.post(url_,json=data_,headers=headers_).json()
    '''print(str(getedthings))
    print(timestamp_)
    print(signature)'''
    highlist = []
    middlelist = []
    for items_ in getedthings['data']['highlist']:
      need_ = items_['province']+items_['city']
      highlist.append(need_)
      highlist = list(set(highlist))

    for items in getedthings['data']['middlelist']:
      need = items['province']+items['city']
      middlelist.append(need)
      middlelist = list(set(middlelist))
   
    print('高风险城市有:')
    for items in highlist:
      print(items)
    print("\n")
    print('中风险城市有:')
    for items in middlelist:
      print(items )

    pass

if __name__ == '__main__':
    main()
    input('press enter to exit')

TakeKeyEasy 发表于 2022-3-15 01:03

收藏,后期来学习下

wsyishui 发表于 2022-3-15 11:01

没有名称为 'requests' 的模块,没跑起来呢

rxxcy 发表于 2022-3-15 11:09

wsyishui 发表于 2022-3-15 11:01
没有名称为 'requests' 的模块,没跑起来呢

pip install requests
页: [1]
查看完整版本: 【初学练手】使用python获取风险城市