add contributor level

- if you are not hiding giveaways above your level then this could be a problem so this checks you can in fact enter a game
This commit is contained in:
mcinj 2022-05-06 10:56:57 -04:00
parent 985be444d6
commit 405dd11a9b
3 changed files with 21 additions and 0 deletions

View file

@ -23,6 +23,7 @@ class SteamGiftsException(Exception):
class SteamGifts: class SteamGifts:
def __init__(self, cookie, gifts_type, pinned, min_points, max_entries, def __init__(self, cookie, 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.xsrf_token = None self.xsrf_token = None
self.points = None self.points = None
self.cookie = { self.cookie = {
@ -79,6 +80,7 @@ class SteamGifts:
try: try:
self.xsrf_token = soup.find('input', {'name': 'xsrf_token'})['value'] self.xsrf_token = soup.find('input', {'name': 'xsrf_token'})['value']
self.points = int(soup.find('span', {'class': 'nav__points'}).text) # storage points self.points = int(soup.find('span', {'class': 'nav__points'}).text) # storage points
self.contributor_level = int(float(soup.select_one('nav a>span[title]')['title']))
except TypeError: except TypeError:
logger.error("⛔ Cookie is not valid.") logger.error("⛔ Cookie is not valid.")
raise SteamGiftsException("Cookie is not valid.") raise SteamGiftsException("Cookie is not valid.")
@ -98,6 +100,11 @@ class SteamGifts:
txt = f"Game {giveaway.game_name} contains the blacklisted keyword {keyword}" txt = f"Game {giveaway.game_name} contains the blacklisted keyword {keyword}"
logger.debug(txt) logger.debug(txt)
return False return False
if giveaway.contributor_level is None or self.contributor_level < giveaway.contributor_level:
txt = f"Game {giveaway.game_name} requires at least level {giveaway.contributor_level} contributor level " \
f"to enter. Your level: {self.contributor_level}"
logger.debug(txt)
return False
if self.points - int(giveaway.cost) < 0: if self.points - int(giveaway.cost) < 0:
txt = f"⛔ Not enough points to enter: {giveaway.game_name}" txt = f"⛔ Not enough points to enter: {giveaway.game_name}"
logger.debug(txt) logger.debug(txt)
@ -144,6 +151,7 @@ class SteamGifts:
giveaway_ended_at=TableGiveaway.unix_timestamp_to_utc_datetime(giveaway.time_remaining_timestamp), giveaway_ended_at=TableGiveaway.unix_timestamp_to_utc_datetime(giveaway.time_remaining_timestamp),
cost=giveaway.cost, cost=giveaway.cost,
copies=giveaway.copies, copies=giveaway.copies,
contributor_level=giveaway.contributor_level,
entered=entered, entered=entered,
game_entries=giveaway.game_entries) game_entries=giveaway.game_entries)
with Session(engine) as session: with Session(engine) as session:

View file

@ -19,6 +19,7 @@ class Giveaway:
self.game_entries = None self.game_entries = None
self.user = None self.user = None
self.copies = None self.copies = None
self.contributor_level = None
self.time_created_timestamp = None self.time_created_timestamp = None
self.time_remaining_string = None self.time_remaining_string = None
self.time_remaining_in_minutes = None self.time_remaining_in_minutes = None
@ -36,6 +37,8 @@ class Giveaway:
self.pinned = pin_class is not None and len(pin_class) > 0 and pin_class[0].find('pinned') != -1 self.pinned = pin_class is not None and len(pin_class) > 0 and pin_class[0].find('pinned') != -1
self.cost, self.copies = self.determine_cost_and_copies(self.soup_item, self.game_name, self.giveaway_game_id) self.cost, self.copies = self.determine_cost_and_copies(self.soup_item, self.game_name, self.giveaway_game_id)
self.game_entries = int(soup_item.select('div.giveaway__links span')[0].text.split(' ')[0].replace(',', '')) self.game_entries = int(soup_item.select('div.giveaway__links span')[0].text.split(' ')[0].replace(',', ''))
contributor_level = soup_item.select_one('div[title="Contributor Level"]')
self.contributor_level = self.determine_contributor_level(contributor_level)
self.user = soup_item.select_one('a.giveaway__username').text self.user = soup_item.select_one('a.giveaway__username').text
times = soup_item.select('div span[data-timestamp]') times = soup_item.select('div span[data-timestamp]')
self.time_remaining_timestamp = int(times[0]['data-timestamp']) self.time_remaining_timestamp = int(times[0]['data-timestamp'])
@ -45,6 +48,15 @@ class Giveaway:
self.time_created_string = times[1].text self.time_created_string = times[1].text
self.time_created_in_minutes = self.determine_time_in_minutes(times[1]['data-timestamp']) self.time_created_in_minutes = self.determine_time_in_minutes(times[1]['data-timestamp'])
def determine_contributor_level(self, contributor_level):
if contributor_level is None:
return 0
match = re.search('^Level (?P<level>[0-9]+)\\+$', contributor_level.text, re.IGNORECASE)
if match:
return int(match.group('level'))
else:
return None
def get_steam_app_id(self, steam_url): def get_steam_app_id(self, steam_url):
match = re.search('^.+/[a-z0-9]+/(?P<steam_app_id>[0-9]+)/$', steam_url, re.IGNORECASE) match = re.search('^.+/[a-z0-9]+/(?P<steam_app_id>[0-9]+)/$', steam_url, re.IGNORECASE)
if match: if match:

View file

@ -35,6 +35,7 @@ class TableGiveaway(Base):
giveaway_ended_at = Column(DateTime(timezone=True), nullable=False) giveaway_ended_at = Column(DateTime(timezone=True), nullable=False)
cost = Column(Integer(), nullable=False) cost = Column(Integer(), nullable=False)
copies = Column(Integer(), nullable=False) copies = Column(Integer(), nullable=False)
contributor_level = Column(Integer(), nullable=False)
entered = Column(Boolean(), nullable=False) entered = Column(Boolean(), nullable=False)
game_entries = Column(Integer(), nullable=False) game_entries = Column(Integer(), nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now()) created_at = Column(DateTime(timezone=True), server_default=func.now())