If your flight tables are in the same datastore as the county layer, it should be doable with a popup. I wouldn't do it, though, because it is quite complex, it would be lots of work converting your Python code to Arcade and the Arcade code wouldn't be very maintainable.
If you want to look into it, these would be starting points:
In your case, I would create a Python toolbox. This way, you can use your existing code, and it's not too much extra work for your users.
The only problem is that you can't display clickable HTML links in the tool messages. Possible workaround: Modify your existing code, so that it builds an HTML document and then open that document in the user's default browser.
# Toolbox.pyt
# File can be created from ArcGIS Pro Catalog
import arcpy
import os
import webbrowser
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = ""
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
# optional parameter, where your users can select a county from a list
params = [
arcpy.Parameter(name="county", displayName="County", datatype="GPString", parameterType="Optional", direction="Input"),
]
params[0].filter.list = [row[0] for row in arcpy.da.SearchCursor("CountyFeatureclass", ["CountyNameField"])]
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
if not parameters[0].value:
parameters[0].setWarningMessage("If you don't select a county from this list, you have to select one in the map!")
def execute(self, parameters, messages):
# get county from user input
county = parameters[0].value
if not county:
# user didn't choose from the dropdown list
# search layer for selection
county_layer = arcpy.mp.ArcGISProject("current").activeMap.listLayers("CountyLayerName")[0]
selection = county_layer.getSelectionSet()
if len(selection) == 0:
# user didn't select a county -> error
arcpy.AddError("You have to select a county!")
if len(selection) > 1:
# user selected multiple counties
# here, I just print a warning and then pick the first one
# you could handle this differently
arcpy.AddWarning("Multiple counties selected, only one will be used!")
county = [row[0] for row in arcpy.da.SearchCursor(county_layer, ["CountyNameField"])][0]
arcpy.AddMessage("Selected county: {}".format(county))
# either call your code or paste it here
pass
# build an HTML file in the user's home directory
html_file = os.path.join(os.path.expanduser("~"), "flight_connections.html")
with open(html_file, "w") as f:
f.write("<html>\n")
# ...
f.write("</html>")
# open the HTML file
webbrowser.open(html_file)
Starting points:
Have a great day!
Johannes