assigne user agent from list

This commit is contained in:
mcinj 2022-05-13 11:43:59 -04:00
parent 0d6b974785
commit ceb55bec68
3 changed files with 26 additions and 10 deletions

View file

@ -1,5 +1,5 @@
from configparser import ConfigParser
from random import randint
from random import randint, randrange
import log
@ -10,9 +10,23 @@ class ConfigException(Exception):
pass
def value_range(min, max):
return [str(x) for x in [*range(min, max + 1)]]
def choose_user_agent():
user_agents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36'
]
return user_agents[randrange(0, len(user_agents))]
class ConfigReader(ConfigParser):
def value_range(min, max):
return [str(x) for x in [*range(min, max + 1)]]
required_values = {
'DEFAULT': {
@ -35,6 +49,7 @@ class ConfigReader(ConfigParser):
default_values = {
'DEFAULT': {
'cookie': '',
'user_agent': f"{choose_user_agent()}",
'enabled': 'true',
'minimum_points': f"{randint(20, 50)}",
'max_entries': f"{randint(1000, 2500)}",
@ -107,4 +122,4 @@ class ConfigReader(ConfigParser):
if self[section][key] not in values:
raise ConfigException((
'Invalid value for "%s" under section "%s" in ' +
'the config file') % (key, section))
'the config file') % (key, section))

View file

@ -19,7 +19,7 @@ class SteamGiftsException(Exception):
class SteamGifts:
def __init__(self, cookie, gifts_type, pinned, min_points, max_entries,
def __init__(self, cookie, user_agent, gifts_type, pinned, min_points, max_entries,
max_time_left, minimum_game_points, blacklist, notification):
self.contributor_level = None
self.xsrf_token = None
@ -27,6 +27,7 @@ class SteamGifts:
self.cookie = {
'PHPSESSID': cookie
}
self.user_agent = user_agent
self.gifts_type = gifts_type
self.pinned = pinned
self.min_points = int(min_points)
@ -68,7 +69,7 @@ class SteamGifts:
def get_soup_from_page(self, url):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36',
'User-Agent': self.user_agent
}
self.requests_retry_session().get(url, headers=headers)
r = requests.get(url, cookies=self.cookie)
@ -144,7 +145,7 @@ class SteamGifts:
def enter_giveaway(self, giveaway):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36',
'User-Agent': self.user_agent
}
payload = {'xsrf_token': self.xsrf_token, 'do': 'entry_insert', 'code': giveaway.giveaway_game_id}
entry = requests.post('https://www.steamgifts.com/ajax.php', data=payload, cookies=self.cookie,

View file

@ -34,7 +34,7 @@ def run():
try:
cookie = config['DEFAULT'].get('cookie')
user_agent = config['DEFAULT'].get('user_agent')
main_page_enabled = config['DEFAULT'].getboolean('enabled')
minimum_points = config['DEFAULT'].getint('minimum_points')
max_entries = config['DEFAULT'].getint('max_entries')
@ -42,7 +42,7 @@ def run():
minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
blacklist = config['DEFAULT'].get('blacklist_keywords')
all_page = SteamGifts(cookie, 'All', False, minimum_points, max_entries,
all_page = SteamGifts(cookie, user_agent, 'All', False, minimum_points, max_entries,
max_time_left, minimum_game_points, blacklist, notification)
wishlist_page_enabled = config['WISHLIST'].getboolean('wishlist.enabled')
@ -50,7 +50,7 @@ def run():
wishlist_max_entries = config['WISHLIST'].getint('wishlist.max_entries')
wishlist_max_time_left = config['WISHLIST'].getint('wishlist.max_time_left')
wishlist_page = SteamGifts(cookie, 'Wishlist', False, wishlist_minimum_points,
wishlist_page = SteamGifts(cookie, user_agent, 'Wishlist', False, wishlist_minimum_points,
wishlist_max_entries, wishlist_max_time_left, 0, '', notification)
if not main_page_enabled and not wishlist_page_enabled: