python微信自動傳送資訊指令碼

2021-10-04 05:29:26 字數 3354 閱讀 5044

需要用的的python模組:

pywin32 實現模擬按鍵盤傳送,及定位位置

apscheduler 實現定時傳送

步驟:略

步驟:略

:# 以下為「ctrl+v」組合鍵,回車傳送,(方法一)

win32api.keybd_event(17,

0,0,

0)# 有效,按下ctrl

time.sleep(1)

# 需要延時

win32gui.sendmessage(win, win32con.wm_keydown,86,

0)# v win32api.keybd_event(17,

0, win32con.keyeventf_keyup,0)

# 放開ctrl

time.sleep(1)

# 緩衝時間

win32gui.sendmessage(win, win32con.wm_keydown, win32con.vk_return,0)

# 回車傳送

return

deftxt_ctrl_v

(txt_str)

:# 定義文字資訊,將資訊快取入剪貼簿

clipboard.openclipboard(

) clipboard.emptyclipboard(

) clipboard.setclipboarddata(win32con.cf_unicodetext, txt_str)

clipboard.closeclipboard(

)return

# def day_english():

# # 獲取金山詞霸每日一句

# url = ''

# r = requests.get(url)

# content = r.json()['content']

# note = r.json()['note']

# print(content + note)

# return content + note

defget_window

(classname, titlename)

: title_name = classname # 單獨開啟,好友名稱

win = win32gui.findwindow(classname, titlename)

# 窗體前端顯示

# win32gui.setforegroundwindow(win)

# 使窗體最大化

win32gui.showwindow(win, win32con.sw_maximize)

win = win32gui.findwindow(classname, titlename)

print

("找到控制代碼:%x"

% win)

if win !=0:

left, top, right, bottom = win32gui.getwindowrect(win)

print

(left, top, right, bottom)

# 最小化為負數

win32gui.setforegroundwindow(win)

# 獲取控制

time.sleep(

0.5)

else

:print

('請注意:找不到【%s】這個人(或群),請啟用視窗!'

% title_name)

return win

#######################傳送過程***************==

defsendtasklog()

:# win = get_window('chatwnd', '檔案傳輸助手')

win = get_window(

'chatwnd'

,'產品4.5協作'

)# 讀取文字

file

=open

(r'f:\tasklog.txt'

, mode=

'r', encoding=

'utf-8'

)str

=file

.read(

)print

(str

) txt_ctrl_v(

str)

send_m(win)

scheduler = blockingscheduler(

)# scheduler.add_job(sendtasklog, 'interval', seconds=3)

# scheduler.add_job(sendtasklog, 'cron',day_of_week='mon-fri', hour=7,minute=31,second='10',misfire_grace_time=30)

scheduler.add_job(sendtasklog,

'cron'

, day_of_week=

'mon-fri'

, hour=

6, minute=

55, second=

'10'

, misfire_grace_time=30)

try:

scheduler.start(

)except

(keyboardinterrupt, systemexit)

:pass

其中,定位視窗:

win = get_window('chatwnd', '產品4.5協作')

其中,視窗控制代碼定位視窗chatwnd用了findwindow

參考鏈結

1 微信好友定時傳送資訊

題目要求每天早上7點和每天晚上10點給自己的好朋友或者父母傳送一條資訊,由於本程式需要電腦一直執行,改了一下時間,17 06和17 09發訊息。from apscheduler.schedulers.blocking import blockingscheduler 匯入python庫 import...

python企業微信推送資訊

在我的企業中獲取企業的id corpid wwfe6edfd511b002e2 應用管理中,推送訊息的應用。並獲取應用的agentid和secret agentid 1000003 secret 5tbu2fubwcfbgeeaqes8mgm0zzac5fjdagk20kfeul0 獲取access...

python之微信自動傳送訊息

如下 from future import unicode literals from threading import timer from wxpy import import requests bot bot defsend news try my friend bot.friends sea...