Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Commit

Permalink
feat: save codes in a text file
Browse files Browse the repository at this point in the history
  • Loading branch information
sibalzer committed Nov 28, 2021
1 parent 802db48 commit b55e526
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.log
cookies.txt
publishers.txt
game_codes.txt

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ services:
volumes:
- ./cookies.txt:/app/cookies.txt # must exist before launching
- ./publishers.txt:/app/publishers.txt # must exist before launching
- ./game_codes.txt:/app/game_codes.txt # must exist before launching
environment:
- TZ=Europe/Berlin
17 changes: 17 additions & 0 deletions primelooter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.browser.close()
self.playwright.__exit__()

@staticmethod
def code_to_file(game: str, code: str, instructions: str) -> None:
with open(f'./game_codes.txt', 'a') as f:
f.write(f"{game}: {code}\n ({instructions.replace('/n',' ')})")

@staticmethod
def exists(tab: Page, selector: str) -> bool:
if tab.query_selector(selector):
Expand Down Expand Up @@ -127,6 +132,18 @@ def claim_external(self, url, publisher):
if PrimeLooter.exists(tab, 'div.gms-success-modal-container'):
log.info("Claimed %s (%s)", loot_name, game_name)

if PrimeLooter.exists(tab, 'div.get-my-stuff-modal-code-success'):
try:
code = tab.query_selector(
'div.get-my-stuff-modal-code div[data-a-target="copy-code-input"] input').get_attribute('value').strip()
instructions = tab.query_selector(
'div[data-a-target=gms-claim-instructions]').inner_text().strip()
PrimeLooter.code_to_file(
game_name, code, instructions)
except Exception as e:
log.warning(
"Could not get code for %s (%s) from %s", loot_name, game_name, publisher)

elif PrimeLooter.exists(tab, "div[data-test-selector=ProgressBarSection]"):
log.warning(
"Could not claim %s from %s by %s (account not connected)", loot_name, game_name, publisher)
Expand Down

0 comments on commit b55e526

Please sign in to comment.