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

Commit

Permalink
Fix error extracting the number of discounts
Browse files Browse the repository at this point in the history
Apparently always asking for thousands of discounts does not always
work, but when there are only a few discounts, the number is not
mentioned explicitly anywhere in the page.

The solution is to combine two approaches. If the number of discounts is
not found, try counting the number of discounts directly in the front
page.
  • Loading branch information
rg3 committed Nov 29, 2011
1 parent 81ebbf3 commit a64e631
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions steam_discounts
Expand Up @@ -126,9 +126,14 @@ if __name__ == '__main__':
page = conn.read() page = conn.read()
conn.close() conn.close()
mo = re.search(r'<span id="tab_Discounts_count_start">.*?of +(\d+)', page) mo = re.search(r'<span id="tab_Discounts_count_start">.*?of +(\d+)', page)
if mo is None: if mo is not None:
sys.exit('ERROR: unable to extract the total number of discounts') max_discounts = int(mo.group(1))
max_discounts = int(mo.group(1)) else:
# Only a few discounts, no "scrolling".
max_discounts = page.count('tab_row_Discounts_')

if max_discounts <= 0:
sys.exit('ERROR: invalid number of discounts found: %d' % (max_discounts, ))


# Retrieve the discounts. # Retrieve the discounts.
conn = urllib.urlopen( conn = urllib.urlopen(
Expand Down

0 comments on commit a64e631

Please sign in to comment.