Fetch params from arguments

This commit is contained in:
Abhorrent_Anger 2023-10-17 13:36:21 +03:00
parent f60db4186b
commit 6c7ce2c699
3 changed files with 37 additions and 10 deletions

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args" : ["phgl3nsiocl0vhso4a84a84uns", "Y0jSaLNFba5DJpsPOmwNpps1TpXtC_cj7yXbhwB3RmU-1697533469-0-1-6faf952d.5ebe3ceb.763f79ca-0.2.1697533469", "asdf666asdf"]
}
]
}

View File

@ -1,6 +1,6 @@
# ScrapTFRaffleBot
Enters Public Raffles.
Enters Public Raffles. Call as `python main.py <SCRAPTF> <CF_CLEARANCE> <USERNAME>`.
## Dependencies:
```

28
main.py
View File

@ -1,5 +1,6 @@
import urllib
import time
import sys
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
@ -8,14 +9,20 @@ import re
from termcolor import colored
SCR_SESSION = 'bG9naW5fcmVkaXJlY3R8czoxNzoiaHR0cHM6Ly9zY3JhcC50Zi8iO2lkfGk6MjI2MTI3Nzt0b2tlbnxzOjY0OiJjNmY1MjkwOWUxMzkyOTg4MmVhYWM1NTJkYjYzOWE4ZjExNDc4ZjhlNDc5NjQ0NTY1ZmRlNDA4ZjJlMmYxZGU4Ijs4M2Y1NmY4NzJiNzAzMzZkZDMyNmM0MDI5NTgxMjBmODM2YWIyZDVkOGNmZTk0NTEyNGQyNDUwOTc3YWQ2NWIwMzczMDVkNTlkOTc5MTQ0YjA3NzhmYTk4ZGNhZmQ4ODI0ZmYyYTkzM2E1MzhiODM1YjI5ZjUzZDJjYWM5NmE2MQ%3D%3D'
USER_ID = '3524755945110770'
SCRAPTF = 'q3guve7k0b5ph8p0tqfunv9qjp'
CF_CLEARANCE = 'Mvzf6zTaelinMYuUoIOFCNBqn.OxJZ0gyWXvgwWKcK0-1690519452-0-0.2.1690519452'
SCR_SESSION = ''
USER_ID = ''
SCRAPTF = ''
CF_CLEARANCE = ''
USERNAME = ''
BASE_URL = 'https://scrap.tf'
RAFFLE_URL = '/raffles/'
ENTER_RAFFLE_URL = '/ajax/viewraffle/EnterRaffle'
def load_arguments():
global SCRAPTF, CF_CLEARANCE, USERNAME
SCRAPTF = sys.argv[1]
CF_CLEARANCE = sys.argv[2]
USERNAME = sys.argv[3]
def fetch_raw(url):
request = urllib.request.Request(url)
@ -30,7 +37,7 @@ def post_raw(url, data):
return page
def add_headers(request):
request.add_header("Cookie", "scr_session=" + SCR_SESSION + '; _pbjs_userid_consent_data=' + USER_ID + '; scraptf=' + SCRAPTF + '; cf_clearance=' + CF_CLEARANCE)
request.add_header("Cookie", 'scraptf=' + SCRAPTF + '; cf_clearance=' + CF_CLEARANCE)
request.add_header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36")
return request
@ -52,7 +59,7 @@ def unentered_raffles():
relative_url = link_element.attrs['href'].replace(RAFFLE_URL, '')
if relative_url:
raffle_list.append(relative_url)
print(colored('There are ' + str(len(raffle_list)) + ' raffles to enter...', 'blue'))
print(colored('There are ' + str(len(raffle_list)) + ' raffles to enter for ' + USERNAME + '...', 'blue'))
check_notifications(parsed_html)
return raffle_list
@ -61,7 +68,7 @@ def get_hash(parsed_html):
if not button:
print(colored('Didn\'t enter ' + parsed_html.find('title').text[:-19] + ' due to a missing enter button!', 'red'))
return False
onclick = button[1].attrs['onclick']
onclick = button[0].attrs['onclick']
quote_text = re.findall(r"'([^']*)'", onclick)
return quote_text[1]
@ -75,11 +82,14 @@ def enter_raffle(raffle):
password = get_hash(parsed_html)
if not password:
return 418
# TODO: Somehow fetch the turnstile key, rendered client-side
turnstile = parsed_html.select('#turnstile-container input')[0].value
csrf = get_csrf(parsed_html)
data = {'raffle' : raffle,
'captcha' : '',
'hash' : password,
'flag' : 'false',
'flag' : 'false',
'turnstile_token' : turnstile,
'csrf' : csrf}
result = post_raw(BASE_URL + ENTER_RAFFLE_URL, data)
if result.status == 200:
@ -92,6 +102,6 @@ def enter_raffles():
for raffle in raffles:
enter_raffle(raffle)
load_arguments()
enter_raffles()