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:
parent
985be444d6
commit
405dd11a9b
3 changed files with 21 additions and 0 deletions
|
@ -23,6 +23,7 @@ class SteamGiftsException(Exception):
|
|||
class SteamGifts:
|
||||
def __init__(self, cookie, gifts_type, pinned, min_points, max_entries,
|
||||
max_time_left, minimum_game_points, blacklist, notification):
|
||||
self.contributor_level = None
|
||||
self.xsrf_token = None
|
||||
self.points = None
|
||||
self.cookie = {
|
||||
|
@ -79,6 +80,7 @@ class SteamGifts:
|
|||
try:
|
||||
self.xsrf_token = soup.find('input', {'name': 'xsrf_token'})['value']
|
||||
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:
|
||||
logger.error("⛔ 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}"
|
||||
logger.debug(txt)
|
||||
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:
|
||||
txt = f"⛔ Not enough points to enter: {giveaway.game_name}"
|
||||
logger.debug(txt)
|
||||
|
@ -144,6 +151,7 @@ class SteamGifts:
|
|||
giveaway_ended_at=TableGiveaway.unix_timestamp_to_utc_datetime(giveaway.time_remaining_timestamp),
|
||||
cost=giveaway.cost,
|
||||
copies=giveaway.copies,
|
||||
contributor_level=giveaway.contributor_level,
|
||||
entered=entered,
|
||||
game_entries=giveaway.game_entries)
|
||||
with Session(engine) as session:
|
||||
|
|
|
@ -19,6 +19,7 @@ class Giveaway:
|
|||
self.game_entries = None
|
||||
self.user = None
|
||||
self.copies = None
|
||||
self.contributor_level = None
|
||||
self.time_created_timestamp = None
|
||||
self.time_remaining_string = 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.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(',', ''))
|
||||
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
|
||||
times = soup_item.select('div span[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_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):
|
||||
match = re.search('^.+/[a-z0-9]+/(?P<steam_app_id>[0-9]+)/$', steam_url, re.IGNORECASE)
|
||||
if match:
|
||||
|
|
|
@ -35,6 +35,7 @@ class TableGiveaway(Base):
|
|||
giveaway_ended_at = Column(DateTime(timezone=True), nullable=False)
|
||||
cost = Column(Integer(), nullable=False)
|
||||
copies = Column(Integer(), nullable=False)
|
||||
contributor_level = Column(Integer(), nullable=False)
|
||||
entered = Column(Boolean(), nullable=False)
|
||||
game_entries = Column(Integer(), nullable=False)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
|
Loading…
Reference in a new issue