-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
97 lines (77 loc) · 2.99 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
89
90
91
92
93
94
95
96
97
# -*- coding: UTF-8 -*-
import sys
import time
import json
import random
from loguru import logger
from seleniumbase import SB
from selenium.webdriver.common.by import By
logger.remove()
logger.add(sys.stdout, format="[<light-green>{time:HH:mm:ss}</light-green>] <lvl>{message}</lvl>", level="INFO")
def verify_cloudflare(sb): # not used yet
sb.assert_element('img[alt="Logo"]', timeout=4)
sb.sleep(3)
def scroll_to_bottom(sb):
while True:
sb.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3)
if sb.assert_text("That's all, no more!", "div.raffle-pagination-done"):
break
def modify_cookie(sb, cookie, value):
if cookie:
cookie["value"] = value
sb.driver.delete_cookie(cookie["name"])
sb.add_cookie(cookie)
def run():
with SB(uc=True) as sb:
# Wait till page loads
sb.uc_open_with_reconnect("https://scrap.tf/", 3)
# Login to steam
with open("config.json") as jsonFile:
data = json.load(jsonFile)
modified_stf = data["scraptf"]
if modified_stf == "":
logger.error("Config.json is empty!")
sys.exit(1)
original_stf = sb.get_cookie("scraptf")
modify_cookie(sb, original_stf, modified_stf)
sb.refresh()
# Get all raffle links
sb.uc_open_with_reconnect("https://scrap.tf/raffles", 3)
scroll_to_bottom(sb)
links = []
all_raffle_hrefs = sb.find_elements(".raffle-name")
for elem in all_raffle_hrefs:
a = elem.find_element(By.TAG_NAME, "a")
links.append(a.get_attribute("href"))
logger.success("Total raffles: {amount}", amount=len(links))
# Join all raffles
for link in links:
sb.uc_open_with_reconnect(link, 3)
try:
sb.wait_for_element(
'button[data-loading-text="Entering..."]:not([style*="display: none;"])'
)
sb.click(
'button[data-loading-text="Entering..."]:not([style*="display: none;"])'
)
logger.opt(colors=True).info(
"{raffle_title} <green>Joined</green>",
raffle_title=sb.get_title().replace(" - Scrap.TF Raffles", ""),
)
time.sleep(random.randint(1, 3))
except Exception:
try:
sb.wait_for_element(
'button[data-loading-text="Leaving..."]:not([style*="display: none;"])'
)
logger.opt(colors=True).info(
"{raffle_title} <yellow>Already joined</yellow>",
raffle_title=sb.get_title().replace(" - Scrap.TF Raffles", "")
)
except Exception as e:
logger.exception(f"Error: {e}")
continue
logger.success("Joined all raffles. :)")
if __name__ == "__main__":
run()