Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3648145
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2022-10-27 11:50:48

import hashlib

import os

import requests

import time

import sys

import json

import csv

#显示某等级地区的小计

def show_level_count(x_list):

    j=0

    for i in range(len(x_list)):

        j+=len (x_list[i]["communitys"])

    print(j)

    return j

def writer_to_csv(risk_txt):

    risk_json = json.loads(risk_txt)

    so_far_time = risk_json["data"]["end_update_time"]

    highlist = risk_json["data"]["highlist"]

    middlelist = risk_json["data"]["middlelist"]

    lowlist = risk_json["data"]["lowlist"]

    encoding='utf-8'

    encoding='gbk'

    f = open('risk_data_' + so_far_time + '.csv','w', encoding=encoding,newline='')

    csv_writer = csv.writer(f)

    level_dict={}    

    level_dict["高风险"]=highlist

    level_dict["中风险"]=middlelist

    level_dict["低风险"]=lowlist

    for level in  level_dict.keys():

        risk_level = level

        for i in range(len(level_dict[level])):

            province = level_dict[level][i]["province"]

            city = level_dict[level][i]["city"]

            county = level_dict[level][i]["county"]

            for j in range(len(level_dict[level][i]["communitys"])):

                csv_writer.writerow(

                    [risk_level, province, city, county, level_dict[level][i]["communitys"][j]])

    # write_to_csv_file(csv_writer, highlist, "高风险")

    # write_to_csv_file(csv_writer, middlelist, "中风险")

    # write_to_csv_file(csv_writer, lowlist, "低风险")

    f.close()

    print("写入risk_data.csv完成.")

def get_risk_area_data():

    timestamp = 外汇跟单gendan5.comstr(int(time.time()))

    # timestamp = '1662646358'

    x_wif_timestamp = timestamp

    timestampHeader = timestamp

    x_wif_nonce = 'QkjjtiLM2dCratiA'

    x_wif_paasid = 'smt-application'

    x_wif_signature_str = timestamp + \

        'fTN2pfuisxTavbTuYVSsNJHetwq5bJvCQkjjtiLM2dCratiA'+timestamp

    x_wif_signature = hashlib.sha256(

        x_wif_signature_str.encode('utf-8')).hexdigest().upper()

    signatureHeader_str = timestamp + \

        '23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA'+'123456789abcdefg'+timestamp

    signatureHeader = hashlib.sha256(

        signatureHeader_str.encode('utf-8')).hexdigest().upper()

    url = ''

    headerss = {

        'Accept': "application/json, text/plain, */*",

        'Content-Type': "application/json;charset=utf-8",

        'x-wif-nonce': "QkjjtiLM2dCratiA",

        'x-wif-paasid': "smt-application",

        'x-wif-signature': x_wif_signature,

        'x-wif-timestamp': x_wif_timestamp,

    }

    From_data = "{\"key\":\"3C502C97ABDA40D0A60FBEE50FAAD1DA\",\

    \"appId\":\"NcApplication\",\"paasHeader\":\"zdww\",\

    \"timestampHeader\":\"" + timestampHeader + "\",\

    \"nonceHeader\":\"123456789abcdefg\",\"signatureHeader\":\"" + signatureHeader + "\"}"

    # print(From_data)

    response = requests.post(url=url, data=From_data, headers=headerss)

    if not response.status_code == 200:

        # print(response.status_code)

        return "", response.status_code

    # print(response.text)    

    return response.text.replace('\u2022', ''), response.status_code

if __name__ == '__main__':

    risk_data=get_risk_area_data()

    if risk_data[1]==200:    

        with open('./risk_data.json', 'w',encoding='utf-8') as f:

            f.write(risk_data[0])

        print("写入risk_data.log完成.")

    f = open('risk_data.json', 'r', encoding='utf-8')

    risk_txt = f.read()

    f.close()

    writer_to_csv(risk_txt)

    print('全部程序完成,请勿频繁使用!')

    os.system('pause')    

阅读(826) | 评论(0) | 转发(0) |
0

上一篇:openCV实践项目

下一篇:Python图形处理

给主人留下些什么吧!~~