Add config file and screenshot capability
This commit is contained in:
parent
fc74020f6c
commit
71e6b6c831
|
|
@ -1,6 +1,9 @@
|
|||
#Github Updated - NotifyBot 9
|
||||
#Github Updated - NotifyBot 10
|
||||
#Import Modules
|
||||
#Setup Geopy
|
||||
#Clear Terminal
|
||||
import os
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
from geopy.geocoders import Nominatim
|
||||
geolocator = Nominatim(user_agent="OpenSkyBot", timeout=5)
|
||||
|
||||
|
|
@ -10,20 +13,32 @@ from colorama import Fore, Back, Style
|
|||
import datetime
|
||||
from defOpenSky import pullplane
|
||||
from defMap import getMap
|
||||
#Setup Config File
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
#Setup PushBullet
|
||||
from pushbullet import Pushbullet
|
||||
pb = Pushbullet("<pushbulletapikey>")
|
||||
pb_channel = pb.get_channel('<channeltaghere>')
|
||||
if config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||
from pushbullet import Pushbullet
|
||||
pb = Pushbullet(config['PUSHBULLET']['API_KEY'])
|
||||
pb_channel = pb.get_channel(config.get('PUSHBULLET', 'CHANNEL_TAG'))
|
||||
else:
|
||||
pb_channel = None
|
||||
pb = None
|
||||
|
||||
from defSS import getSS
|
||||
|
||||
#Setup Tweepy
|
||||
from defTweet import tweepysetup
|
||||
tweet_api = tweepysetup()
|
||||
if config.getboolean('TWITTER', 'ENABLE'):
|
||||
from defTweet import tweepysetup
|
||||
tweet_api = tweepysetup()
|
||||
else:
|
||||
tweet_api = None
|
||||
#Set Plane ICAO
|
||||
TRACK_PLANE = '<planeicaohere>'
|
||||
TRACK_PLANE = config.get('PLANE', 'ICAO')
|
||||
icao = TRACK_PLANE.upper()
|
||||
#Pre Set Variables
|
||||
geo_altitude = None
|
||||
#Pre Set Non Reseting Variables
|
||||
geo_alt_ft = None
|
||||
last_geo_alt_ft = None
|
||||
last_below_desired_ft = None
|
||||
|
|
@ -63,7 +78,7 @@ while True:
|
|||
#Pull Variables from planeData
|
||||
if planeData != None:
|
||||
for dataStates in planeData.states:
|
||||
icao = (dataStates.icao24)
|
||||
icao = (dataStates.icao24).upper()
|
||||
callsign = (dataStates.callsign)
|
||||
longitude = (dataStates.longitude)
|
||||
latitude = (dataStates.latitude)
|
||||
|
|
@ -165,15 +180,19 @@ while True:
|
|||
tookoff_message = ("Just took off from" + " " + aera_hierarchy + ", " + state + ", " + country_code)
|
||||
print (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)
|
||||
getSS(icao)
|
||||
if pb != None:
|
||||
with open("map.png", "rb") as pic:
|
||||
map_data = pb.upload_file(pic, "Tookoff IMG")
|
||||
push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), tookoff_message)
|
||||
push = pb_channel.push_file(**map_data)
|
||||
with open("screenshot.png", "rb") as pic:
|
||||
map_data = pb.upload_file(pic, "Tookoff IMG2")
|
||||
push = pb_channel.push_file(**map_data)
|
||||
if tweet_api != None:
|
||||
tweet_api.update_with_media("map.png", status = tookoff_message)
|
||||
takeoff_time = time.time()
|
||||
|
||||
|
||||
|
||||
if landed:
|
||||
landed_time_msg = ""
|
||||
if takeoff_time != None:
|
||||
|
|
@ -182,15 +201,21 @@ while True:
|
|||
landed_message = ("Landed just now in" + " " + aera_hierarchy + ", " + state + ", " + country_code + ". " + landed_time_msg)
|
||||
print (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)
|
||||
getSS(icao)
|
||||
if pb != None:
|
||||
with open("map.png", "rb") as pic:
|
||||
map_data = pb.upload_file(pic, "Landed IMG")
|
||||
push = pb_channel.push_note(config.get('PUSHBULLET', 'TITLE'), landed_message)
|
||||
push = pb_channel.push_file(**map_data)
|
||||
with open("screenshot.png", "rb") as pic:
|
||||
map_data = pb.upload_file(pic, "Landed IMG2")
|
||||
push = pb_channel.push_file(**map_data)
|
||||
if tweet_api != None:
|
||||
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
|
||||
last_feeding = feeding
|
||||
last_geo_alt_ft = geo_alt_ft
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
#V1
|
||||
[PLANE]
|
||||
#Plane
|
||||
ICAO = planeicaohere
|
||||
|
||||
#Place Opensky credentials here
|
||||
[OPENSKY]
|
||||
USERNAME = None
|
||||
PASSWORD = None
|
||||
|
||||
[GOOGLE]
|
||||
#API KEYS - enable static map images API in GCP and get key
|
||||
STATICMAPKEY = googleapikey
|
||||
|
||||
|
||||
|
||||
[TWITTER]
|
||||
ENABLE = FALSE
|
||||
CONSUMER_KEY = ckhere
|
||||
CONSUMER_SECRET = cshere
|
||||
ACCESS_TOKEN = athere
|
||||
ACCESS_TOKEN_SECRET = atshere
|
||||
|
||||
[PUSHBULLET]
|
||||
ENABLE = FALSE
|
||||
TITLE = "Title"
|
||||
API_KEY = apikey
|
||||
CHANNEL_TAG = channeltag
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
def getMap(mapLocation):
|
||||
import requests
|
||||
api_key = "<google maps static api key>"
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
api_key = config.get('GOOGLE', 'STATICMAPKEY')
|
||||
url = "https://maps.googleapis.com/maps/api/staticmap?"
|
||||
|
||||
center = str(mapLocation)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
def pullplane(TRACK_PLANE):
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
from opensky_api import OpenSkyApi
|
||||
opens_api = OpenSkyApi("<openskyusername>", "<openskypass>")
|
||||
opens_api = OpenSkyApi(config.get('OPENSKY', 'USERNAME'), config.get('OPENSKY', 'PASSWORD'))
|
||||
planeData = opens_api.get_states(time_secs=0, icao24=TRACK_PLANE.lower())
|
||||
return planeData
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#https://pypi.org/project/selenium/
|
||||
#https://zwbetz.com/download-chromedriver-binary-and-add-to-your-path-for-automated-functional-testing/
|
||||
#https://pythonspot.com/selenium-take-screenshot/
|
||||
#https://sites.google.com/a/chromium.org/chromedriver/downloads
|
||||
#https://tecadmin.net/setup-selenium-with-chromedriver-on-debian/
|
||||
#https://blog.testproject.io/2018/02/20/chrome-headless-selenium-python-linux-servers/
|
||||
#https://serverfault.com/questions/172076/how-to-find-the-browser-versions-from-command-line-in-linux-windows
|
||||
from selenium import webdriver
|
||||
import time
|
||||
def getSS(icao):
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
chrome_options.add_argument('--headless')
|
||||
chrome_options.add_argument('window-size=800,800')
|
||||
# chrome_options.add_argument('--no-sandbox') # required when running as root user. otherwise you would get no sandbox errors.
|
||||
browser = webdriver.Chrome(options=chrome_options)
|
||||
url = "https://globe.adsbexchange.com/?largeMode=2&hideButtons&hideSidebar&zoom=9&icao=" + icao
|
||||
browser.get(url)
|
||||
time.sleep(10)
|
||||
browser.save_screenshot("screenshot.png")
|
||||
browser.quit()
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
# Authenticate to Twitter
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
import tweepy
|
||||
def tweepysetup():
|
||||
#DOCU
|
||||
#https://realpython.com/twitter-bot-python-tweepy/
|
||||
import tweepy
|
||||
auth = tweepy.OAuthHandler("CONSUMER_KEY", "CONSUMER_SECRET")
|
||||
auth.set_access_token("ACCESS_TOKEN", "ACCESS_TOKEN_SECRET")
|
||||
auth = tweepy.OAuthHandler(config.get('TWITTER', 'CONSUMER_KEY'), config.get('TWITTER', 'CONSUMER_SECRET'))
|
||||
auth.set_access_token(config.get('TWITTER', 'ACCESS_TOKEN'), config.get('TWITTER', 'ACCESS_TOKEN_SECRET'))
|
||||
tweet_api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
|
||||
return tweet_api
|
||||
Loading…
Reference in New Issue