modrzew / pokeminer

Pokemon location scraper
MIT License
220 stars 62 forks source link

Pushbullet integration? #110

Open puddingbrood opened 8 years ago

puddingbrood commented 8 years ago

I know the aim of this project is not for live usage, but it's definitely getting used as such. Should Pushbullet integration be added? It's incredibly easy to add. Just import the library from pushbullet .

Add this to the top of db.py from pushbullet import Pushbullet

Under Base = declarative_base() (around line 34) add pb = Pushbullet(config.PUSHBULLET_KEY)

And at around line 120 under session.add(obj) CACHE.add(obj) Add datestr = datetime.fromtimestamp(pokemon['expire_timestamp']) dateoutput = datestr.strftime("%H:%M:%S") if pokemon['pokemon_id'] in config.POKEMONS_PUSH: push = pb.push_link("Pokemon {} found! Disappears at {}".format(pokemon_names[str(pokemon['pokemon_id'])],str(dateoutput)), 'http://www.google.com/maps/place/{},{}'.format(pokemon['lat'],pokemon['lon']))

And finally add this to the config POKEMONS_PUSH = [3,6,9,26,28,31,34,36,38,45,51,53,57,62,65,68,71,76,78,83,85,89,94,103,105,107,112,114,115,127,128,130,131,132,137,139,141,142,143,148,149,150,151] PUSHBULLET_KEY = 'your pushbullet api key'

It might be more logical to do this in a second config and check if it's empty or not (less clutter for someone that doesn't use it).

LordLioath commented 8 years ago

Considering you put this all together, and that I'm not sure @modrzew will want this, you might want to just make a pull request with this instead, that way if he doesn't want it in the main branch, you already have a fork with it. Just seems a bit odd to make an issue with all the changes instead of a pull request.

modrzew commented 8 years ago

There's an existing discussion about webhooks in #87. What I have in mind is an interface that's similiar to Observer pattern that will simply notify all plugged subscribers about new sightings, without making any part of "core" pokeminer dependant on any subscriber. Then it should be easy enough to write addons like webhooks, pushbullet etc.

subzerofun commented 8 years ago

@puddingbrood – thanks for your integration of Pushbullet! however i can´t get the code to send a message when a pokemon is found. pokeminer - worker.py and web.py - are running without errors, the api key is also correct - i tested that by simply adding

push = pb.push_note("This is a test", "This really is a test")

right after

pb = Pushbullet(config.PUSHBULLET_KEY)

and immediately got a message on my phone (and browser).

but your code (datestr = datetime.fromtimestamp(pokemon['expire_timestamp']) ...) simply doesn´t get triggered. i have put the line with the ids in config.py, and of course, the api key.

so it should actually work... could the issue be that CACHE.add(obj) got renamed to 'SIGHTING_CACHE.add(pokemon)' ?

does it work for you with the latest version?

iluretar commented 8 years ago

@puddingbrood it's not working because pokemon_names doesn't exist in db.py you have to import it from names

from names import pokemon_names