-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
88 lines (67 loc) · 2.98 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
import time
# Set the URL of the issue page you want to monitor
url = 'https://github.com/lone-wolf45/Webpage-Maker/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc'
# Set the path of your Chrome driver executable
path='C:\\Users\vedant\OneDrive\Desktop'
# Set the labels you want to monitor
# labels = ["up-for-grabs", "good first issue"]
# Set the path of the file where you want to store the issue information
file_path = 'C:\\Users\\vedant\OneDrive\Desktop\issues.txt'
# Define a function to write the issue information to the file
def write_to_file(issue_info):
with open(file_path, 'a') as f:
f.write(issue_info + '\n\n')
# Define a function to claim the issue by adding a comment
def claim_issue(driver):
comment_box = wait.until(EC.element_to_be_clickable((By.ID, "new_comment_field")))
comment_box.send_keys("Claiming this issue", Keys.CONTROL, Keys.RETURN)
# Define a function to check if that issue is already been visited
def search_issue(issue_link):
with open(file_path, 'r') as file:
# read all content of a file
content = file.read()
# check if string present in a file
if issue_link in content:
return False
else:
return True
# Start the browser and open the issue page
driver = webdriver.Chrome(path)
driver.get(url)
# Set up the wait object
wait = WebDriverWait(driver, 20)
while True:
# Find all the issues with the required labels
issues_label_xpath = "//a[contains(@class,'IssueLabel')]"
issues_label = wait.until(EC.presence_of_all_elements_located((By.XPATH, issues_label_xpath)))
for issue_label in issues_label:
# Check if the issue has the required label
label = issue_label.text
# if label in labels:
if label=="good first issue":
# Get the URL of the issue and open it
issue_parent_element = issue_label.find_element(By.XPATH, "..")
issue_grandparent_element = issue_parent_element.find_element(By.XPATH, "..")
issue_link_element = issue_grandparent_element.find_element(By.CLASS_NAME, "Link--primary")
issue_link = issue_link_element.get_attribute('href')
if(search_issue(issue_link)):
driver.get(issue_link)
# Write the issue information to the file
issue_title = driver.find_element(By.XPATH, "//bdi[contains(@class, 'js-issue-title')]")
issue_info = f"{issue_title.text}\n{issue_link}\n\n"
write_to_file(issue_info)
# Claim the issue by adding a comment
claim_issue(driver)
# break
else:
break
# break
driver.get(url)
time.sleep(600)
# driver.refresh()
driver.quit()