run from config.ini file

This commit is contained in:
mcinj 2022-04-23 12:34:04 -04:00
parent e6a7aa780e
commit 9e481fc2e3
4 changed files with 44 additions and 11 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
env/ env/
*.ini *.ini
__pycache__/ __pycache__/
.idea

View file

@ -14,4 +14,4 @@ COPY requirements.txt .
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
COPY ./src/* /app/ COPY ./src/* /app/
CMD ["python", "cli.py"] CMD ["python", "run.py"]

View file

@ -84,29 +84,39 @@ class SteamGifts:
game_list = soup.find_all('div', {'class': 'giveaway__row-inner-wrap'}) game_list = soup.find_all('div', {'class': 'giveaway__row-inner-wrap'})
if not len(game_list): if not len(game_list):
log("⛔ Page is empty. Please, select another type.", "red") random_seconds = randint(900, 1400)
sleep(10) txt = f"We have run out of gifts to consider. Trying again in {random_seconds} seconds."
exit() log(txt, "yellow")
sleep(random_seconds)
self.start()
continue
for item in game_list: for item in game_list:
if len(item.get('class', [])) == 2 and not self.pinned: if len(item.get('lass', [])) == 2 and not self.pinned:
continue continue
if self.points == 0 or self.points < self.min_points: if self.points == 0 or self.points < self.min_points:
txt = f"🛋️ Sleeping to get 6 points. We have {self.points} points, but we need {self.min_points} to start." random_seconds = randint(900, 1400)
txt = f"🛋️ Sleeping {random_seconds} seconds to get more points. We have {self.points} points, but we need {self.min_points} to start."
log(txt, "yellow") log(txt, "yellow")
sleep(900) sleep(random_seconds)
self.start() self.start()
break break
game_name = item.find('a', {'class': 'giveaway__heading__name'}).text
game_id = item.find('a', {'class': 'giveaway__heading__name'})['href'].split('/')[2]
game_cost = item.find_all('span', {'class': 'giveaway__heading__thin'})[-1] game_cost = item.find_all('span', {'class': 'giveaway__heading__thin'})[-1]
if game_cost: if game_cost:
game_cost = game_cost.getText().replace('(', '').replace(')', '').replace('P', '') game_cost = game_cost.getText().replace('(', '').replace(')', '').replace('P', '')
else: else:
continue continue
times = item.select('div span[data-timestamp]')
game_remaining = times[0].text
game_created = times[1].text
game_entries = item.select('div.giveaway__links span')[0].text
game_name = item.find('a', {'class': 'giveaway__heading__name'}).text txt = f"{game_name} {game_cost} - {game_entries} - Created {game_created} ago with {game_remaining} remaining."
log(txt, 'grey')
if self.points - int(game_cost) < 0: if self.points - int(game_cost) < 0:
txt = f"⛔ Not enough points to enter: {game_name}" txt = f"⛔ Not enough points to enter: {game_name}"
@ -114,7 +124,6 @@ class SteamGifts:
continue continue
elif self.points - int(game_cost) >= 0: elif self.points - int(game_cost) >= 0:
game_id = item.find('a', {'class': 'giveaway__heading__name'})['href'].split('/')[2]
res = self.entry_gift(game_id) res = self.entry_gift(game_id)
if res: if res:
self.points -= int(game_cost) self.points -= int(game_cost)

23
src/run.py Normal file
View file

@ -0,0 +1,23 @@
import configparser
config = configparser.ConfigParser()
def run():
from main import SteamGifts as SG
config.read('config.ini')
cookie = config['DEFAULT'].get('cookie')
pinned_games = config['DEFAULT'].getboolean('pinned')
gift_types = config['DEFAULT'].get('gift_types')
min_points = config['DEFAULT'].getint('minimum_points')
s = SG(cookie, gift_types, pinned_games, min_points)
s.start()
if __name__ == '__main__':
run()