用Python制作GitHub消息助手
↑↑↑關(guān)注后"星標(biāo)"簡說Python 人人都可以簡單入門Python、爬蟲、數(shù)據(jù)分析 ?簡說Python推薦? 來源/Python中文社區(qū) 作者/邵可佳,目前任職墨跡天氣算法專家崗位





https://github.com/siversalih/pyChrome-Web-Automationhttps://pychrome.wordpress.com/usage/
browser.open("https://github.com/login")
#?name="login"
name_locator?=?"http://*[@name='login']"
el_name?=?browser.findElementByXPath(name_locator)?
browser.sendTextToElement(username,?el_name)?
#?name="password"
pass_locator?=?"http://*[@name='password']"
el_pass?=?browser.findElementByXPath(pass_locator)?
browser.sendTextToElement(password,el_pass)?
login_locator?=?"http://*[@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?=?"http://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")
#?取消不活躍項(xiàng)目的訂閱(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?=?"http://*[@data-target='notifications-list-subscription-form.menu']"
????el_notify_menus?=?browser.findElementByXPath(locator)?
????#?value="ignore"
????sub_locator?=?"http://*[@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?=?"http://*[@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掃碼回復(fù):2021
獲取最新學(xué)習(xí)資源

點(diǎn)擊公眾號卡片關(guān)注,一起學(xué)Python 學(xué)習(xí)更多: 整理了我開始分享學(xué)習(xí)筆記到現(xiàn)在超過250篇優(yōu)質(zhì)文章,涵蓋數(shù)據(jù)分析、爬蟲、機(jī)器學(xué)習(xí)等方面,別再說不知道該從哪開始,實(shí)戰(zhàn)哪里找了
看完“點(diǎn)贊”的美德不能丟?
評論
圖片
表情
