m_func.py 3.6 KB
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Date: 2020/5/28 23:13
# @Author:bxh
# @file: usiness_admin_func.py

import json
from urllib.parse import *


path = 'E:/task_api/'

def teardown_hook_get_Authorization(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        Authorization =jsondata['data']['access']['token']
    try:
        # 保存token到文件
        with open(path + 'config/Authorization.txt','w+') as f:
            f.write(Authorization)
            print('写入成功,Authorization:{}'.format(Authorization))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return Authorization

def teardown_hook_get_task_Authorization(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        Authorization =jsondata['data']['access']['accessToken']
    try:
        # 保存token到文件
        with open(path + 'config/task_Authorization.txt','w+') as f:
            f.write(Authorization)
            print('写入成功,Authorization:{}'.format(Authorization))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return Authorization

def teardown_hook_get_access_token(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        access_token =jsondata['data']['access']['token']
    try:
        # 保存token到文件
        with open(path + 'config/access_token.txt','w+') as f:
            f.write(access_token)
            print('写入成功,access_token:{}'.format(access_token))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return access_token

def teardown_hook_get_login_code(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        login_code =jsondata['data']['list'][2]['url']
        res = login_code.split("=")[1].rstrip('"')
        res = unquote(res)

    try:
        # 保存token到文件
        with open(path + 'config/login_code.txt','w+') as f:
            f.write(res)
            print('写入成功,res:{}'.format(res))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return res

def get_Authorization():
    try:
        # 保存token到文件
        with open(path + "config/Authorization.txt", 'r') as f:
            Authorization = f.read()
            print('读取成功,Authorization:{}'.format(Authorization))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return Authorization

def get_task_Authorization():
    try:
        # 保存token到文件
        with open(path + "config/task_Authorization.txt", 'r') as f:
            Authorization = f.read()
            print('读取成功,Authorization:{}'.format(Authorization))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return Authorization

def get_access_token():
    try:
        # 保存token到文件
        with open(path + "config/access_token.txt", 'r') as f:
            access_token = f.read()
            print('读取成功,access_token:{}'.format(access_token))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return access_token

def get_login_code():
    try:
        # 保存token到文件
        with open(path + "config/login_code.txt", 'r') as f:
            login_code = f.read()
            print('读取成功,access_token:{}'.format(login_code))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return login_code