From a64e6310eeb9f4877d6c25d1d5de0488e51a5e4b Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Date: Wed, 30 Nov 2011 00:07:39 +0100 Subject: [PATCH] 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. --- steam_discounts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/steam_discounts b/steam_discounts index 8e9d350..836043b 100755 --- a/steam_discounts +++ b/steam_discounts @@ -126,9 +126,14 @@ if __name__ == '__main__': page = conn.read() conn.close() mo = re.search(r'.*?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(