Permalink
Browse files

Fix error extracting the number of discounts

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...
1 parent 81ebbf3 commit a64e6310eeb9f4877d6c25d1d5de0488e51a5e4b @rg3 committed Nov 29, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 steam_discounts
View
11 steam_discounts
@@ -126,9 +126,14 @@ if __name__ == '__main__':
page = conn.read()
conn.close()
mo = re.search(r'<span id="tab_Discounts_count_start">.*?of +(\d+)', page)
- if mo is None:
- sys.exit('ERROR: unable to extract the total number of discounts')
- max_discounts = int(mo.group(1))
+ if mo is not None:
+ 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.
conn = urllib.urlopen(

0 comments on commit a64e631

Please sign in to comment.