Advertisement
Readdeo

notifier.py gmaps link fix for bad-r0bot

Jul 28th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4.  
  5. import json
  6. from pushbullet import Pushbullet
  7. from datetime import datetime
  8. import sys
  9.  
  10.  
  11. # Fixes the encoding of the male/female symbol
  12. reload(sys)
  13. sys.setdefaultencoding('utf8')
  14.  
  15. pushbullet_client = None
  16. wanted_pokemon = list()
  17.  
  18. with open('locales/pokemon.en.json') as f:
  19. pokemon_names = json.load(f)
  20.  
  21. # Initialize object
  22. def init():
  23. global pushbullet_client, wanted_pokemon
  24. # load pushbullet key
  25.  
  26. wanted_pokemon = ["Ivysaur", "Venusaur", "Charmeleon",
  27. "Charizard", "Wartortle", "Blastoise", "Butterfree", "Beedrill", "Arbok",
  28. "Raichu", "Sandslash", "Nidorina", "Nidoqueen", "Nidorino", "Nidoking", "Clefable",
  29. "Ninetales", "Wigglytuff", "Gloom", "Vileplume", "Parasect", "Venomoth",
  30. "Dugtrio", "Golduck", "Primeape", "Growlithe", "Arcanine", "Poliwrath", "Kadabra",
  31. "Alakazam", "Machoke", "Machamp", "Weepinbell", "Victreebel", "Tentacruel", "Graveler",
  32. "Golem", "Rapidash", "Slowbro", "Magneton", "Farfetch'd", "Dodrio", "Dewgong", "Muk",
  33. "Cloyster", "Haunter", "Gengar", "Exeggcute", "Exeggutor", "Marowak",
  34. "Weezing", "Rhydon", "Chansey", "Kangaskhan", "Seadra",
  35. "Mr. Mime", "Scyther", "Electabuzz", "Magmar", "Pinsir", "Tauros",
  36. "Gyarados", "Lapras", "Ditto", "Vaporeon", "Jolteon", "Flareon", "Porygon",
  37. "Omanyte", "Omastar", "Kabuto", "Kabutops", "Aerodactyl", "Snorlax", "Articuno",
  38. "Zapdos", "Moltres", "Dragonair", "Dragonite", "Mewtwo", "Mew" ]
  39. api_key = "PUSH BULLET API KEY HERE" #get one by setting up an account through pushbullet.com
  40. if api_key:
  41. pushbullet_client = Pushbullet(api_key)
  42.  
  43. # Safely parse incoming strings to unicode
  44. def _str(s):
  45. return s.encode('utf-8').strip()
  46.  
  47. #Google maps link
  48. def gmaps_link(lat, lng):
  49. latLon = '{},{}'.format(repr(lat), repr(lng))
  50. return 'http://maps.google.com/maps?q={}'.format(latLon)
  51.  
  52. # Notify user for discovered Pokemon
  53. def pokemon_found(pokemon):
  54. global wanted_pokemon
  55. # get name
  56. pokename = pokemon_names[str(pokemon['id'])]
  57. # check array
  58. if not pushbullet_client:
  59. #print "[-] %%%%%%%%%%%% Notifier error: pushbullet failure"
  60. return
  61. if not pokename in wanted_pokemon:
  62. #print "[-] %%%%%%%%%%%% Notifier error: pokemon not wanted"
  63. return
  64. # notify
  65. #print "[+] ************************************* Notifier found pokemon:", pokename
  66.  
  67. google_maps_link = gmaps_link(pokemon["lat"], pokemon["lng"])
  68.  
  69. notification_text = "Pokemon Finder found " + _str(pokename) + "!"
  70. disappear_time = str(datetime.fromtimestamp(pokemon["disappear_time"]).strftime("%I:%M%p").lstrip('0'))+")"
  71. location_text = "Locate on Google Maps : " + google_maps_link + ". " + _str(pokename) + " will be available until " + disappear_time + "."
  72.  
  73. push = pushbullet_client.push_link(notification_text, google_maps_link, body=location_text)
  74.  
  75.  
  76.  
  77. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement