Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c6c05f

Browse files
authored
Merge pull request #50 from juzim/fix-error-on-already-claimed
Check if newsletter was already claimed before processing
2 parents fa18463 + 30f861c commit 1c6c05f

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

‎script/alreadyClaimedException.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class AlreadyClaimedException(Exception):
2+
pass

‎script/noBookException.py‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎script/packtpub.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from utils import make_soup, wait, download_file
55
from logs import *
66
from noBookException import NoBookException
7+
from alreadyClaimedException import AlreadyClaimedException
78

89
class Packtpub(object):
910
"""
@@ -16,6 +17,9 @@ def __init__(self, config, dev):
1617
self.__url_base = self.__config.get('url', 'url.base')
1718
self.__headers = self.__init_headers()
1819
self.__session = requests.Session()
20+
self.resetInfo()
21+
22+
def resetInfo(self):
1923
self.info = {
2024
'paths': []
2125
}
@@ -122,6 +126,11 @@ def __GET_claim(self):
122126
if div_target is None:
123127
raise Exception('Could not access claim page. This is most likely caused by invalid credentials')
124128

129+
errorMessage = soup.find(id='messages-container')
130+
131+
if errorMessage is not None and errorMessage.text.strip() == 'You have already claimed this promotion.':
132+
raise AlreadyClaimedException()
133+
125134
# only last one just claimed
126135
div_claimed_book = div_target.select('.product-line')[0]
127136
self.info['book_id'] = div_claimed_book['nid']

‎script/spider.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from logs import *
1212
from notify import Notify, SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN
1313
from noBookException import NoBookException
14+
from alreadyClaimedException import AlreadyClaimedException
1415

1516
def parse_types(args):
1617
if args.types is None:
@@ -120,12 +121,17 @@ def main():
120121
elif lastNewsletterUrl != currentNewsletterUrl:
121122
log_info('[*] getting free eBook from newsletter')
122123
try:
124+
packtpub.resetInfo()
123125
packtpub.runNewsletter(currentNewsletterUrl)
124126
handleClaim(packtpub, args, config, dir_path)
125127

126128
with open(lastNewsletterUrlPath, 'w+') as f:
127129
f.write(currentNewsletterUrl)
128130

131+
except AlreadyClaimedException as a:
132+
log_info('[*] book was already claimed, skipping')
133+
with open(lastNewsletterUrlPath, 'w+') as f:
134+
f.write(currentNewsletterUrl)
129135
except Exception as e:
130136
log_debug(e)
131137
if args.notify:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /