From 9a10edbc608c222a70e761b432a892fa5d35e041 Mon Sep 17 00:00:00 2001 From: Jxck-S Date: Wed, 22 Jul 2020 12:35:45 -0400 Subject: [PATCH] Add Image Map ability --- OpenSky Bot.py | 36 ++++++++++++++++++++++++++---------- defMap.py | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 defMap.py diff --git a/OpenSky Bot.py b/OpenSky Bot.py index 7679cd6..ea531c4 100644 --- a/OpenSky Bot.py +++ b/OpenSky Bot.py @@ -1,18 +1,20 @@ +#Github Updated - NotifyBot 8 #Import Modules #Setup Geopy from geopy.geocoders import Nominatim -geolocator = Nominatim(user_agent="*", timeout=5) +geolocator = Nominatim(user_agent="OpenSkyBot", timeout=5) import json import time from colorama import Fore, Back, Style import datetime from defOpenSky import pullplane +from defMap import getMap #Setup PushBullet from pushbullet import Pushbullet pb = Pushbullet("") -elon_jet_channel = pb.get_channel('') +pb_channel = pb.get_channel('') #Setup Tweepy from defTweet import tweepysetup @@ -162,18 +164,32 @@ while True: if tookoff: tookoff_message = ("Just took off from" + " " + aera_hierarchy + ", " + state + ", " + country_code) print (tookoff_message) - push = elon_jet_channel.push_note("title", tookoff_message) - tweet_api.update_status(tookoff_message) + getMap(aera_hierarchy + ", " + state + ", " + country_code) + 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() - if landed: - landed_message = ("Landed just now in" + " " + aera_hierarchy + ", " + state + ", " + country_code) + if landed: + 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) - push = elon_jet_channel.push_note("title", landed_message) - tweet_api.update_status(landed_message) + getMap(aera_hierarchy + ", " + state + ", " + country_code) + 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 + landed_time = None + time_since_tk = None #Set Variables to compare to next check @@ -187,8 +203,8 @@ while True: planeDataMSG = str(planeData) if takeoff_time != None: elapsed_time = time.time() - takeoff_time - timesince = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(elapsed_time)) - print(timesince) + time_since_tk = time.strftime("Time Since Take off %H Hours : %M Mins : %S Secs", time.gmtime(elapsed_time)) + print(time_since_tk) diff --git a/defMap.py b/defMap.py new file mode 100644 index 0000000..f42313e --- /dev/null +++ b/defMap.py @@ -0,0 +1,22 @@ +def getMap(mapLocation): + import requests + 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() \ No newline at end of file