windows gitlab 代码更新提示(弹窗)通知
2019-08-22 本文已影响0人
焚_44b3
有开发者提交代码后,能随时监测到,并且通过windows弹窗来通知你合并代码。
刚学python,实属不易,直接代码
import time
import requests
import re
import os
# 这个模块必须要,用来调用windows弹窗通知
from win10toast import ToastNotifier
import time,datetime
os.environ['TZ'] = 'Asia/Shanghai'
auto_mark = None
def get_commit_info():
# 必须配置
session_id = "您的sessionid,登录gitlab后,在浏览器中找到。"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
"Cookie": "sidebar_collapsed=%s; _gitlab_session=%s" % ("false", session_id),
}
# 监听git地址
url = "项目在gitlab中的地址"
resp = requests.get(url, headers=headers)
resp = resp.content.decode('utf-8')
# 获取最新更改信息
latest_commit = {}
latest_commit['info'] = re.findall(r'<a class="commit-row-message item-title".*?>(.*?)</a>', resp, re.S | re.M)[0]
email,author = re.findall(r'<a class="commit-author-link".*?href="mailto:(.*?)".*?>(.*?)</a>', resp, re.S | re.M)[0]
latest_commit['email'] = email
latest_commit['author'] = author
datetimes = re.findall(r'<time class="js-timeago".*?datetime="(.*?)".*?>', resp, re.S | re.M)[0]
latest_commit['datetime'] = datetimes
return latest_commit
# 调用windos弹窗
def prompt_windows(data):
toaster = ToastNotifier()
info = data['info'] + data['email'] + data['datetime']
print("更新信息:",info)
toaster.show_toast(u'git 代码合并提示!',u''+info)
def main():
global auto_mark
while True:
temp_commit_info = get_commit_info()
temp_auto_mark = temp_commit_info['datetime']
# print(temp_auto_mark,auto_mark)
if (temp_auto_mark != auto_mark):
print("发现了更新...")
prompt_windows(temp_commit_info)
auto_mark = temp_auto_mark
time.sleep(30)
if __name__ == "__main__":
print("git更新监测已经启动...")
main()