python 自动刷新tableau看板数据

tableau看板数据刷新三步骤
1.提取
2.prep 处理
3.刷新看板

为了实现自动化,使用了python中的pyautogui包,加上windows的定时执行任务,实现自动刷新

import pyautogui
#import pyperclip
import os
import time
import numpy as np
import cv2
import warnings
warnings.filterwarnings('ignore')

def image_difference(image_name,im1):
    path = r"C:\Users\ABC\Desktop\picture"+ '\\' +image_name
    #print(path)
    image1 = cv2.imread(path)
    path1 = r"C:\Users\ABC\Desktop\picture"+ '\\' +im1
    image2 = cv2.imread(path1)
    difference = cv2.subtract(image1, image2)
    result = not np.any(difference) #if difference is all zeros it will return False
    return result



Path = r'D:\tg\kanban\数据提取(new).twb'
os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同
time.sleep(15)#设置打印的时间间隔
pyautogui.hotkey('win', 'up')
#pyautogui.moveTo(x=659, y=750) # 绝对坐标
#pyautogui.click(x=659,y=750,button='left')
#pyautogui.mouseDown()   #按下鼠标按键(左键)
# 点击数据
time.sleep(3)
pyautogui.click(x=74,y=34,button='left')
# 刷新数据
time.sleep(3)
pyautogui.click(x=122,y=122,button='left')
# 刷新
time.sleep(3)
pyautogui.click(x=979,y=654,button='left')


os.chdir(r'C:\Users\ABC\Desktop\picture')

# 输入密码
while True:
    time.sleep(1.5)
    img2 = pyautogui.screenshot(region=[789,411, 37, 25])  # 分别代表:左上角坐标,宽高
    img2.save(r'11.png')
    if image_difference('11.png','12.png') is True:
        print("两张图片一样")
        #time.sleep(2)
        time.sleep(1)
        pyautogui.typewrite('密码',interval=0.1)
        pyautogui.keyDown('enter')
        continue
    else:
        print("两张图片不一样")
        break



# 等待刷新完
while True:
    pyautogui.click(x=959,y=377,button='left')
    time.sleep(10)
    img2 = pyautogui.screenshot(region=[1028,643, 82, 28])  # 分别代表:左上角坐标,宽高
    img2.save(r'133.png')
    if image_difference('133.png','13.png') is True:
        print("两张图片一样")
        #time.sleep(2)
        # 关闭
        pyautogui.click(x=1062,y=656,button='left')
        time.sleep(2)
        # 保存
        pyautogui.click(x=132,y=66,button='left')
        break
    else:
        print("两张图片不一样")
        print("再等5分钟")
        continue

time.sleep(2)
pyautogui.hotkey('win', 'down')

# 加载新数据
time.sleep(2)#设置打印的时间间隔
Path = r'D:\tg\kanban\新建文件夹 (3)'
os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同

time.sleep(2)
# 按下键盘组合键
pyautogui.hotkey('ctrl', 'a')
time.sleep(1)
pyautogui.hotkey('ctrl', 'c')

time.sleep(1)
# time.sleep(1)#设置打印的时间间隔
Path = r'D:\tg\kanban\数据提取'
os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同
time.sleep(2)
pyautogui.hotkey('ctrl', 'v')
time.sleep(2)
pyautogui.keyDown('enter') #按键按下shift



time.sleep(10)
Path = r'D:\tg\kanban\数据预处理0330.tfl'
os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同
time.sleep(120)
pyautogui.click(x=1172,y=212,button='left')
time.sleep(2)
pyautogui.click(x=1172,y=433,button='left')
time.sleep(2)
# 点击流程
pyautogui.click(x=372,y=178,button='left')
time.sleep(2)
# 运行
pyautogui.click(x=410,y=199,button='left')
time.sleep(2)
# 替换
pyautogui.click(x=1244,y=659,button='left')


while True:
    time.sleep(10)
    img2 = pyautogui.screenshot(region=[944,599, 32, 23])  # 分别代表:左上角坐标,宽高
    img2.save(r'16.png')
    if image_difference('16.png','15.png') is True:
        print("两张图片一样")
        #time.sleep(2)
        # 关闭
        pyautogui.click(x=959,y=611,button='left')
        time.sleep(2)
        # 保存
        pyautogui.click(x=1612,y=151,button='left')
        break
    else:
        print("两张图片不一样")
        print("再等1分钟")
        continue


time.sleep(2)
Path = r'D:\tg\kanban\kanban.twbx'
os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同
time.sleep(30)
# 点击关闭
pyautogui.click(x=1348,y=120,button='left')
pyautogui.hotkey('win', 'up')
time.sleep(5)
# 点击窗口
pyautogui.click(x=594,y=33,button='left')
time.sleep(2)
# 点击看发生
pyautogui.click(x=692,y=305,button='left')
time.sleep(20)
# 点击数据
pyautogui.click(x=73,y=34,button='left')
time.sleep(2)
# 点击刷新数据
pyautogui.click(x=126,y=121,button='left')
time.sleep(2)
# 点击刷新
pyautogui.click(x=986,y=657,button='left')
time.sleep(2)
pyautogui.typewrite('密码',interval=0.1)
pyautogui.keyDown('enter')

while True:
    time.sleep(15)
    pyautogui.click(x=874,y=651,button='left')
    img2 = pyautogui.screenshot(region=[1029,641, 82, 29])  # 分别代表:左上角坐标,宽高
    img2.save(r'18.png')
    if image_difference('18.png','19.png') is True:
        print("两张图片一样")
        #time.sleep(2)
        # 关闭
        pyautogui.click(x=1068,y=656,button='left')
        break
    else:
        print("两张图片不一样")
        print("再等2秒钟")
        
        continue
    
    
time.sleep(2)
print('点击发布按钮')
pyautogui.click(x=879,y=64,button='left')

time.sleep(5)
# 点击确定
pyautogui.click(x=1052,y=489,button='left')


time.sleep(20)
print('点击确定')
pyautogui.click(x=1113,y=847,button='left')

time.sleep(6)
print('点击发布')
pyautogui.click(x=1003,y=523,button='left')

print("完成")

你可能感兴趣的:(#,Python自动化办公,python,tableau)