脚本
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
# 基础函数配置
|
||||
import pandas as pd
|
||||
import requests
|
||||
from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
import json
|
||||
import numpy as np
|
||||
import time
|
||||
import datetime
|
||||
ROOT = Path('.').absolute() # 当前工作目录
|
||||
|
||||
def generateToken() -> str:
|
||||
""" 生成 token """
|
||||
|
||||
token_api = 'https://api.dingtalk.com/v1.0/oauth2/accessToken'
|
||||
|
||||
# 该信息在钉钉开放应用中
|
||||
data = {
|
||||
"appKey": "ding5kqocon5s9oph5uq",
|
||||
"appSecret": 'HL1jgsIIfLAC0eTH0A1m4mwxUDqbgsiPeCCGGE3ocM6qJBTIW7Ivt9drxF_Z4Kb_'
|
||||
}
|
||||
|
||||
res = requests.post(token_api, json=data)
|
||||
token = res.json()['accessToken']
|
||||
|
||||
return token
|
||||
def read_instances(token, formUuid, page, n):
|
||||
""" 函数功能:读取普通表单的所有数据 """
|
||||
|
||||
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": token
|
||||
}
|
||||
|
||||
formData = {
|
||||
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
||||
"userId" : "yida_pub_account",
|
||||
"language" : "zh_CN",
|
||||
"formUuid" : formUuid,
|
||||
"currentPage" : page,
|
||||
"pageSize" : n
|
||||
}
|
||||
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
return res.json()
|
||||
def transcation(FORMID,data_new,userId):
|
||||
""" 函数功能:更新表单内容 """
|
||||
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": TOKEN
|
||||
}
|
||||
|
||||
payload = {
|
||||
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
||||
"userId" : userId, # "yida_pub_account", # 曹伟 id
|
||||
"language" : "zh_CN",
|
||||
"useLatestVersion" : "false",
|
||||
"formInstanceId" : FORMID,
|
||||
"updateFormDataJson" : json.dumps(data_new, cls=NpEncoder),
|
||||
}
|
||||
|
||||
res = requests.put(api, headers=headers, json=payload)
|
||||
|
||||
return res.json()
|
||||
def read_instances_new(token, formUuid, page, n,modifiedFromTimeGMT,modifiedToTimeGMT):
|
||||
""" 函数功能:读取流程表单的所有数据 """
|
||||
|
||||
api = f'https://api.dingtalk.com//v1.0/yida/processes/instances?pageNumber={page}&pageSize={n}'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": token
|
||||
}
|
||||
|
||||
formData = {
|
||||
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
||||
"userId" : "yida_pub_account",
|
||||
"language" : "zh_CN",
|
||||
"formUuid" : formUuid,
|
||||
"modifiedFromTimeGMT":modifiedFromTimeGMT,
|
||||
"modifiedToTimeGMT":modifiedToTimeGMT
|
||||
}
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
return res.json()
|
||||
def update_instances(TOKEN, processInstanceId,code,name):
|
||||
""" 更新表单实例 """
|
||||
|
||||
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": TOKEN
|
||||
}
|
||||
|
||||
data_new= {
|
||||
code : name
|
||||
}
|
||||
|
||||
payload = {
|
||||
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
||||
"userId" : "yida_pub_account",
|
||||
"language" : "zh_CN",
|
||||
"formInstanceId" : processInstanceId,
|
||||
"useLatestVersion" : 'false',
|
||||
"updateFormDataJson" : json.dumps(data_new, cls=NpEncoder) #json.dumps(data_new, cls=NpEncoder)
|
||||
}
|
||||
|
||||
res = requests.put(api, headers=headers,json =payload)
|
||||
|
||||
return res.json()
|
||||
def instances_id(TOKEN,FORMID,id):
|
||||
""" 函数功能:查询表单实例 """
|
||||
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/{id}?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=2268275546837446&language=zh_CN'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": TOKEN
|
||||
}
|
||||
|
||||
res = requests.get(api, headers=headers)
|
||||
|
||||
return res.json()
|
||||
def operator(token, formUuid,processInstanceId):
|
||||
""" 函数功能:读取流程表单的所有数据 """
|
||||
|
||||
api = f'https://api.dingtalk.com//v1.0/yida/forms/operationsLogs/query'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-acs-dingtalk-access-token": token
|
||||
}
|
||||
|
||||
formData = {
|
||||
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
||||
"userId" : "yida_pub_account",
|
||||
"formUuid" : formUuid,
|
||||
"formInstanceIdList":json.dumps(processInstanceId, cls=NpEncoder)
|
||||
}
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
return res.json()
|
||||
class NpEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, np.integer):
|
||||
return int(obj)
|
||||
elif isinstance(obj, np.floating):
|
||||
return float(obj)
|
||||
elif isinstance(obj, np.ndarray):
|
||||
return obj.tolist()
|
||||
else:
|
||||
return super(NpEncoder, self).default(obj)
|
||||
TOKEN = generateToken()
|
||||
'''读取员工对应关系:宜搭员工-ID对应表 '''
|
||||
FORMID = "FORM-EA866E715PF9YA7ECCAGSABX91Q72PVA3WRFL6" # 宜搭员工-ID对应表 FORM-EA866E715PF9YA7ECCAGSABX91Q72PVA3WRFL6
|
||||
form_data = read_instances(token=TOKEN, formUuid=FORMID, page=1, n=100)
|
||||
PAGES = form_data.get('totalCount')//100 + 1
|
||||
ALL_DATA_staff = {}
|
||||
""" 获取全量数据 """
|
||||
for i in range(1, PAGES+1):
|
||||
# form_data = read_processes_instances(token=TOKEN, formUuid=FORMID, createFromTimeGMT=CREATE_FROM, createToTimeGMT=CREATE_TO, page=i, n=100, searchField={'textField_l7if5ff9': '否'})
|
||||
form_data = read_instances(token=TOKEN, formUuid=FORMID, page=i, n=100)
|
||||
for data in form_data.get('data'):
|
||||
ALL_DATA_staff[data['formData']['textField_lfrw3u58']]=data['formData']['textField_lfrw3u59']
|
||||
|
||||
import datetime
|
||||
now = datetime.datetime.now()
|
||||
ten_minutes_ago = now - datetime.timedelta(minutes=15)
|
||||
modifiedToTimeGMT = now.strftime("%Y-%m-%d %H:%M:%S") # %H:%M:%S
|
||||
modifiedFromTimeGMT = ten_minutes_ago.strftime("%Y-%m-%d %H:%M:%S") # %H:%M:%S
|
||||
|
||||
# 读取节点化回访流程表单
|
||||
FORMID = "FORM-L89662816B04LXH893M4K50Q7MIZ1SVQI08ALU2" # 新签节点化服务待办
|
||||
# 读取流程表单数据
|
||||
form_data = read_instances_new(token=TOKEN, formUuid=FORMID, page=1, n=100,modifiedFromTimeGMT=modifiedFromTimeGMT,modifiedToTimeGMT=modifiedToTimeGMT)
|
||||
PAGES = form_data.get('totalCount')//100 + 1
|
||||
ALL_DATA_node = []
|
||||
""" 获取全量数据 """
|
||||
for i in range(1, PAGES+1):
|
||||
form_data = read_instances_new(token=TOKEN, formUuid=FORMID, page=i, n=100,modifiedFromTimeGMT=modifiedFromTimeGMT,modifiedToTimeGMT=modifiedToTimeGMT)
|
||||
for data in form_data.get('data'):
|
||||
try:
|
||||
string = data['data']['checkboxField_liviovx6']
|
||||
if "问题" in string or "商机" in string:
|
||||
ALL_DATA_node.append(data['processInstanceId'])
|
||||
formData = {'checkboxField_liviovx6':string}
|
||||
res_new = transcation(data['processInstanceId'],formData,data['data']['employeeField_la80kj0k_id'][0])
|
||||
print(res_new)
|
||||
except:
|
||||
pass
|
||||
print(f'读取到 新签节点化服务待办表单中 {len(ALL_DATA_node)} 条数据!')
|
||||
|
||||
# 读取[流程]续约服务流程
|
||||
FORMID = "FORM-PE866MD1MJMU0WGLYRFLYEN5YN9L1I55Z7ZUK22" # [流程]续约服务流程
|
||||
# 读取流程表单数据
|
||||
form_data = read_instances_new(token=TOKEN, formUuid=FORMID, page=1, n=100,modifiedFromTimeGMT=modifiedFromTimeGMT,modifiedToTimeGMT=modifiedToTimeGMT)
|
||||
PAGES = form_data.get('totalCount')//100 + 1
|
||||
ALL_DATA_node = []
|
||||
""" 获取全量数据 """
|
||||
for i in range(1, PAGES+1):
|
||||
form_data = read_instances_new(token=TOKEN, formUuid=FORMID, page=i, n=100,modifiedFromTimeGMT=modifiedFromTimeGMT,modifiedToTimeGMT=modifiedToTimeGMT)
|
||||
for data in form_data.get('data'):
|
||||
try:
|
||||
string = data['data']['radioField_r3yeqvd']
|
||||
if "产品问题" in string or "服务问题" in string or "价格问题" in string or "门店问题" in string:
|
||||
print(string)
|
||||
ALL_DATA_node.append(data['processInstanceId'])
|
||||
formData = {'radioField_r3yeqvd':string}
|
||||
operator_new = operator(TOKEN, FORMID,[data['processInstanceId']])
|
||||
res_new = transcation(data['processInstanceId'],formData,ALL_DATA_staff[operator_new['operationLogMap'][data['processInstanceId']][0]['operator']['displayName']])
|
||||
print(res_new)
|
||||
except:
|
||||
pass
|
||||
print(f'读取到 [流程]续约服务流程表单中 {len(ALL_DATA_node)} 条数据!')
|
||||
Reference in New Issue
Block a user