Movatterモバイル変換


[0]ホーム

URL:


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

Commit522f8f3

Browse files
committed
Add pushover notification
1 parent15423fa commit522f8f3

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+
fromlogsimport*
2+
importrequests
3+
frompushoverimportClient
4+
5+
classPushover(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+
defsend(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+
defsendError(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
fromnotification.iftttimportIfttt
33
fromlogsimport*
44
fromnotification.joinimportJoin
5+
fromnotification.mypushoverimportPushover
56

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

1012
classNotify(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
elifservice_type==SERVICE_JOIN:
2527
self.service=Join(config,packpub_info,upload_info)
28+
elifservice_type==SERVICE_PUSHOVER:
29+
self.service=Pushover(config,packpub_info,upload_info)
2630

2731
defrun(self):
2832
"""

‎script/spider.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
fromuploadimportUpload,SERVICE_GOOGLE_DRIVE,SERVICE_ONEDRIVE,SERVICE_DROPBOX,SERVICE_SCP
1010
fromdatabaseimportDatabase,DB_FIREBASE
1111
fromlogsimport*
12-
fromnotifyimportNotify,SERVICE_GMAIL,SERVICE_IFTTT,SERVICE_JOIN
12+
fromnotifyimportNotify,SERVICE_GMAIL,SERVICE_IFTTT,SERVICE_JOIN,SERVICE_PUSHOVER
1313
fromnoBookExceptionimportNoBookException
1414
fromalreadyClaimedExceptionimportAlreadyClaimedException
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)

[8]ページ先頭

©2009-2025 Movatter.jp