Skip to content

Commit

Permalink
Run without twitter and based on location
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 14, 2022
1 parent d73aa4e commit 1c6a864
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 135 deletions.
6 changes: 5 additions & 1 deletion BotCommander/Commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def __init__(self):
print("")
print("*** Initializing The General ***")
print(" ")
self.flight_commander = FlightCommander()
lat = float(input("Enter Latitude: "))
lon = float(input("Enter Longitude: "))
distance = float(input("Enter Distance: (km) "))
self.flight_commander = FlightCommander(location=[lat, lon], distance=distance)
print("*** The General Initialized ***")


def step(self):
self.flight_commander.step()
sleep(10)
Expand Down
Binary file modified BotCommander/__pycache__/Commander.cpython-39.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions Database/FlightBots_Data/aircraft_codes_to_update.csv
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ BE18,False
P32R,False
LJ36,False
R22,False
TRIN,False
PA27,False
A169,False
P28R,False
LJ75,False
HA4T,False
NG5,False
PAY3,False
KODI,False
LAE1,False
AS29,False
DISC,False
DV20,False
AC95,False
C82S,False
BT36,False
AT8T,False
25 changes: 9 additions & 16 deletions FlightBots/FlightCommander.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@


class FlightCommander:
def loadFlightData(self, resetData):
if resetData == True:
self.flightData = forceResetFlightData()
else:
self.flightData = checkIfFlightDataExists()
def loadFlightData(self):
self.flightData = forceResetFlightData()

def createFilters(self, exclude=[]):
def createFilters(self, exclude=[1,2,3]):
self.filters = []
for i in range(0, len(SearchType)):
if i not in exclude:
self.filters.append(SearchFilter(filter_type=i, offset=i))

def __init__(self, resetData=False, exclude_filters=[]):
def __init__(self, location, distance, resetData=False, exclude_filters=[]):
self.current_index = 0
self.location = location
self.distance = distance
#print(" * Flight Data Object Not Found: Creating... *") ref size
print(" ** Initalizing Flight Commander **")
self.loadFlightData(resetData=resetData)
self.loadFlightData()
print(" * Intitalizing Flight Filters *")
self.createFilters(exclude=exclude_filters)
print(" * Flight Filters Initialized *")
Expand All @@ -42,19 +41,13 @@ def step(self):
for i in range(0, len(self.filters)):
if self.filters[i].next_index == self.current_index:
#Search with filter
if self.filters[i].searchWithFilters(self.flightData.getActivateFlights()) == True:
if self.filters[i].searchWithFilters(self.flightData.getActivateFlights(), self.location, self.distance) == True:
#Tweet Data
tweeted, response = tweetFlightData(self.filters[i].filtered_flights, self.filters[i].searchType)
#Print responses
print(self.filters[i].searchType.name.capitalize(), "Responses:")
for r in range(0, len(response)):
print(str(response[r][1]) + "x " + response[r][0])
#Move to Next Step
tweetFlightData(self.filters[i].filtered_flights, self.filters[i].searchType)
self.filters[i].moveToNextStep()
else:
self.filters[i].tryNextLoop()
#Save Current Flight Data
saveFlightData(self.flightData)
#Move To Next Index
self.current_index += 1
#Stop Overflow digits
Expand Down
2 changes: 1 addition & 1 deletion FlightBots/Helpers/FlightData.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def forceResetFlightData():
print(" * Force Reseting Flight Data *")
obj_path = 'SavedData/FlightData/flightData.pkl'
obj = FlightData()
return saveFlightData(obj)
return (obj)

#obj = checkIfFlightDataExists()
#print(obj)
107 changes: 6 additions & 101 deletions FlightBots/Helpers/Tweet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from twython import Twython
from twython import TwythonError

import cartopy.crs as ccrs
import os
import cartopy
Expand All @@ -8,64 +7,6 @@

from FlightBots.Templates.SearchFilter import SearchType

# IMPORT ACCOUNTS
# ********************************************
from TwiiterAuths.FlightBots_Auth.Military_Flights import (
consumer_key as consumer_key_military,
consumer_secret as consumer_secret_military,
access_token as access_token_military,
access_token_secret as access_token_secret_military
)

militaryFlights = Twython(
consumer_key_military,
consumer_secret_military,
access_token_military,
access_token_secret_military
)

from TwiiterAuths.FlightBots_Auth.Blocked_Flights import (
consumer_key as consumer_key_blocked,
consumer_secret as consumer_secret_blocked,
access_token as access_token_blocked,
access_token_secret as access_token_secret_blocked
)

blockedFlights = Twython(
consumer_key_blocked,
consumer_secret_blocked,
access_token_blocked,
access_token_secret_blocked
)

from TwiiterAuths.FlightBots_Auth.Billionaire_Flights import (
consumer_key as consumer_key_billionaire,
consumer_secret as consumer_secret_billionaire,
access_token as access_token_billionaire,
access_token_secret as access_token_secret_billionaire
)

billionaireFlights = Twython(
consumer_key_billionaire,
consumer_secret_billionaire,
access_token_billionaire,
access_token_secret_billionaire
)

from TwiiterAuths.FlightBots_Auth.Celebrity_Flights import (
consumer_key as comumer_key_celeb,
consumer_secret as consumer_secret_celeb,
access_token as access_token_celeb,
access_token_secret as access_token_secret_celeb
)

celebrityFlights = Twython(
comumer_key_celeb,
consumer_secret_celeb,
access_token_celeb,
access_token_secret_celeb
)
# ********************************************

def getLocation(latitude, longitude):
coordinates = [(latitude, longitude)]
Expand All @@ -88,44 +29,8 @@ def addResponse(responses, new_reponse):

strFile = "SavedData/FlightData/temp_map.jpg"

def sendTweet(status, type, lat, long):
try:
if type == SearchType.military:
photo = open(strFile, 'rb')
response = militaryFlights.upload_media(media=photo)
os.remove(strFile)
militaryFlights.update_status(status=status, lat=lat, long=long, media_ids=[response['media_id']])
elif type == SearchType.blocked:
photo = open(strFile, 'rb')
response = blockedFlights.upload_media(media=photo)
os.remove(strFile)
blockedFlights.update_status(status=status, lat=lat, long=long, media_ids=[response['media_id']])
elif type == SearchType.billionaire:
photo = open(strFile, 'rb')
response = billionaireFlights.upload_media(media=photo)
os.remove(strFile)
billionaireFlights.update_status(status=status, lat=lat, long=long, media_ids=[response['media_id']])
elif type == SearchType.celebrity:
photo = open(strFile, 'rb')
response = celebrityFlights.upload_media(media=photo)
os.remove(strFile)
celebrityFlights.update_status(status=status, lat=lat, long=long, media_ids=[response['media_id']])

except TwythonError as error:
if error.error_code == 403: #Duplicate Tweet
return "Duplicate Tweet: Code 403"
else:
return str(error)
except NameError as error:
return "Name Error: Non Twitter Error"
except ValueError as error:
return "Value Error: Non Twitter Error"
else:
return "Sent"

def tweetMilitaryFlightLogs(logs):
tweeted = False
responses = []
if len(logs) > 0:
for flight in logs:
if len(flight.logs) > 2:
Expand Down Expand Up @@ -160,18 +65,18 @@ def tweetMilitaryFlightLogs(logs):
adjustment_lat = -0.5 if list_of_latitudes[0] < list_of_latitudes[1] else 0.5
plt.text(list_of_longitudes[0], list_of_latitudes[0] + adjustment_lat, 'Start', horizontalalignment='center', transform=ccrs.Geodetic())
if os.path.exists(strFile):
print(string_status)
os.remove(strFile) # Opt.: os.system("rm "+strFile)
plt.show()
plt.savefig(strFile,bbox_inches='tight')
plt.clf() # Clear Buffer
else:
print(string_status)
plt.savefig(strFile,bbox_inches='tight')
plt.show()
plt.clf() # Clear Buffer
temp_response = sendTweet(string_status, SearchType.military, last_latitude, last_longitude)
responses = addResponse(responses, temp_response)
if temp_response == "Sent":
tweeted = True

return tweeted, responses
return

def tweetBlockedFlightLogs(logs):
tweeted = False
Expand Down
Binary file modified FlightBots/Helpers/__pycache__/FlightData.cpython-39.pyc
Binary file not shown.
Binary file modified FlightBots/Helpers/__pycache__/Tweet.cpython-39.pyc
Binary file not shown.
31 changes: 15 additions & 16 deletions FlightBots/Templates/SearchFilter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Kyle R Fogerty
import csv
from enum import Enum
import geopy

class SearchType(Enum):
military = 0
Expand All @@ -9,25 +10,23 @@ class SearchType(Enum):
celebrity = 3

class SearchFilter:
def checkDistance(self, coords_1, flightlog, distance):
return True if geopy.distance.vincenty(coords_1, flightlog.coordinates).km < distance else False

#Check Single Flight Log For Military Attributes
def checkSingleMilitaryFlightLog(self, flight_log):
def checkSingleMilitaryFlightLog(self, flight_log, main_coords, distance):
if flight_log.comments != None and flight_log.airline_name != None and flight_log.lastLogLengthVsNow() == True: #Check For none fields
lowercase_comments = flight_log.comments.lower()
lowercase_airline_name = flight_log.airline_name.lower()
keywords = ["force", "army","navy","unit ","squadron","special","military"] #Keywords used to located miltary aircraft
for keyword in range(0, len(keywords)):
if keywords[keyword] in lowercase_comments or keywords[keyword] in lowercase_airline_name:
flight_log.setMilitaryInfo()
return flight_log #Returns with true
if self.checkDistance(main_coords, flight_log, distance) == True:
for keyword in range(0, len(keywords)):
if keywords[keyword] in lowercase_comments or keywords[keyword] in lowercase_airline_name:
flight_log.setMilitaryInfo()
return flight_log #Returns with true
return flight_log

#Check Single Flight Log for Blocked Attributes
def checkSingleFlightLogBlocked(self, flight_log):
if flight_log.lastLogLengthVsNow() == True: #Check if updated
if "blocked" in flight_log.flight.aircraft_code.lower() or "blocked" in flight_log.flight.callsign.lower():
flight_log.setBlockedInfo()
return flight_log #Returns True, in filter
return flight_log #Returns False, not in filter



def checkSingleFlightLogBillionaire(self, flight_log):
Expand Down Expand Up @@ -55,11 +54,11 @@ def checkSingleFlightLogCelebrity(self, flight_log):
csvfile.close()
return flight_log #Returns False, not in filter

def checkAllFlightLogs(self, flight_logs):
def checkAllFlightLogs(self, flight_logs, main_coords, distance):
keywords_found = [] #Flight Logs Containing Keywords
for flight in flight_logs:
if self.searchType == SearchType.military:
new_log = self.checkSingleMilitaryFlightLog(flight)
new_log = self.checkSingleMilitaryFlightLog(flight, main_coords, distance)
if new_log.military_jet == True:
keywords_found.append(new_log)
elif self.searchType == SearchType.blocked:
Expand All @@ -77,8 +76,8 @@ def checkAllFlightLogs(self, flight_logs):

return keywords_found #Return List of Flights Containing Keywords

def searchWithFilters(self, logs):
self.filtered_flights = self.checkAllFlightLogs(logs)
def searchWithFilters(self, logs, main_coords, distance):
self.filtered_flights = self.checkAllFlightLogs(logs, main_coords, distance)
return False if len(self.filtered_flights) == 0 else True

def setTiming(self, offset, sleep_timer):
Expand Down
Binary file modified FlightBots/Templates/__pycache__/FlightLog.cpython-39.pyc
Binary file not shown.
Binary file modified FlightBots/Templates/__pycache__/SearchFilter.cpython-39.pyc
Binary file not shown.
Binary file modified FlightBots/__pycache__/FlightCommander.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions Run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#Kyle R Fogerty
#Run
from BotCommander.Commander import BotCommander
Expand Down

0 comments on commit 1c6a864

Please sign in to comment.