import requests
import json
import base64
import os

apikey = "4fc3a688d6aaf8c4368bad7acf78c9e7"
if (True):
    input = "upload"
    outputformat = "pdf"
    headers = {'Content-Type': 'application/json'}
    urlbegin = "https://api.convertio.co/convert"
    data_begin = {
        "apikey": apikey,
        "input": "upload",
        "outputformat": outputformat,
        "filename": "123.doc"
    }

    req = requests.post(urlbegin, json.dumps(data_begin), headers=headers)
    result = json.loads(req.text)
    id = result['data']['id']
    print(id)
urlupload = "https://api.convertio.co/convert/" + id + "/123.doc"
#file = open('123.doc', 'rb')
files = {'file': open('E:/UnitAi-Project/client/experimentfile/文件在线转换api测试(完成修正，待验证)/123.doc', 'rb')}
req = requests.put(urlupload, files=files)
result = json.loads(req.text)
print(result)
print("begin!")
urlcheck = "https://api.convertio.co/convert/" + id + "/status"

while 1:
    req = requests.get(urlcheck)
    result1 = json.loads(req.text)
    try:
        if (result1['data']['step'] == "finish"):
            break
        else:
            print("Waiting")
            # print(result['data']['step_percent'])
    except:
        print(result1)

urlfinish = "https://api.convertio.co/convert/" + id + "/dl/base64"

req = requests.get(urlfinish, headers=headers)
result = json.loads(req.text)
try:
    base = result['data']['content']
    print(result)
except:
    print(result)

# print(base)
imgdata = base64.b64decode(base)
file = open('123.pdf', 'wb')
file.write(imgdata)
file.close()

4f2a5481f03fb59e27c33c414c117b0e6343d2d0
<mask token>

<mask token>
if True:
    input = 'upload'
    outputformat = 'pdf'
    headers = {'Content-Type': 'application/json'}
    urlbegin = 'https://api.convertio.co/convert'
    data_begin = {'apikey': apikey, 'input': 'upload', 'outputformat':
        outputformat, 'filename': '123.doc'}
    req = requests.post(urlbegin, json.dumps(data_begin), headers=headers)
    result = json.loads(req.text)
    id = result['data']['id']
    print(id)
<mask token>
print(result)
print('begin!')
<mask token>
while 1:
    req = requests.get(urlcheck)
    result1 = json.loads(req.text)
    try:
        if result1['data']['step'] == 'finish':
            break
        else:
            print('Waiting')
    except:
        print(result1)
<mask token>
try:
    base = result['data']['content']
    print(result)
except:
    print(result)
<mask token>
file.write(imgdata)
file.close()

<mask token>
apikey = '4fc3a688d6aaf8c4368bad7acf78c9e7'
if True:
    input = 'upload'
    outputformat = 'pdf'
    headers = {'Content-Type': 'application/json'}
    urlbegin = 'https://api.convertio.co/convert'
    data_begin = {'apikey': apikey, 'input': 'upload', 'outputformat':
        outputformat, 'filename': '123.doc'}
    req = requests.post(urlbegin, json.dumps(data_begin), headers=headers)
    result = json.loads(req.text)
    id = result['data']['id']
    print(id)
urlupload = 'https://api.convertio.co/convert/' + id + '/123.doc'
files = {'file': open(
    'E:/UnitAi-Project/client/experimentfile/文件在线转换api测试(完成修正，待验证)/123.doc',
    'rb')}
req = requests.put(urlupload, files=files)
result = json.loads(req.text)
print(result)
print('begin!')
urlcheck = 'https://api.convertio.co/convert/' + id + '/status'
while 1:
    req = requests.get(urlcheck)
    result1 = json.loads(req.text)
    try:
        if result1['data']['step'] == 'finish':
            break
        else:
            print('Waiting')
    except:
        print(result1)
urlfinish = 'https://api.convertio.co/convert/' + id + '/dl/base64'
req = requests.get(urlfinish, headers=headers)
result = json.loads(req.text)
try:
    base = result['data']['content']
    print(result)
except:
    print(result)
imgdata = base64.b64decode(base)
file = open('123.pdf', 'wb')
file.write(imgdata)
file.close()

import requests
import json
import base64
import os
apikey = '4fc3a688d6aaf8c4368bad7acf78c9e7'
if True:
    input = 'upload'
    outputformat = 'pdf'
    headers = {'Content-Type': 'application/json'}
    urlbegin = 'https://api.convertio.co/convert'
    data_begin = {'apikey': apikey, 'input': 'upload', 'outputformat':
        outputformat, 'filename': '123.doc'}
    req = requests.post(urlbegin, json.dumps(data_begin), headers=headers)
    result = json.loads(req.text)
    id = result['data']['id']
    print(id)
urlupload = 'https://api.convertio.co/convert/' + id + '/123.doc'
files = {'file': open(
    'E:/UnitAi-Project/client/experimentfile/文件在线转换api测试(完成修正，待验证)/123.doc',
    'rb')}
req = requests.put(urlupload, files=files)
result = json.loads(req.text)
print(result)
print('begin!')
urlcheck = 'https://api.convertio.co/convert/' + id + '/status'
while 1:
    req = requests.get(urlcheck)
    result1 = json.loads(req.text)
    try:
        if result1['data']['step'] == 'finish':
            break
        else:
            print('Waiting')
    except:
        print(result1)
urlfinish = 'https://api.convertio.co/convert/' + id + '/dl/base64'
req = requests.get(urlfinish, headers=headers)
result = json.loads(req.text)
try:
    base = result['data']['content']
    print(result)
except:
    print(result)
imgdata = base64.b64decode(base)
file = open('123.pdf', 'wb')
file.write(imgdata)
file.close()

import requests
import json
import base64
import os

apikey = "4fc3a688d6aaf8c4368bad7acf78c9e7"
if (True):
    input = "upload"
    outputformat = "pdf"
    headers = {'Content-Type': 'application/json'}
    urlbegin = "https://api.convertio.co/convert"
    data_begin = {
        "apikey": apikey,
        "input": "upload",
        "outputformat": outputformat,
        "filename": "123.doc"
    }

    req = requests.post(urlbegin, json.dumps(data_begin), headers=headers)
    result = json.loads(req.text)
    id = result['data']['id']
    print(id)
urlupload = "https://api.convertio.co/convert/" + id + "/123.doc"
#file = open('123.doc', 'rb')
files = {'file': open('E:/UnitAi-Project/client/experimentfile/文件在线转换api测试(完成修正，待验证)/123.doc', 'rb')}
req = requests.put(urlupload, files=files)
result = json.loads(req.text)
print(result)
print("begin!")
urlcheck = "https://api.convertio.co/convert/" + id + "/status"

while 1:
    req = requests.get(urlcheck)
    result1 = json.loads(req.text)
    try:
        if (result1['data']['step'] == "finish"):
            break
        else:
            print("Waiting")
            # print(result['data']['step_percent'])
    except:
        print(result1)

urlfinish = "https://api.convertio.co/convert/" + id + "/dl/base64"

req = requests.get(urlfinish, headers=headers)
result = json.loads(req.text)
try:
    base = result['data']['content']
    print(result)
except:
    print(result)

# print(base)
imgdata = base64.b64decode(base)
file = open('123.pdf', 'wb')
file.write(imgdata)
file.close()
