用Python制作GitHub消息助手
简说Python
共 5347字,需浏览 11分钟
·
2021-02-22 09:00
↑↑↑关注后"星标"简说Python 人人都可以简单入门Python、爬虫、数据分析 简说Python推荐 来源/Python中文社区 作者/邵可佳,目前任职墨迹天气算法专家岗位
https://github.com/siversalih/pyChrome-Web-Automation
https://pychrome.wordpress.com/usage/
browser.open("https://github.com/login")
# name="login"
name_locator = "//*[@name='login']"
el_name = browser.findElementByXPath(name_locator)
browser.sendTextToElement(username, el_name)
# name="password"
pass_locator = "//*[@name='password']"
el_pass = browser.findElementByXPath(pass_locator)
browser.sendTextToElement(password,el_pass)
login_locator = "//*[@name='commit']"
el_login = browser.findElementByXPath(login_locator)
browser.clickElement(el_login)
browser.open("https://github.com/notifications")
# 获取有消息的Repositories列表
locator = "js-notification-sidebar-repositories"
el_repos = browser.findElementByClass(locator)
repos_list = browser.findElementsByTag("li", el_repos)
browser.newTab("https://github.com/" + repos_name + "/pulls?q=")
# 判断最近的 pull request
locator = "//div[@aria-label='Issues']"
el_pulls = browser.findElementByXPath(locator)
pull_list = browser.findElementsByTag("relative-time", el_pulls)
timedelta = 0
if type(pull_list)==list and len(pull_list)>0:
# 2020-11-10T00:55:39Z
# last_pull_time_str = pull_list[0].getAttribute("datetime")
last_pull_time_str = pull_list[0].get_attribute("datetime")
last_time = datetime.strptime(last_pull_time_str, "%Y-%m-%dT%H:%M:%SZ")
timedelta = (datetime.now() - last_time).days
logger.debug(repos_name + " timedelta: " + str(timedelta) + " days")
# 取消不活跃项目的订阅(1年以上没有pull request)
if unsubscribe and timedelta > 366:
el_notify_button =browser.findElementsByTag("notifications-list-subscription-form")
browser.clickElement(el_notify_button)
time.sleep(1)
# data-target="notifications-list-subscription-form.menu"
locator = "//*[@data-target='notifications-list-subscription-form.menu']"
el_notify_menus = browser.findElementByXPath(locator)
# value="ignore"
sub_locator = "//*[@value='ignore']"
el_ignore_button =browser.findElementByXPath(sub_locator, el_notify_menus)
browser.clickElement(el_ignore_button)
logger.debug(repos_name + " cancel subscribed")
el_repos_link = browser.findElementByTag("a", repos)
browser.clickElement(el_repos_link)
# mr-1 js-notifications-mark-all-prompt
time.sleep(1)
el_sel_all =browser.findElementByClass("js-notifications-mark-all-prompt")
browser.clickElement(el_sel_all)
time.sleep(1)
# title="Done"
done_locator = "//*[@title='Done']"
el_done = browser.findElementByXPath(done_locator)
browser.clickElement(el_done)
logger.debug(repos_name + " remove notifiy")
https://gitee.com/knifecms/puppetry/blob/master/github-agent/resp_notify.py
扫码回复:2021
获取最新学习资源
点击公众号卡片关注,一起学Python 学习更多: 整理了我开始分享学习笔记到现在超过250篇优质文章,涵盖数据分析、爬虫、机器学习等方面,别再说不知道该从哪开始,实战哪里找了
看完“点赞”的美德不能丢
评论