import json

import requests
import time


# url = 'http://test.dvema.com'
# base_url = 'http://127.0.0.1:8000/'
base_url = 'http://dvema.com/'
username='13800138001'
password='ansjer.x123789'
login_url = base_url + 'account/login'

data = {
    'userName': username,
    'userPwd': password
}
res = requests.post(url=login_url, data=data)
res = res.json()

if res['result_code'] == 0:
    request_times = 0
    while request_times < 5:
        try:
            statistics_url = base_url + 'faq/synZositechHelp'
            # zh_url = 'https://mobileapphelp.zendesk.com/api/v2/help_center/articles/embeddable_search.json?locale=zh-cn&section=null&origin=web_widget'
            zh_url = 'https://mobileapphelp.zendesk.com/api/v2/help_center/zh-cn/articles.json?page%5Bsize%5D=100'
            zhcnDatares = requests.get(url=zh_url, timeout=10).text

            en_url = 'https://mobileapphelp.zendesk.com/api/v2/help_center/en-us/articles.json?page%5Bsize%5D=100'
            # en_url = 'https://mobileapphelp.zendesk.com/api/v2/help_center/articles/embeddable_search.json?locale=en-us&section=null&origin=web_widget'
            enusDatares = requests.get(url=en_url, timeout=10).text
            data = {
                'token': res['result']['access_token'],
                'zhresults': zhcnDatares,
                'enresults': enusDatares
            }
            res = requests.post(url=statistics_url, data=data)

        except Exception as e:
            print(e)
            request_times += 1
            print(request_times)
            time.sleep(3)

print('success')



