-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoclaimer.py
144 lines (87 loc) · 4.37 KB
/
autoclaimer.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from playwright.sync_api import sync_playwright
from time import sleep
from datetime import datetime
import cookie_eater
import json
class Autoclaimer():
def __init__(self):
# imports all the cookies from cookies.json deletes, also undesirable keys from cookie's dicts
self.cookies_ = cookie_eater.cookies_proccessing()
# for counting the cicles of main loop
self.iterator = 1
one_hour = 61000*60 # actually not one hour, but one hour and one minute, for error margin
# starts driver and session context
self.start_driver()
# main worker loop, every 1 hour does the three methods in a row
while True:
for _ in range(2):
# NOTE:
# this loop runs claim management methods twice bc sometimes webkit can't resolve the url by timeout
# it is an already recognised bug of webdrivers that could be fixed by just setting wait_for_timeout()
# with infinite time amount, but it could cause a lot of other issues like using "infinite" ram then
# crashing the OS
exceptionRaised = self.claim() # returns True if exception is raised, else returns False
# if no exception is raised, then do this for loop only once
if not exceptionRaised:
break
# logs on console the time that has been claimed
print(f'[{self.date_now()}] claimed! >{self.iterator}< || waiting next')
self.iterator += 1
try:
self.page.wait_for_timeout(one_hour)
except KeyboardInterrupt:
# if user presses ctrl+C then closes driver
self.close_driver()
raise KeyboardInterrupt()
self.page.reload()
def start_driver(self):
# page and session (context) initiation
self.playwright = sync_playwright().start()
self.browser = self.playwright.webkit.launch(ignore_default_args=["--mute-audio"])
context = self.browser.new_context()
self.page = context.new_page()
# cookie adding management
self.page.goto("https://freebitco.in/")
context.add_cookies(self.cookies_)
# after setting cookies, refreshes the page
self.page.goto("https://freebitco.in/?op=home")
##
def claim(self):
last_log_info = open('log_info.txt', 'r').read()
# tries to roll without captcha
try:
# sends directly the event of button's onclick
play_without_captcha = self.page.dispatch_event(
'div#play_without_captchas_button',
'click'
)
# roll click
roll_button = self.page.locator(
'input[id="free_play_form_button"]'
)
roll_button.click()
# if any exception occurs, write it on log_info.txt (normally timeout exception,
# explained on the note inside main worker loop at Autoclaimer().__init__())
except Exception as e:
open('log_info.txt', 'w').write(
f"{last_log_info}\n{e} not able to detect button || at {self.date_now()}"
)
print(e, f'\n || at [{self.date_now()}]')
return True
else:
#print(roll_button.text_content(), 'clicked!')
open('log_info.txt', 'w').write(
f"{last_log_info}\n claimed || at {self.date_now()}"
)
# breaks for loop of running methods twice if no exception is raised
return False
def close_driver(self):
# closes browser and driver
self.browser.close()
self.playwright.stop()
def date_now(self):
date = str(datetime.now()) # gets only str from datetime.now()
return date[0:19] # returns only 19 digits from date, that matches just year-month-day hour-minute-second (with no ms)
if __name__ == '__main__':
# if code is running by its side, then calls autoclaimer class
Autoclaimer()