写了个脚本自己换行等等


1/3/2019 日记 所有文章

2019-01-02 17:11:18
天气:阵雨转多云
温度:17℃-23.8℃-24℃
风力:北风小于3级
湿度:60%

# 一个python小脚本

行了代码在这被pyhook坑了

#-*-coding:utf-8-*-
#SettingCode here
__author__ = "a_little_rubbish"
__date__ = "1/1/2019 11:39 PM"

#import your model here
import pyautogui
import pyHook
import pythoncom
import datetime
import pyautogui
import pyperclip
import json,requests

#your class&function here
count=0
def onKeyboardEvent(event):
    # 监听键盘事件
    global count
    x={'city': '曲阜', 'cityid': '101120710', 'temp1': '-℃', 'temp2': '-℃', 'weather': '未知', 'img1': 'n3.gif',
     'img2': 'd1.gif', 'ptime': '18:00'}
    y={'city': '曲阜', 'cityid': '101120710', 'temp': '-', 'WD': '-', 'WS': '-', 'SD': '-', 'AP': '1000.3hPa',
     'njd': '暂无实况', 'WSE': '<3', 'time': '18:00', 'sm': '1.6', 'isRadar': '0', 'Radar': ''}

    if event.Key=="Return":
        pyautogui.press('shift')
        pyautogui.typewrite('<br/>')
        pyautogui.press('shift')


    if event.Key=="F4":
        wea1='---\ntitle: '
        pyautogui.press('shift')
        pyperclip.copy(wea1)  # 先复制
        pyautogui.hotkey('ctrl', 'v')  # 再粘贴
        pyautogui.press('shift')

    if event.Key == "F7":
        wea2 = '\ndate: {0}\ncategories: backEnd\ntags: \n- \n- \n- \n---\n\n:::tip\n\n:::\n<!-- more -->\n## '.format(str(datetime.datetime.now())[:-7])
        pyautogui.press('shift')
        pyperclip.copy(wea2)  # 先复制
        pyautogui.hotkey('ctrl', 'v')  # 再粘贴
        pyautogui.press('shift')

    if event.Key == "F8":
        resx = requests.get('http://www.weather.com.cn/data/cityinfo/101120710.html')
        x = json.loads(resx.content.decode(encoding="utf-8"))["weatherinfo"]
        resy = requests.get('http://www.weather.com.cn/data/sk/101120710.html')
        y = json.loads(resy.content.decode(encoding="utf-8"))["weatherinfo"]
        print(x,"\n",y)
        wea1 = '\ndate: {0}\ncategories: Other\nsidebar: false\n---\n{1}<br/>\n天气:{2}<br/>\n温度:{3}<br/>\n风力:{4}<br/>\n湿度:{5}<br/>\n<!-- more -->\n# '.format(str(datetime.datetime.now())[:-7], str(datetime.datetime.now())[:-7], x['weather'], x['temp1']+'-'+y['temp']+'℃-'+x['temp2'], y['WD']+y['WS'],y["SD"])
        pyautogui.press('shift')
        pyperclip.copy(wea1)  # 先复制
        pyautogui.hotkey('ctrl', 'v')  # 再粘贴
        pyautogui.press('shift')
    return True


def main():
    # 创建一个“钩子”管理对象
    hm = pyHook.HookManager()

    # 监听所有键盘事件
    hm.KeyDown = onKeyboardEvent
    # 设置键盘“钩子”
    hm.HookKeyboard()


    # 进入循环,如不手动关闭,程序将一直处于监听状态
    pythoncom.PumpMessages()


if __name__ == "__main__":
    while True:
        try:
            main()
        except TypeError:
            print("出错一次")
            continue
Last Updated: 11/8/2019, 3:50:25 PM