-
Notifications
You must be signed in to change notification settings - Fork 2
/
engine.py
67 lines (52 loc) · 1.85 KB
/
engine.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
import os
import time
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from dotenv import load_dotenv
def github_login(username, password, driver):
driver.get("https://github.com/login")
time.sleep(2)
username_input = driver.find_element(By.ID, "login_field")
password_input = driver.find_element(By.ID, "password")
sign_in_button = driver.find_element(By.NAME, "commit")
username_input.send_keys(username)
password_input.send_keys(password)
sign_in_button.click()
time.sleep(5)
def star_repositories(page, delay, driver, url):
driver.get(f"{url}&page={page}")
time.sleep(3)
# Find all star buttons on the page
star_buttons = driver.find_elements(By.XPATH, "//button[contains(@aria-label, 'Star this repository')]")
if not star_buttons:
return False # No star buttons found, likely end of repositories
for button in star_buttons:
try:
button.click()
time.sleep(delay)
except Exception as e:
print(f"Error clicking star button: {e}")
return len(star_buttons)
def star_organization(page, delay, driver, url):
driver.get(f"{url}?page={page}")
time.sleep(3)
success = 0
links = []
elements = driver.find_elements(By.XPATH, '//a[@data-testid="listitem-title-link"]')
for element in elements:
url = element.get_attribute("href")
links.append(url)
print(links)
if not links:
return False
for link in links:
try:
driver.get(link)
star_button = driver.find_elements(By.XPATH, "//button[contains(@aria-label, 'Star this repository')]")[0]
star_button.click()
time.sleep(delay)
success += 1
except Exception as e:
print(f"Error clicking star button: {e}")
return success