# -*- coding:UTF-8 -*-
# @Time  : 2020/12/4 13:24
# @File  : temp_doris_to_redis.py
# @email : litao@igengmei.com
# @author : litao
import time

city_list = {
"sichuan":298,
"xinjiang":299,
"neimenggu":300,
"xinjiang":301,
"xizang":302,
"hainan":303,
"shanxi":304,
"yunnan":305,
"anhui":306,
"liaoning":307,
"guizhou":308,
"henan":309,
"aomen":310,
"jilin":311,
"guangxi":312,
"hainan":313,
"jilin":314,
"gansu":315,
"tianjin":316,
"hebei":317,
"shanxi":318,
"yunnan":319,
"hainan":320,
"neimenggu":321,
"neimenggu":322,
"xinjiang":323,
"sichuan":324,
"chongqing":325,
"tianjin":326,
"guangxi":327,
"beijing":328,
"anhui":329,
"liaoning":330,
"guizhou":331,
"shandong":332,
"chongqing":333,
"xinjiang":334,
"anhui":335,
"hebei":336,
"jilin":337,
"hunan":338,
"xizang":339,
"xinjiang":340,
"hainan":341,
"beijing":342,
"hunan":343,
"chongqing":344,
"jiangsu":345,
"shannxi":346,
"jiangsu":347,
"anhui":348,
"beijing":349,
"guangdong":350,
"hebei":351,
"sichuan":352,
"chongqing":353,
"hainan":354,
"hunan":355,
"neimenggu":356,
"anhui":357,
"shanghai":358,
"chongqing":359,
"guangxi":360,
"yunnan":361,
"anhui":362,
"tianjin":363,
"yunnan":364,
"liaoning":365,
"liaoning":366,
"aomen":367,
"hainan":368,
"heilongjiang":369,
"shannxi":370,
"beijing":371,
"heilongjiang":372,
"sichuan":373,
"chongqing":374,
"yunnan":375,
"sichuan":376,
"shandong":377,
"chongqing":378,
"gansu":379,
"yunnan":380,
"hainan":381,
"guangdong":382,
"dongjingdu":2669,
"tianjin":383,
"zhejiang":384,
"shandong":385,
"neimenggu":386,
"hubei":387,
"hubei":388,
"guangxi":389,
"beijing":390,
"chongqing":391,
"chongqing":392,
"beijing":393,
"shanghai":394,
"guangdong":395,
"chongqing":396,
"liaoning":397,
"liaoning":398,
"anhui":399,
"fujian":400,
"jiangxi":401,
"gansu":402,
"jiangxi":403,
"sichuan":404,
"taiwan":405,
"qinghai":406,
"sichuan":407,
"sichuan":408,
"guangdong":409,
"guangxi":410,
"guangxi":411,
"guizhou":412,
"qinghai":413,
"ningxia":414,
"heilongjiang":415,
"qinghai":416,
"beijing":417,
"qinghai":418,
"hainan":419,
"qinghai":420,
"qinghai":421,
"xinjiang":422,
"hebei":423,
"tianjin":424,
"zhejiang":425,
"shanxi":426,
"anhui":430,
"henan":427,
"guangxi":428,
"chongqing":429,
"anhui":430,
"heilongjiang":431,
"heilongjiang":432,
"shannxi":433,
"hebei":434,
"hunan":435,
"xinjiang":436,
"guangdong":437,
"shandong":438,
"guangxi":439,
"yunnan":440,
"jiangsu":441,
"anhui":442,
"hunan":443,
"anhui":444,
"beijing":445,
"taiwan":446,
"hubei":447,
"qinghai":448,
"anhui":449,
"hubei":450,
"neimenggu":451,
"guangdong":452,
"liaoning":453,
"neimenggu":454,
"zhejiang":455,
"shanghai":456,
"heilongjiang":457,
"jiangxi":458,
"chongqing":459,
"guangdong":460,
"sichuan":461,
"henan":462,
"zhejiang":463,
"taiwan":464,
"gansu":465,
"guangdong":466,
"jilin":467,
"shandong":468,
"gansu":469,
"shannxi":470,
"jiangxi":471,
"tianjin":472,
"jiangsu":1681,
"hubei":473,
"hubei":474,
"zhejiang":475,
"shandong":476,
"tianjin":477,
"shanghai":478,
"shannxi":479,
"liaoning":480,
"jiangxi":481,
"xianggang":482,
"gansu":483,
"heilongjiang":484,
"tianjin":485,
"henan":486,
"jizhoutebiezizhidao":2536,
"henan":487,
"chongqing":488,
"xinjiang":489,
"xinjiang":490,
"xinjiang":491,
"xinjiang":492,
"yunnan":493,
"jiangsu":494,
"guangxi":495,
"shandong":496,
"hebei":497,
"gansu":498,
"xizang":499,
"hainan":500,
"sichuan":501,
"chongqing":502,
"sichuan":503,
"jiangsu":504,
"shandong":505,
"liaoning":506,
"jilin":507,
"yunnan":508,
"yunnan":509,
"shannxi":510,
"hainan":511,
"hainan":512,
"gansu":513,
"shandong":514,
"xizang":515,
"zhejiang":516,
"anhui":517,
"guizhou":518,
"guangxi":519,
"gansu":520,
"fujian":521,
"hunan":522,
"aomen":523,
"henan":524,
"henan":525,
"sichuan":526,
"shannxi":527,
"anhui":528,
"mangu":3936,
"guangdong":529,
"sichuan":530,
"guangdong":531,
"beijing":532,
"sichuan":533,
"taiwan":534,
"shanghai":535,
"beijing":536,
"shandong":284,
"heilongjiang":537,
"jiangxi":538,
"sichuan":539,
"chongqing":540,
"shanghai":541,
"jiangsu":542,
"guangxi":543,
"fujian":544,
"jiangsu":545,
"taiwan":546,
"henan":547,
"xizang":548,
"sichuan":549,
"zhejiang":550,
"fujian":551,
"tianjin":552,
"yunnan":553,
"liaoning":554,
"sichuan":555,
"chongqing":556,
"henan":557,
"taiwan":558,
"beijing":559,
"gansu":560,
"jiangxi":561,
"shanghai":562,
"yunnan":563,
"fujian":564,
"henan":565,
"guizhou":566,
"hubei":567,
"chongqing":568,
"guizhou":569,
"guizhou":570,
"chongqing":571,
"shandong":572,
"shanghai":573,
"gansu":574,
"guangdong":575,
"hebei":576,
"guangxi":577,
"hainan":578,
"hainan":579,
"heilongjiang":580,
"heilongjiang":581,
"fujian":582,
"yunnan":583,
"zhejiang":584,
"xizang":585,
"shandong":586,
"chongqing":587,
"shandong":588,
"henan":589,
"fujian":590,
"hainan":591,
"shanghai":592,
"shanxi":593,
"henan":594,
"jiangxi":595,
"xizang":596,
"guangdong":597,
"guangdong":598,
"guangdong":599,
"zhejiang":600,
"hunan":601,
"zhejiang":7401,
"hubei":602,
"liaoning":603,
"guangdong":604,
"xinjiang":605,
"hebei":606,
"beijing":607,
"hubei":608,
"shanghai":609,
"chongqing":610,
"ningxia":611,
"shouer":612,
"heilongjiang":613,
"guangdong":1033,
"beijing":614,
"shannxi":615,
"jilin":616,
"shanghai":617,
"jilin":618,
"heilongjiang":619,
"sichuan":620,
"hubei":621,
"jiangsu":622,
"jiangsu":623,
"anhui":624,
"xinjiang":625,
"shandong":626,
"taiwan":627,
"jiangsu":628,
"taiwan":629,
"taiwan":630,
"shannxi":631,
"taiwan":632,
"jiangsu":633,
"zhejiang":634,
"tianjin":635,
"hebei":636,
"taiwan":637,
"tianjin":638,
"hubei":639,
"gansu":640,
"liaoning":641,
"shanxi":642,
"jilin":643,
"chongqing":644,
"neimenggu":645,
"anhui":646,
"chongqing":647,
"guizhou":648,
"beijing":649,
"xinjiang":650,
"hainan":651,
"hainan":652,
"chongqing":653,
"chongqing":654,
"shandong":655,
"shandong":656,
"shanxi":657,
"hainan":658,
"yunnan":659,
"zhejiang":660,
"neimenggu":661,
"hubei":662,
"anhui":663,
"neimenggu":664,
"chongqing":665,
"xinjiang":666,
"tianjin":667,
"chongqing":668,
"gansu":669,
"jiangsu":670,
"hainan":671,
"ningxia":672,
"guangxi":673,
"fujian":674,
"shanxi":675,
"xianggang":677,
"hunan":678,
"hunan":679,
"hubei":676,
"hubei":680,
"hubei":681,
"shanxi":682,
"hubei":683,
"neimenggu":684,
"neimenggu":685,
"hebei":686,
"xinnanweiershizhou":7382,
"qinghai":687,
"xinjiapo":5188,
"xianggang":688,
"henan":689,
"henan":690,
"jiangxi":691,
"shannxi":692,
"taiwan":693,
"tianjin":694,
"yunnan":695,
"chongqing":696,
"anhui":697,
"henan":698,
"jiangsu":699,
"sichuan":700,
"shanxi":701,
"jilin":702,
"jiangsu":703,
"guangdong":704,
"shannxi":705,
"jiangsu":706,
"jilin":707,
"beijing":708,
"shandong":709,
"sichuan":710,
"hubei":711,
"heilongjiang":712,
"jiangxi":713,
"taiwan":714,
"xinjiang":715,
"ningxia":716,
"liaoning":717,
"jiangxi":718,
"zhejiang":297,
"hunan":719,
"chongqing":720,
"hunan":721,
"chongqing":722,
"chongqing":723,
"hunan":724,
"guangxi":725,
"shanxi":726,
"shannxi":727,
"guangdong":728,
"taiwan":729,
"chongqing":730,
"qinghai":731,
"yunnan":732,
"shandong":733,
"taiwan":734,
"jiangsu":735,
"hunan":736,
"hebei":737,
"jiangxi":738,
"gansu":739,
"fujian":740,
"guangdong":741,
"guangdong":742,
"yunnan":743,
"henan":744,
"jiangsu":745,
"guangdong":746,
"ningxia":747,
"chongqing":748,
"henan":749,
"zhejiang":750,
"guangdong":751,
"henan":752,
"hunan":753,
"shandong":754,
"sichuan":755,
"sichuan":756,
"guizhou":757,
}
import requests
import redis
import json
headers = {'X-GAIA-HELIOS-VERSION': '0.7.4','X-GM-Request-Id': '123','x-gm-path': '/6261582/','X-GM-Rpc-Method': 'doris/search/query_sku',}

data = {'requests': '[{\"request_id\": null, \"method\": \"doris/search/query_sku\", \"params\": {\"sort_with_submission\": true, \"or_filters\": [], \"sort_params\": {\"lat\": 40.001815, \"lng\": 116.487356, \"in_whitelist\": 1, \"user_city_tag_id\": 328, \"device_id\": \"androidid_ba0799595f555c98\"}, \"sort_type\": 0, \"use_tagv3\": false, \"filters\": {\"tag_ids\": [2944, 776, 137, 777, 141, 789, 152, 804, 954, 197, 200, 203, 5074, 97, 99, 868, 14699, 2412, 14700, 115, 243, 885, 14198, 121, 123]}, \"offset\": 0, \"query\": \"\", \"is_sort_with_icon\": true, \"user_city_tag_id\": 328, \"size\": 10}, \"environment\": {\"trace_context\": {\"debug\": false, \"sampled\": false, \"trace_id\": \"1abd5ea122024a32827e0a0dd8ad45eb\", \"span_id\": \"0.2\"}, \"l5d_path\": \"/prod/gaia\", \"passport\": null, \"client_info\": {\"log_id\": \"gaia.z1l7e4odb43efc0179047f890fc023ba\", \"span_id\": \"z1l7e4o0ffec82d12944357b60360e80\"}, \"session_id\": \"ifop8w1o4spoe969kxd6yh77wzgtsz3c\"}}]'}
# print(data)
response = requests.post('http://172.16.50.10:8050/v1/batch', headers=headers, data=data)
data = json.dumps(response.json())
print(data)
# rds = redis.StrictRedis.from_url("redis://:XfkMCCdWDIU%ls$h3@172.16.50.159:6379", decode_responses=True)
query_list = ["1"]
for query in query_list:
    res = json.dumps(query)
    for city in city_list:
        try:
            key = "meigou_" + city + "_" + query
            # if rds.exists(key):
            #     continue
            data = {
                'requests': '[{\"request_id\": null, \"method\": \"doris/search/query_sku\", \"params\": {\"sort_with_submission\": true, \"or_filters\": [], \"sort_params\": {\"lat\": 40.001815, \"lng\": 116.487356, \"in_whitelist\": 1, \"user_city_tag_id\": 328, \"device_id\": \"androidid_ba0799595f555c98\"}, \"sort_type\": 0, \"use_tagv3\": false, \"filters\": {\"tag_ids\": [2944, 776, 137, 777, 141, 789, 152, 804, 954, 197, 200, 203, 5074, 97, 99, 868, 14699, 2412, 14700, 115, 243, 885, 14198, 121, 123]}, \"offset\": 0, \"query\": \"\", \"is_sort_with_icon\": true, \"user_city_tag_id\": 328, \"size\": 10}, \"environment\": {\"trace_context\": {\"debug\": false, \"sampled\": false, \"trace_id\": \"1abd5ea122024a32827e0a0dd8ad45eb\", \"span_id\": \"0.2\"}, \"l5d_path\": \"/prod/gaia\", \"passport\": null, \"client_info\": {\"log_id\": \"gaia.z1l7e4odb43efc0179047f890fc023ba\", \"span_id\": \"z1l7e4o0ffec82d12944357b60360e80\"}, \"session_id\": \"ifop8w1o4spoe969kxd6yh77wzgtsz3c\"}}]'
            }
            # print(data)
            response = requests.post('http://backend.pass-develop.env/v1/batch', headers=headers, data=data)
            data = json.dumps(response.json())
            time.sleep(0.2)
            print(response.json())
            print(key)
            # rds.set(key,data)
        except:
            continue
        # break