Add Image Map ability
This commit is contained in:
parent
5cb1079fd9
commit
9a10edbc60
|
@ -1,18 +1,20 @@
|
||||||
|
#Github Updated - NotifyBot 8
|
||||||
#Import Modules
|
#Import Modules
|
||||||
#Setup Geopy
|
#Setup Geopy
|
||||||
from geopy.geocoders import Nominatim
|
from geopy.geocoders import Nominatim
|
||||||
geolocator = Nominatim(user_agent="*", timeout=5)
|
geolocator = Nominatim(user_agent="OpenSkyBot", timeout=5)
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
import datetime
|
import datetime
|
||||||
from defOpenSky import pullplane
|
from defOpenSky import pullplane
|
||||||
|
from defMap import getMap
|
||||||
|
|
||||||
#Setup PushBullet
|
#Setup PushBullet
|
||||||
from pushbullet import Pushbullet
|
from pushbullet import Pushbullet
|
||||||
pb = Pushbullet("<pushbulletapikey>")
|
pb = Pushbullet("<pushbulletapikey>")
|
||||||
elon_jet_channel = pb.get_channel('<channeltaghere>')
|
pb_channel = pb.get_channel('<channeltaghere>')
|
||||||
|
|
||||||
#Setup Tweepy
|
#Setup Tweepy
|
||||||
from defTweet import tweepysetup
|
from defTweet import tweepysetup
|
||||||
|
@ -162,18 +164,32 @@ while True:
|
||||||
if tookoff:
|
if tookoff:
|
||||||
tookoff_message = ("Just took off from" + " " + aera_hierarchy + ", " + state + ", " + country_code)
|
tookoff_message = ("Just took off from" + " " + aera_hierarchy + ", " + state + ", " + country_code)
|
||||||
print (tookoff_message)
|
print (tookoff_message)
|
||||||
push = elon_jet_channel.push_note("title", tookoff_message)
|
getMap(aera_hierarchy + ", " + state + ", " + country_code)
|
||||||
tweet_api.update_status(tookoff_message)
|
with open("map.png", "rb") as pic:
|
||||||
|
map_data = pb.upload_file(pic, "Tookoff")
|
||||||
|
push = pb_channel.push_note("title", tookoff_message)
|
||||||
|
push = pb_channel.push_file(**map_data)
|
||||||
|
tweet_api.update_with_media("map.png", status = tookoff_message)
|
||||||
takeoff_time = time.time()
|
takeoff_time = time.time()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if landed:
|
if landed:
|
||||||
landed_message = ("Landed just now in" + " " + aera_hierarchy + ", " + state + ", " + country_code)
|
landed_time_msg = ""
|
||||||
|
if takeoff_time != None:
|
||||||
|
landed_time = time.time() - takeoff_time
|
||||||
|
landed_time_msg = time.strftime("Apx. flt. time %H Hours : %M Mins ", time.gmtime(landed_time))
|
||||||
|
landed_message = ("Landed just now in" + " " + aera_hierarchy + ", " + state + ", " + country_code + ". " + landed_time_msg)
|
||||||
print (landed_message)
|
print (landed_message)
|
||||||
push = elon_jet_channel.push_note("title", landed_message)
|
getMap(aera_hierarchy + ", " + state + ", " + country_code)
|
||||||
tweet_api.update_status(landed_message)
|
with open("map.png", "rb") as pic:
|
||||||
|
map_data = pb.upload_file(pic, "Landed")
|
||||||
|
push = pb_channel.push_note("title", landed_message)
|
||||||
|
push = pb_channel.push_file(**map_data)
|
||||||
|
tweet_api.update_with_media("map.png", status = landed_message)
|
||||||
takeoff_time = None
|
takeoff_time = None
|
||||||
|
landed_time = None
|
||||||
|
time_since_tk = None
|
||||||
|
|
||||||
|
|
||||||
#Set Variables to compare to next check
|
#Set Variables to compare to next check
|
||||||
|
@ -187,8 +203,8 @@ while True:
|
||||||
planeDataMSG = str(planeData)
|
planeDataMSG = str(planeData)
|
||||||
if takeoff_time != None:
|
if takeoff_time != None:
|
||||||
elapsed_time = time.time() - takeoff_time
|
elapsed_time = time.time() - takeoff_time
|
||||||
timesince = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(elapsed_time))
|
time_since_tk = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(elapsed_time))
|
||||||
print(timesince)
|
print(time_since_tk)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
def getMap(mapLocation):
|
||||||
|
import requests
|
||||||
|
api_key = "<google maps static api key>"
|
||||||
|
url = "https://maps.googleapis.com/maps/api/staticmap?"
|
||||||
|
|
||||||
|
center = str(mapLocation)
|
||||||
|
zoom = 9
|
||||||
|
|
||||||
|
r = requests.get(url + "center=" + center + "&zoom=" +
|
||||||
|
str(zoom) + "&size=800x800 &key=" +
|
||||||
|
api_key + "&sensor=false")
|
||||||
|
|
||||||
|
# wb mode is stand for write binary mode
|
||||||
|
f = open('map.png', 'wb')
|
||||||
|
|
||||||
|
# r.content gives content,
|
||||||
|
# in this case gives image
|
||||||
|
f.write(r.content)
|
||||||
|
|
||||||
|
# close method of file object
|
||||||
|
# save and close the file
|
||||||
|
f.close()
|
Loading…
Reference in New Issue