├── README.md ├── notify.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # apollo-notifications 2 | 3 | A simple python script that polls your reddit inbox for new comments/messages 4 | and then sends notifications via Pushover with the urls formatted for Apollo. 5 | 6 | When opening these notifications the links will automatically redirect to the 7 | Apollo app. 8 | 9 | ## install dependencies 10 | 11 | ```` 12 | pip3 install -r requirements.txt 13 | ```` 14 | 15 | ## setup 16 | 17 | 1. create a "personal use script" app here: https://old.reddit.com/prefs/apps/ 18 | 19 | note the client id/secret 20 | 21 | 2. buy the awesome pushover app for iOS and make an account here: https://pushover.net 22 | 23 | 3. create an application for apollo on https://pushover.net and give it a cool 24 | Apollo icon 25 | 26 | note your pushover account user id and the key for the app you created there 27 | 28 | 4. edit the code and change the parameters as per comments 29 | -------------------------------------------------------------------------------- /notify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import praw 4 | import pyotp 5 | import json 6 | import os 7 | import pwd 8 | import prawcore.exceptions 9 | import time 10 | import sys 11 | from pushover import Client 12 | 13 | # pushover user key 14 | PUSHOVER_USER = '' 15 | # push over app key 16 | PUSHOVER_APP = '' 17 | # 2FA secret (if using 2FA) 18 | KEY = '' 19 | # reddit oauth - create "personal use script" app at https://old.reddit.com/prefs/apps/ 20 | CLIENT_ID = '' 21 | CLIENT_SECRET = '' 22 | # reddit username/password 23 | USERNAME = '' 24 | PASSWORD = '' 25 | 26 | if len(KEY) >0: 27 | totp = pyotp.TOTP(KEY) 28 | 29 | class RedditNotifications: 30 | 31 | def __init__(self): 32 | self.reddit = praw.Reddit( 33 | client_id=CLIENT_ID, 34 | client_secret=CLIENT_SECRET, 35 | # set this to just PASSWORD if you don't use 2FA 36 | password=PASSWORD if len(KEY) == 0 else PASSWORD + ":" + totp.now(), 37 | user_agent="APP", 38 | username=USERNAME 39 | ) 40 | 41 | homedir = pwd.getpwuid(os.getuid()).pw_dir 42 | self.datafile = f"{homedir}/.reddit_seen" 43 | 44 | if os.path.exists(self.datafile): 45 | self.seen = json.loads(open(self.datafile).read()) 46 | else: 47 | self.seen = { 48 | 'message': {}, 49 | 'comment': {} 50 | } 51 | 52 | self.pushover = Client(PUSHOVER_USER, api_token=PUSHOVER_APP) 53 | 54 | 55 | def main(self): 56 | for i in range(0, 3): 57 | try: 58 | for item in self.reddit.inbox.all(): 59 | if type(item) == praw.models.reddit.comment.Comment: 60 | if item.id in self.seen['comment']: 61 | continue 62 | 63 | self.handle_comment(item) 64 | elif type(item) == praw.models.reddit.message.Message or type(item) == praw.models.reddit.message.SubredditMessage: 65 | if item.id in self.seen['message']: 66 | continue 67 | 68 | self.handle_message(item) 69 | else: 70 | raise Exception("unknown item type: %s" % (type(item))) 71 | break 72 | except prawcore.exceptions.OAuthException: 73 | time.sleep(1) 74 | 75 | 76 | def handle_comment(self, item): 77 | url = 'apollo://reddit.com' + item.context 78 | 79 | self.pushover.send_message(item.body, title=item.submission.title, url=url) 80 | 81 | self.seen['comment'][item.id] = 1 82 | self.save() 83 | 84 | 85 | def handle_message(self, item): 86 | url = 'apollo://reddit.com/message/messages/' + item.id 87 | 88 | self.pushover.send_message(item.body, title=item.subject, url=url) 89 | 90 | self.seen['message'][item.id] = 1 91 | self.save() 92 | 93 | 94 | def save(self): 95 | with open(self.datafile + '.new','w') as f: 96 | f.write(json.dumps(self.seen,indent=4)) 97 | 98 | os.rename(self.datafile + '.new', self.datafile) 99 | 100 | 101 | r = RedditNotifications() 102 | r.main() 103 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | praw 2 | python-pushover2 3 | pyotp 4 | --------------------------------------------------------------------------------