assigne user agent from list
This commit is contained in:
parent
0d6b974785
commit
ceb55bec68
3 changed files with 26 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from random import randint
|
from random import randint, randrange
|
||||||
|
|
||||||
import log
|
import log
|
||||||
|
|
||||||
|
@ -10,10 +10,24 @@ class ConfigException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConfigReader(ConfigParser):
|
def value_range(min, max):
|
||||||
def value_range(min, max):
|
|
||||||
return [str(x) for x in [*range(min, max + 1)]]
|
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):
|
||||||
|
|
||||||
|
|
||||||
required_values = {
|
required_values = {
|
||||||
'DEFAULT': {
|
'DEFAULT': {
|
||||||
'enabled': ('true', 'false'),
|
'enabled': ('true', 'false'),
|
||||||
|
@ -35,6 +49,7 @@ class ConfigReader(ConfigParser):
|
||||||
default_values = {
|
default_values = {
|
||||||
'DEFAULT': {
|
'DEFAULT': {
|
||||||
'cookie': '',
|
'cookie': '',
|
||||||
|
'user_agent': f"{choose_user_agent()}",
|
||||||
'enabled': 'true',
|
'enabled': 'true',
|
||||||
'minimum_points': f"{randint(20, 50)}",
|
'minimum_points': f"{randint(20, 50)}",
|
||||||
'max_entries': f"{randint(1000, 2500)}",
|
'max_entries': f"{randint(1000, 2500)}",
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SteamGiftsException(Exception):
|
||||||
|
|
||||||
|
|
||||||
class SteamGifts:
|
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):
|
max_time_left, minimum_game_points, blacklist, notification):
|
||||||
self.contributor_level = None
|
self.contributor_level = None
|
||||||
self.xsrf_token = None
|
self.xsrf_token = None
|
||||||
|
@ -27,6 +27,7 @@ class SteamGifts:
|
||||||
self.cookie = {
|
self.cookie = {
|
||||||
'PHPSESSID': cookie
|
'PHPSESSID': cookie
|
||||||
}
|
}
|
||||||
|
self.user_agent = user_agent
|
||||||
self.gifts_type = gifts_type
|
self.gifts_type = gifts_type
|
||||||
self.pinned = pinned
|
self.pinned = pinned
|
||||||
self.min_points = int(min_points)
|
self.min_points = int(min_points)
|
||||||
|
@ -68,7 +69,7 @@ class SteamGifts:
|
||||||
|
|
||||||
def get_soup_from_page(self, url):
|
def get_soup_from_page(self, url):
|
||||||
headers = {
|
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)
|
self.requests_retry_session().get(url, headers=headers)
|
||||||
r = requests.get(url, cookies=self.cookie)
|
r = requests.get(url, cookies=self.cookie)
|
||||||
|
@ -144,7 +145,7 @@ class SteamGifts:
|
||||||
|
|
||||||
def enter_giveaway(self, giveaway):
|
def enter_giveaway(self, giveaway):
|
||||||
headers = {
|
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}
|
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,
|
entry = requests.post('https://www.steamgifts.com/ajax.php', data=payload, cookies=self.cookie,
|
||||||
|
|
|
@ -34,7 +34,7 @@ def run():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cookie = config['DEFAULT'].get('cookie')
|
cookie = config['DEFAULT'].get('cookie')
|
||||||
|
user_agent = config['DEFAULT'].get('user_agent')
|
||||||
main_page_enabled = config['DEFAULT'].getboolean('enabled')
|
main_page_enabled = config['DEFAULT'].getboolean('enabled')
|
||||||
minimum_points = config['DEFAULT'].getint('minimum_points')
|
minimum_points = config['DEFAULT'].getint('minimum_points')
|
||||||
max_entries = config['DEFAULT'].getint('max_entries')
|
max_entries = config['DEFAULT'].getint('max_entries')
|
||||||
|
@ -42,7 +42,7 @@ def run():
|
||||||
minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
|
minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
|
||||||
blacklist = config['DEFAULT'].get('blacklist_keywords')
|
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)
|
max_time_left, minimum_game_points, blacklist, notification)
|
||||||
|
|
||||||
wishlist_page_enabled = config['WISHLIST'].getboolean('wishlist.enabled')
|
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_entries = config['WISHLIST'].getint('wishlist.max_entries')
|
||||||
wishlist_max_time_left = config['WISHLIST'].getint('wishlist.max_time_left')
|
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)
|
wishlist_max_entries, wishlist_max_time_left, 0, '', notification)
|
||||||
|
|
||||||
if not main_page_enabled and not wishlist_page_enabled:
|
if not main_page_enabled and not wishlist_page_enabled:
|
||||||
|
|
Loading…
Reference in a new issue