Skip to content

Commit

Permalink
Add ICAO code to searchable fields (#2)
Browse files Browse the repository at this point in the history
* Update airports.py

* Update version

* Update info.plist

* Update README.md
  • Loading branch information
otherguy authored Aug 30, 2017
1 parent da21677 commit 5b3875e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ When holding down a modifier key, the action can be specified:
| `ctrl` | Open the Wikipedia page of the selected airport. |
| `` | Show the airports location in Maps.app |

Since version `0.1.4`, you can search for ICAO codes as well!

## Developers

If you want to contribute, fork this repository and submit a pull request.
Expand Down
15 changes: 8 additions & 7 deletions airports.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_web_data():
airport_city = row['municipality'].strip()
airport_url = row['home_link'].strip()
airport_wiki = row['wikipedia_link'].strip()
airport_icao = row['ident'].upper().strip()

# Add a '.' after single uppercase letters
airport_name = re.sub( r"\b([A-Z])(?![\w\-\.])", r"\1.", airport_name)
Expand All @@ -57,18 +58,18 @@ def get_web_data():
airport_country = country

# Build our airport object.
airports.append( Map( id = airport_id, iata_code = iata_code, type = airport_type,
name = airport_name, coords = airport_coords, country = airport_country,
city = airport_city, url = airport_url, wiki = airport_wiki ) )
airports.append( Map( id = airport_id, iata_code = iata_code, icao_code = airport_icao,
type = airport_type, name = airport_name, coords = airport_coords,
country = airport_country, city = airport_city, url = airport_url, wiki = airport_wiki ) )

# Sort the list by airport_type. Snce it's only 'Large', 'Medium' and 'Small', they should be sorted correctly.
airports = sorted(airports, key=lambda k: k.type)

airports = sorted(airports, key=lambda k: (k.type, k.iata_code))
return airports

# Build a search key given an airport object.
def key_for_airports(airport):
return '{},{},{},{}'.format(unidecode(airport.iata_code), unidecode(airport.name), unidecode(airport.country), unidecode(airport.city))
searchkey = '{},{},{},{},{}'.format(unidecode(airport.iata_code), unidecode(airport.name), unidecode(airport.icao_code), unidecode(airport.country), unidecode(airport.city))
return searchkey

# ==========================================================================
# ================================= MAIN ===================================
Expand Down Expand Up @@ -107,7 +108,7 @@ def key_for_airports(airport):
for airport, score, wffilter in filtered_airports:

title = '(%s) %s' % (airport.iata_code, airport.name)
subtitle = ('%s, %s' % (airport.city, airport.country)) if airport.city != '' else airport.country
subtitle = airport.icao_code + ' ' + ('(%s, %s)' % (airport.city, airport.country)) if airport.city != '' else airport.country

item = wf.add_item( title, subtitle,
autocomplete=airport.iata_code,
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
</dict>
</dict>
<key>version</key>
<string>0.1.2</string>
<string>0.1.4</string>
<key>webaddress</key>
<string>https://github.com/darkwinternight/alfred-airports-workflow</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.3
0.1.4

0 comments on commit 5b3875e

Please sign in to comment.