Skip to content

Commit 6718224

Browse files
authored
Merge pull request #61 from wizzro/master
Add pushover notification
2 parents 15423fa + 522f8f3 commit 6718224

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ Now you should be able to trigger the event
244244
python script/spider.py --config config/prod.cfg --notify join
245245
```
246246

247+
### Pushover notification
248+
249+
* Get your [USER_KEY](https://pushover.net/)
250+
* Create a [new application](https://pushover.net/apps/build)
251+
* (Optional) Add an [icon](https://pushover.net/icons/9aqpv697p9g6wzo.png)
252+
* Change your pushover credentials in the config file
253+
254+
```
255+
[pushover]
256+
pushover.user_key=PUSHOVER_USER_KEY
257+
pushover.api_key=PUSHOVER_API_KEY
258+
```
259+
247260
### Heroku
248261

249262
Create a new branch

config/prod_example.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ join.api_key=API_KEY
6060
firebase.database_secret=FIREBASE_DATABASE_SECRET
6161
firebase.url=FIREBASE_URL
6262
firebase.path=/books
63+
64+
[pushover]
65+
pushover.user_key=PUSHOVER_USER_KEY
66+
pushover.api_key=PUSHOVER_API_KEY

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ paramiko==2.0.2
1313
cryptography==1.6
1414
scp==0.10.2
1515
onedrivesdk==1.1.8
16-
16+
python-pushover==0.3

script/notification/mypushover.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from logs import *
2+
import requests
3+
from pushover import Client
4+
5+
class Pushover(object):
6+
"""
7+
"""
8+
9+
def __init__(self, config, packpub_info, upload_info):
10+
self.__config = config
11+
self.__packpub_info = packpub_info
12+
self.__client = Client(self.__config.get('pushover', 'pushover.user_key'), api_token=self.__config.get('pushover', 'pushover.api_key'))
13+
14+
15+
def send(self):
16+
self.__client.send_message(self.__packpub_info['description'].encode('utf-8'), title="New book downloaded from Packt: " + self.__packpub_info['title'].encode('utf-8'), url="https://www.packtpub.com/packt/offers/free-learning", url_title="See more")
17+
log_success('[+] notification sent to pushover')
18+
19+
def sendError(self, exception, source):
20+
self.__client.send_message(repr(exception), title='packtpub-crawler {source}: Could not download ebook'.format(source=source))
21+
log_success('[+] error notification sent to pushover')

script/notify.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from notification.ifttt import Ifttt
33
from logs import *
44
from notification.join import Join
5+
from notification.mypushover import Pushover
56

67
SERVICE_GMAIL = 'gmail'
78
SERVICE_IFTTT = 'ifttt'
89
SERVICE_JOIN = 'join'
10+
SERVICE_PUSHOVER = 'pushover'
911

1012
class Notify(object):
1113
"""
@@ -23,6 +25,8 @@ def __init__(self, config, packpub_info, upload_info, service_type):
2325
self.service = Ifttt(config, packpub_info, upload_info)
2426
elif service_type == SERVICE_JOIN:
2527
self.service = Join(config, packpub_info, upload_info)
28+
elif service_type == SERVICE_PUSHOVER:
29+
self.service = Pushover(config, packpub_info, upload_info)
2630

2731
def run(self):
2832
"""

script/spider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from upload import Upload, SERVICE_GOOGLE_DRIVE, SERVICE_ONEDRIVE, SERVICE_DROPBOX, SERVICE_SCP
1010
from database import Database, DB_FIREBASE
1111
from logs import *
12-
from notify import Notify, SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN
12+
from notify import Notify, SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN, SERVICE_PUSHOVER
1313
from noBookException import NoBookException
1414
from alreadyClaimedException import AlreadyClaimedException
1515

@@ -67,7 +67,7 @@ def main():
6767
parser.add_argument('-e', '--extras', action='store_true', help='download source code (if exists) and book cover')
6868
parser.add_argument('-u', '--upload', choices=[SERVICE_GOOGLE_DRIVE, SERVICE_ONEDRIVE, SERVICE_DROPBOX, SERVICE_SCP], help='upload to cloud')
6969
parser.add_argument('-a', '--archive', action='store_true', help='compress all file')
70-
parser.add_argument('-n', '--notify', choices=[SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN], help='notify after claim/download')
70+
parser.add_argument('-n', '--notify', choices=[SERVICE_GMAIL, SERVICE_IFTTT, SERVICE_JOIN, SERVICE_PUSHOVER], help='notify after claim/download')
7171
parser.add_argument('-s', '--store', choices=[DB_FIREBASE], help='store info')
7272
parser.add_argument('-o', '--claimOnly', action='store_true', help='only claim books (no downloads/uploads)')
7373

0 commit comments

Comments
 (0)