예제 #1
0
def loglogmonth(conn, fromdate):  #Log a month of logs
    year, month, *rest = fromdate.split('-', 2)
    print("Sending request for logs from " + month + "-" + year + "...")
    logs = fseutils.fserequest_new('flightlogs', 'monthyear', 'FlightLog',
                                   'xml', 1, 1,
                                   '&month=' + month + '&year=' + year)
    if logs != []:
        c = getlogdbcon(conn)
        rows = []
        fields = (("Id", 1), ("Type", 0), ("Time", 0), ("Distance", 1),
                  ("SerialNumber", 1), ("Aircraft", 0), ("MakeModel", 0),
                  ("From", 0), ("To", 0), ("FlightTime", 0), ("Income", 2),
                  ("PilotFee", 2), ("CrewCost", 2), ("BookingFee", 2),
                  ("Bonus", 2), ("FuelCost", 2), ("GCF", 2), ("RentalPrice",
                                                              2),
                  ("RentalType", 0), ("RentalUnits", 0), ("RentalCost", 2))
        print("Recording data...")
        for log in logs:
            row = fseutils.getbtns(log, fields)
            row[2] = row[2].replace('/', '-')
            rows.append(tuple(row))
        c.execute('BEGIN TRANSACTION')
        c.executemany(
            'INSERT INTO logs VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
            rows)
        conn.commit()
    else:
        print("Got no data!")
예제 #2
0
def getshops(icao):
	services=fseutils.fserequest_new('icao','fbo','FBO','xml',1,1,'&icao='+icao)
	options=[]
	if len(services)>0:
		for opt in services:
			thisfbo=fseutils.getbtns(opt, [("Status", 0), ("RepairShop", 0)])
			if thisfbo==["Active", "Yes"]:
				options.append(tuple(fseutils.getbtns(opt, [("Name", 0), ("Owner", 0)])))
	return options
예제 #3
0
def getshops(icao):
    services = fseutils.fserequest_new('icao', 'fbo', 'FBO', 'xml', 1, 1,
                                       '&icao=' + icao)
    options = []
    if len(services) > 0:
        for opt in services:
            thisfbo = fseutils.getbtns(opt, [("Status", 0), ("RepairShop", 0)])
            if thisfbo == ["Active", "Yes"]:
                options.append(
                    tuple(fseutils.getbtns(opt, [("Name", 0), ("Owner", 0)])))
    return options
예제 #4
0
def getcommo(ctype): # Adds up locations and quantities of stuff to send to the mapper
	if ctype=="fuel":
		t1="JetA Fuel"
		t2="100LL Fuel"
	elif ctype=="mtrl":
		t1="Supplies"
		t2="Building materials"
	else:
		print("Commodity type "+ctype+" not recognized!")
	if t1 is not None:
		print("Sending request for commodities...")
		commo = fseutils.fserequest_new('commodities','key','Commodity','xml',1,1)
		print("Sorting results...")
		stuff = []
		for item in commo: #Parse commodity info
			typ = fseutils.gebtn(item, "Type")
			if typ==t1 or typ==t2:
				loc = fseutils.gebtn(item, "Location")
				amt = fseutils.gebtn(item, "Amount")
				stuff.append((loc,typ,amt))
		if stuff!=[]: #Add up quantity per location
			qty=[] #List to hold quantities and types
			for item in stuff:
				match=-1
				i=-1
				for prev in qty:
					i+=1
					if item[0]==qty[0]: #Test if the location has already been added
						match=1
						break
				if match==-1: #If location not added, then add new location/quantity
					if item[1]==t1:
						idx=0
					else: #t2
						idx=1
					qty.append([item[0],int(item[2].split()[0]),idx])
				else: #If location already added, then sum with other quantity
					qty[i][1]+=item[2].split()
					qty[i][2]=2 #Indicates a mix of t1 and t2
			coords,cmin,cmax=fseutils.getcoords(i[0] for i in qty)
			if len(coords)==len(qty): #If not, there was some key error I guess
				locations=[]
				print("Working with "+str(len(coords))+" coords...")
				for i in range(len(coords)):
					print("Apending "+str(coords[i][0])+","+str(coords[i][1])+","+str(qty[i][1])+","+str(qty[i][2]))
					locations.append([coords[i][0],coords[i][1],qty[i][1],qty[i][2]])
				return locations,cmin,cmax
		else:
			print("No "+ctype+" found!")
예제 #5
0
def request_throttle(qry, srch, tagname, ra, more=""):
    global requests
    now = int(time.time())
    total = len(requests)
    if total > 9:  #Be conservative here...
        sinceten = now - requests[total - 11]
        if sinceten < 60:
            towait = 90 - sinceten  #...because server is evidently dumb
            print("Reaching 10 requests/min limit, sleeping " + str(towait) +
                  " secs.")
            printsleep(towait)
            print(
                'Hopefully we have appeased the rate limiter gods, resuming requests now...'
            )
    requests.append(now)
    tags = fseutils.fserequest_new(qry, srch, tagname, 'xml', ra, 1, more)
    return tags
예제 #6
0
def logpaymonth(conn,fromdate): #Log a month of payments
	year,month,*rest=fromdate.split('-', 2)
	print("Sending request for payment listing...")
	payments = fseutils.fserequest_new('payments','monthyear','Payment','xml',1,1,'&month='+month+'&year='+year)
	if payments!=[]:
		c=getpaydbcon(conn)
		rows=[]
		fields=(("Date", 0), ("To", 0), ("From", 0), ("Amount", 2), ("Reason", 0), ("Location", 0), ("Fbo", 0), ("Aircraft", 0), ("Id", 1),  ("Comment", 0))
		print("Recording data...")
		for payment in payments:
			row=fseutils.getbtns(payment,fields)
			if row[8]=="null":
				row[8]=""
			row[0]=row[0].replace('/','-')
			rows.append(tuple(row))
		c.execute('BEGIN TRANSACTION')
		c.executemany('INSERT INTO payments VALUES (?,?,?,?,?,?,?,?,?,?)',rows)
		conn.commit()
예제 #7
0
			for current in needfixes:
				#print("Writing "+current[0]+" to file")
				f.write(current[0]+"\n")
		#print("Will remove oldnews from needfixes list:")
		#print(needfixes)
		for oldie in oldnews: #Remove aircraft already notified from the list
			#print("Removing "+oldie[0]+" from notify list")
			needfixes.remove(oldie)
	except IOError:
		print("Could not open file: "+str(file))
	return needfixes

ns = {'sfn': 'http://server.fseconomy.net'} #namespace for XML stuff
aog=[] #List of planes and FBO options
print("Sending request for aircraft list...")
airplanes = fseutils.fserequest_new('aircraft','key','Aircraft','xml',1,1)
print("Received airplane list:")
print(airplanes)
for plane in airplanes:
	nr=int(plane.find('sfn:NeedsRepair',ns).text) #Indications repair is needed
	since100=int(plane.find('sfn:TimeLast100hr',ns).text.split(":")[0])
	mx=0
	print("Repair: "+str(nr)+"  100hr: "+str(since100))
	if nr>0:
		mx=1
	if since100>99: #100 hr past due
		mx=2
	if mx>0: #Something is broken
		row=fseutils.getbtns(plane, [("Registration", 0), ("MakeModel", 0), ("Location", 0)]) #License and registration please
		print("Finding repair options for "+row[0])
		shops=getshops(row[2]) #Get list of shops here
예제 #8
0
                #print("Writing "+current[0]+" to file")
                f.write(current[0] + "\n")
        #print("Will remove oldnews from needfixes list:")
        #print(needfixes)
        for oldie in oldnews:  #Remove aircraft already notified from the list
            #print("Removing "+oldie[0]+" from notify list")
            needfixes.remove(oldie)
    except IOError:
        print("Could not open file: " + str(filename))
    return needfixes


ns = {'sfn': 'http://server.fseconomy.net'}  #namespace for XML stuff
aog = []  #List of planes and FBO options
print("Sending request for aircraft list...")
airplanes = fseutils.fserequest_new('aircraft', 'key', 'Aircraft', 'xml', 1, 1)
print("Received airplane list:")
print(airplanes)
for plane in airplanes:
    nr = int(plane.find('sfn:NeedsRepair',
                        ns).text)  #Indications repair is needed
    since100 = int(plane.find('sfn:TimeLast100hr', ns).text.split(":")[0])
    mx = 0
    print("Repair: " + str(nr) + "  100hr: " + str(since100))
    if nr > 0:
        mx = 1
    if since100 > 99:  #100 hr past due
        mx = 2
    if mx > 0:  #Something is broken
        row = fseutils.getbtns(
            plane, [("Registration", 0), ("MakeModel", 0),
예제 #9
0
#!/usr/bin/python3
import fseutils # My custom FSE functions
from pathlib import Path
from appdirs import AppDirs

cautdays = 14 #Days of supplies to first send first notification
cautjeta = 1000 #Gallons of Jet A to first send first notification
caut100ll = 1000 #Gallons of 100LL to first send first notification
warndays = 0 #Second notifications
warnjeta = 0
warn100ll = 0
print("Sending request for FBO list...")
commo = fseutils.fserequest_new('fbos','key','FBO','xml',2,0)
#print(commo)
lowjeta = []
low100ll = []
lowsupp = []
nojeta = []
no100ll = []
nosupp = []
for fbo in commo: #Parse commodity info
	#print(fbo)
	icao = fseutils.gebtn(fbo,"Icao",0)
	#print("ICAO="+icao)
	f100 = int(fseutils.gebtn(fbo,"Fuel100LL",0))
	#print("f100="+str(f100))
	fja = int(fseutils.gebtn(fbo,"FuelJetA",0))
	#print("fja="+str(fja))
	days = int(fseutils.gebtn(fbo,"SuppliedDays",0))
	#print("days="+str(days))
	if fja<1:
예제 #10
0
#!/usr/bin/python3
import fseutils # My custom FSE functions

ns = {'sfn': 'http://server.fseconomy.net'} #namespace for XML stuff
print("Sending request for alias listing...")
#aliases = fserequest(0,'query=aircraft&search=aliases','sfn:AircraftAliases','xml',ns)
aliases = fseutils.fserequest_new('aircraft','aliases','AircraftAliases','xml',0,1)
print("Sending request for configs...")
#configs = fserequest(1,'query=aircraft&search=configs','sfn:AircraftConfig','xml',ns)
configs = fseutils.fserequest_new('aircraft','configs','AircraftConfig','xml',1,1)
if configs!=[] and aliases!=[]:
	payloads=[] #Holds payload calculations
	print("Processing data...")
	#cfields=(("sfn:MakeModel", 0), ("sfn:MTOW", 1), ("sfn:EmptyWeight", 1))
	cfields=(("MakeModel", 0), ("MTOW", 1), ("EmptyWeight", 1))
	aliaslist=[] #holds list of list of aliases
	i=0 #To store which alias we are adding to
	print("Getting payloads...")
	for config in configs: #Calculate payloads
		#thisac=getbtns(config, cfields, ns)
		thisac=fseutils.getbtns(config, cfields)
		payload=thisac[1]-thisac[2]
		#print(thisac[0],payload)
		payloads.append((thisac[0], payload)) #Store the name and payload
	print("Getting aliases...")
	for model in aliases: #List the aliases
		themake=model.find('sfn:MakeModel',ns).text #Get the make/model
		if themake==payloads[i][0]: #Test if this matches the corresponding payload plane
			print("Appending list for "+themake)
			aliaslist.append([]) #Start a new list of aliases
			for alias in model.findall('sfn:Alias',ns):
예제 #11
0
#!/usr/bin/python3
import fseutils  # My custom FSE functions
from pathlib import Path
from appdirs import AppDirs

cautdays = 14  #Days of supplies to first send first notification
cautjeta = 1000  #Gallons of Jet A to first send first notification
caut100ll = 1000  #Gallons of 100LL to first send first notification
warndays = 0  #Second notifications
warnjeta = 0
warn100ll = 0
print("Sending request for FBO list...")
commo = fseutils.fserequest_new('fbos', 'key', 'FBO', 'xml', 2, 0)
#print(commo)
lowjeta = []
low100ll = []
lowsupp = []
nojeta = []
no100ll = []
nosupp = []
for fbo in commo:  #Parse commodity info
    #print(fbo)
    icao = fseutils.gebtn(fbo, "Icao", 0)
    #print("ICAO="+icao)
    f100 = int(fseutils.gebtn(fbo, "Fuel100LL", 0))
    #print("f100="+str(f100))
    fja = int(fseutils.gebtn(fbo, "FuelJetA", 0))
    #print("fja="+str(fja))
    days = int(fseutils.gebtn(fbo, "SuppliedDays", 0))
    #print("days="+str(days))
    if fja < 1:
예제 #12
0
day=today.day
listofmonths.append(month)
for j in range(daysago):
	history=today - timedelta(j+1)
	listofdays.append(history)
#	print(str(listofdays[j].month)+"/"+str(listofdays[j].day))
	if history.month!=listofmonths[k]:
		listofmonths.append(history.month)
		k+=1
me=fseutils.getname()
ns = {'sfn': 'http://server.fseconomy.net'} #namespace for XML stuff
plogs=[]
firstrqtime=int(time.time())
print("Sending request for aircraft list...")
requests+=1
airplanes = fseutils.fserequest_new('aircraft','key','Aircraft','xml',1,1)
#print(airplanes)
print("Processing list...")
for plane in airplanes:
	thisac=fseutils.getbtns(plane, [("Registration", 0), ("MakeModel", 0), ("SerialNumber", 0)])
	plogs.append((thisac[0],[]))
	for eachmonth in listofmonths:
		if requests>8:
			printsleep(120)
			requests=0
		print("Sending request for "+thisac[0]+" ("+thisac[2]+") logs for "+str(eachmonth)+"/"+str(year)+"...")
		requests+=1
		logs=fseutils.fserequest_new('flightlogs','monthyear','FlightLog','xml',0,1,'&serialnumber='+thisac[2]+'&month='+str(month)+'&year='+str(year))
		print("Processing "+str(len(logs))+" logs...")
		for flt in logs:
			fltime = flt.find('sfn:Time', ns).text
예제 #13
0
day = today.day
listofmonths.append(month)
for j in range(daysago):
    history = today - timedelta(j + 1)
    listofdays.append(history)
    #	print(str(listofdays[j].month)+"/"+str(listofdays[j].day))
    if history.month != listofmonths[k]:
        listofmonths.append(history.month)
        k += 1
me = fseutils.getname()
ns = {'sfn': 'http://server.fseconomy.net'}  #namespace for XML stuff
plogs = []
firstrqtime = int(time.time())
print("Sending request for aircraft list...")
requests += 1
airplanes = fseutils.fserequest_new('aircraft', 'key', 'Aircraft', 'xml', 1, 1)
#print(airplanes)
print("Processing list...")
for plane in airplanes:
    thisac = fseutils.getbtns(plane, [("Registration", 0), ("MakeModel", 0),
                                      ("SerialNumber", 0)])
    plogs.append((thisac[0], []))
    for eachmonth in listofmonths:
        if requests > 8:
            printsleep(120)
            requests = 0
        print("Sending request for " + thisac[0] + " (" + thisac[2] +
              ") logs for " + str(eachmonth) + "/" + str(year) + "...")
        requests += 1
        logs = fseutils.fserequest_new(
            'flightlogs', 'monthyear', 'FlightLog', 'xml', 0, 1,