#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json

import xlwt

from Object.TokenObject import TokenObject
import base64
import requests

token = TokenObject()
token = token.generate({'userID': str(2)})

file = open('./file/UID-2020-09-09-06-14-44.txt', mode='r', encoding='utf-8')
content = file.read()
content = content.replace(' ', '\t')

file1 = open('./file/UID_2020_09_09_06_14_44.txt', mode='w', encoding='utf-8')
file1.write(content)
file1.close()

tmps = content.split('\n')
workbook = xlwt.Workbook(encoding='utf-8')
sheet1 = workbook.add_sheet('UID')
num = 0
for tmp in tmps:
    lines = tmp.split('\t')
    for i in range(len(lines)):
        sheet1.write(num, i, lines[i].strip())
    num += 1

workbook.save('./file/UID_2020_09_09_06_14_44.xls')


file.close()

# url = 'http://192.168.136.35:8000/upload'
# postData = {
#     'area': 0,
#     'token': token['access_token'],
#     'fileName': content
# }
# # postData = json.dumps(postData)
# print(postData)
# res = requests.post(url=url, data=postData)
# print(res)
