Skip to content

Commit bee57ae

Browse files
authored
Merge pull request #71 from juzim/manual-claim-on-error
Include book title and URL in error message
2 parents e604cc1 + 1dd5515 commit bee57ae

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ python script/spider.py --config config/prod.cfg --notify ifttt
224224
Value mappings:
225225
* value1: title
226226
* value2: description
227-
* value3: image URL
227+
* value3: landing page URL
228228

229229
### Join notification
230230

script/notification/gmail.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ def __prepare_error_message(self, exception, source):
7272
<head></head>
7373
<body>
7474
<div>{title}</div>
75+
<div>Download manually: <a href="{url}">{url}</a></div>
7576
<div>{description}</div>
7677
""".format(title=text,
77-
description=repr(exception))
78+
description=repr(exception),
79+
url=self.__packpub_info['landingPageUrl'])
7880

7981
html += """\
8082
<div>Powered by <a href="https://github.com/niqdev/packtpub-crawler">packtpub-crawler</a></div>

script/notification/ifttt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def send(self):
2222

2323
def sendError(self, exception, source):
2424
title = "packtpub-crawler [{source}]: Could not download ebook".format(source=source)
25-
r = requests.post(self.__url, data = {'value1':title, 'value2':repr(exception)})
25+
r = requests.post(self.__url, data = {'value1':title, 'value2':repr(exception), 'value3':self.__packpub_info['landingPageUrl']})
2626

2727
log_success('[+] error notification sent to IFTTT')

script/notification/join.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def send(self):
2222
log_success('[+] notification sent to Join')
2323

2424
def sendError(self, exception, source):
25-
url = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?apikey={apiKey}&deviceId={deviceIds}&title={title}&text={description}".format(
25+
url = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?apikey={apiKey}&deviceId={deviceIds}&title={title}&text={description}&url={url}".format(
2626
apiKey=self.__config.get('join', 'join.api_key'),
2727
deviceIds=self.__config.get('join', 'join.device_ids'),
28-
title='packtpub-crawler {source}: Could not download ebook'.format(source=source),
29-
description=repr(exception)
28+
title='packtpub-crawler {source}: Could not download ebook: {title}'.format(source=source, title=self.__packpub_info['title']),
29+
description=repr(exception),
30+
url=self.__packpub_info['landingPageUrl']
3031
)
3132

3233
r = requests.post(url)

script/packtpub.py

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def runDaily(self):
148148
else:
149149
loginUrl = self.__url_base + self.__config.get('url', 'url.login')
150150

151+
self.info['landingPageUrl'] = loginUrl
152+
151153
soup = self.__GET_login(loginUrl)
152154
wait(self.__delay, self.__dev)
153155

@@ -166,6 +168,8 @@ def runNewsletter(self, currentNewsletterUrl):
166168
"""
167169

168170
soup = self.__GET_login(currentNewsletterUrl)
171+
self.info['landingPageUrl'] = currentNewsletterUrl
172+
169173
self.__parseNewsletterBookInfo(soup)
170174
wait(self.__delay, self.__dev)
171175
self.__GET_claim()

script/spider.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ def main():
101101
except Exception as e:
102102
log_debug(e)
103103
if args.notify:
104-
Notify(config, None, None, args.notify).sendError(e, 'daily')
105-
return
104+
Notify(config, packtpub.info, None, args.notify).sendError(e, 'daily')
106105

107106
lastNewsletterUrlPath = dir_path + 'config/lastNewsletterUrl'
108107
lastNewsletterUrl = None
@@ -135,7 +134,7 @@ def main():
135134
except Exception as e:
136135
log_debug(e)
137136
if args.notify:
138-
Notify(config, None, None, args.notify).sendError(e, 'newsletter')
137+
Notify(config, packtpub.info, None, args.notify).sendError(e, 'newsletter')
139138
else:
140139
log_info('[*] already got latest ebook from newsletter, skipping')
141140

0 commit comments

Comments
 (0)