m_func.py 9.3 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/'
path = 'E:/mmm_auto/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
#写入抢单任务id
def teardown_hook_get_loot_task_id(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        task_id =jsondata['data']['id']
    try:
        # 保存token到文件
        with open(path + 'config/loot_task_id.txt','w+') as f:
            f.write(task_id)
            print('写入成功,task_id:{}'.format(task_id))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return task_id
#获取抢单任务id
def get_loot_task_id():
    try:
        # 保存token到文件
        with open(path + "config/loot_task_id.txt", 'r') as f:
            task_id = f.read()
            print('读取成功,task_id:{}'.format(task_id))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return task_id
#写入竞标任务id
def teardown_hook_get_bid_task_id(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        task_id =jsondata['data']['id']
    try:
        # 保存token到文件
        with open(path + 'config/bid_task_id.txt','w+') as f:
            f.write(task_id)
            print('写入成功,task_id:{}'.format(task_id))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return task_id
#获取竞标任务id
def get_bid_task_id():
    try:
        # 保存token到文件
        with open(path + "config/bid_task_id.txt", 'r') as f:
            task_id = f.read()
            print('读取成功,task_id:{}'.format(task_id))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return task_id

#写入指派任务id
def teardown_hook_get_appoint_task_id(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        task_id =jsondata['data']['id']
    try:
        # 保存token到文件
        with open(path + 'config/appoint_task_id.txt','w+') as f:
            f.write(task_id)
            print('写入成功,task_id:{}'.format(task_id))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return task_id
#获取指派任务id
def get_appoint_task_id():
    try:
        # 保存token到文件
        with open(path + "config/appoint_task_id.txt", 'r') as f:
            task_id = f.read()
            print('读取成功,task_id:{}'.format(task_id))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return task_id

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
#----------------------------获取公共用户id-------------------------
def teardown_hook_get_uid0(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        uid0 =jsondata['data']['list'][0]['uid']
    try:
        # 保存token到文件
        with open(path + 'config/uid0.txt','w+') as f:
            f.write(uid0)
            print('写入成功,uid0:{}'.format(uid0))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return uid0

def get_uid0():
    try:
        # 保存token到文件
        with open(path + "config/uid0.txt", 'r') as f:
            uid0 = f.read()
            print('读取成功,uid0:{}'.format(uid0))
    except Exception as e:
        print('读取失败', e)
    # Authorization = str(Authorization)
    return uid0
def teardown_hook_get_uid1(response):
    if response.status_code == 200:
        jsondata = json.loads(response.text)
        uid1 =jsondata['data']['list'][1]['uid']
    try:
        # 保存token到文件
        with open(path + 'config/uid1.txt','w+') as f:
            f.write(uid1)
            print('写入成功,uid1:{}'.format(uid1))
            f.close()
    except Exception as e:
        print('写入失败', e)
    return uid1

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

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

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


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

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