Working Scrap.TF public raffle bot

This commit is contained in:
Abhorrent_Anger 2023-07-04 16:10:29 +03:00
parent b8a9d314eb
commit 9c9eb76f86
2 changed files with 92 additions and 1 deletions

View File

@ -1,3 +1,9 @@
# ScrapTFRaffleBot
Enters Public Raffles.
Enters Public Raffles.
## Dependencies:
```
pip install urllib2
pip install termcolor
```

85
main.py Normal file
View File

@ -0,0 +1,85 @@
import urllib
import time
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
import re
from termcolor import colored
SCR_SESSION = 'bG9naW5fcmVkaXJlY3R8czoxNzoiaHR0cHM6Ly9zY3JhcC50Zi8iO2lkfGk6MjI2MTI3Nzt0b2tlbnxzOjY0OiJjNmY1MjkwOWUxMzkyOTg4MmVhYWM1NTJkYjYzOWE4ZjExNDc4ZjhlNDc5NjQ0NTY1ZmRlNDA4ZjJlMmYxZGU4Ijs4M2Y1NmY4NzJiNzAzMzZkZDMyNmM0MDI5NTgxMjBmODM2YWIyZDVkOGNmZTk0NTEyNGQyNDUwOTc3YWQ2NWIwMzczMDVkNTlkOTc5MTQ0YjA3NzhmYTk4ZGNhZmQ4ODI0ZmYyYTkzM2E1MzhiODM1YjI5ZjUzZDJjYWM5NmE2MQ%3D%3D'
BASE_URL = 'https://scrap.tf'
RAFFLE_URL = '/raffles/'
ENTER_RAFFLE_URL = '/ajax/viewraffle/EnterRaffle'
def fetch_raw(url):
request = urllib.request.Request(url)
request.add_header("Cookie", "scr_session=" + SCR_SESSION)
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")
page = urllib.request.urlopen(request).read()
return page
def post_raw(url, data):
request = urllib.request.Request(url, urllib.parse.urlencode(data).encode())
request.add_header("Cookie", "scr_session=" + SCR_SESSION)
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")
page = urllib.request.urlopen(request)
return page
def fetch(url):
html = fetch_raw(url)
return BeautifulSoup(html, 'lxml')
def check_notifications(parsed_html):
notices = parsed_html.select('.user-notices-count')[0].text
if notices != '0':
print(colored('You have ' + notices + ' new notices!', 'red'))
def unentered_raffles():
parsed_html = fetch(BASE_URL + RAFFLE_URL)
raffles = parsed_html.select('#raffles-list .panel-raffle:not(.raffle-entered)')
raffle_list = []
for element in raffles:
link_element = element.find('a')
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'))
check_notifications(parsed_html)
return raffle_list
def get_hash(parsed_html):
button = parsed_html.select('.btn.btn-embossed.btn-info.btn-lg')
onclick = button[1].attrs['onclick']
quote_text = re.findall(r"'([^']*)'", onclick)
return quote_text[1]
def get_csrf(parsed_html):
form = parsed_html.select('#logoutForm')[0]
input_element = form.find('input')
return input_element.attrs['value']
def enter_raffle(raffle):
parsed_html = fetch(BASE_URL + RAFFLE_URL + raffle)
password = get_hash(parsed_html)
csrf = get_csrf(parsed_html)
data = {'raffle' : raffle,
'captcha' : '',
'hash' : password,
'flag' : 'false',
'csrf' : csrf}
result = post_raw(BASE_URL + ENTER_RAFFLE_URL, data)
if result.status == 200:
print(colored('Succesfully entered ' + parsed_html.find('title').text + ' (' + raffle + ')!', 'green'))
time.sleep(5)
return result
def enter_raffles():
raffles = unentered_raffles()
for raffle in raffles:
enter_raffle(raffle)
enter_raffles()