Skip to content

Commit 4b11f65

Browse files
author
Kevin Le
committed
temporary mappings
1 parent 55e9ca7 commit 4b11f65

File tree

5 files changed

+141
-7
lines changed

5 files changed

+141
-7
lines changed

README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Smartraveller API
22

3-
A simple API for travel advisories published by the Australian Government on [Smartraveller](https://www.smartraveller.gov.au/).
3+
A simple API for travel advisories published by the Australian Government DFAT on [Smartraveller](https://www.smartraveller.gov.au/).
44

55
**This is not an official API. Visit the Smartraveller website for the latest information.**
66

@@ -22,7 +22,7 @@ Note: Set Vercel function region to `Sydney, Australia (Southeast) - syd1` as re
2222

2323
## Endpoint(s)
2424

25-
### [GET /advisory](https://smartraveller.api.kevle.xyz/advisory?country=es)
25+
### [GET /advisory](https://smartraveller.api.kevle.xyz/advisory)
2626

2727
Fetches an advice summary for a country.
2828

@@ -31,10 +31,12 @@ Responses may be cached for up to 1 hour.
3131
#### Query Parameters
3232

3333
- country (required)
34-
- Note: Fuzzy matches for country - E.g. "Spain" or "ES" is accepted. However it is recommend to use Alpha 3 country codes.
34+
- Note: Fuzzy matches for country - E.g. "Spain" or "ES" is accepted. However it is recommend to use [ISO 3166-1 alpha-2 country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
3535

3636
#### Example Response
3737

38+
https://smartraveller.api.kevle.xyz/advisory?country=es
39+
3840
```
3941
{
4042
"advisory": "Exercise normal safety precautions",
@@ -45,6 +47,14 @@ Responses may be cached for up to 1 hour.
4547
}
4648
```
4749

50+
## Known Problems
51+
52+
Smartraveller uses non-standardised and inconsistent names for countries and does not utilise any standard country codes such as the [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) standard.
53+
54+
Mappings for certain countries have been temporarily added, but may be inconsistent.
55+
56+
Need to explore if it is possible to build a mapping programatically using the available ["PublishedPages" API](https://www.smartraveller.gov.au/api/publishedpages).
57+
4858
## Copyright
4959

5060
Smartraveller material accessed is provided under the latest [Creative Commons Attribution licence](https://creativecommons.org/licenses/by/4.0/).

api/api.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ def advisory():
2727

2828
advisory = get_overall_advisory(country_query)
2929

30+
if advisory is None:
31+
return "Smartraveller does not have published advisory for selected country", 404
32+
3033
advisory["country"] = country.name
3134
advisory["alpha_2"] = country.alpha_2
32-
advisory["official_name"] = country.official_name
35+
36+
if hasattr(country, 'official_name'):
37+
advisory["official_name"] = country.official_name
3338

3439
response = Response(json.dumps(advisory))
3540
response.headers['Cache-Control'] = 's-maxage=3600' # Vercel cache for 1 hour

api/smartraveller/advisory.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,41 @@
99
"Do not travel": 4
1010
}
1111

12+
# Smartraveller uses non-standardised names for countries - see README.md
13+
# Temporary permanent solution...
14+
special_mappings = {
15+
"congo": "democratic-republic-congo",
16+
"iran,-islamic-republic-of": "iran",
17+
"israel": "middle-east/israel-and-palestinian-territories",
18+
"kyrgyzstan": "kyrgyz-republic",
19+
"korea,-democratic-people's-republic-of": "north-korea-democratic-peoples-republic-korea",
20+
"taiwan,-province-of-china": "taiwan",
21+
"united-states": "americas/united-states-america",
22+
"viet-nam": "vietnam",
23+
"russian-federation": "russia",
24+
"greenland": "denmark",
25+
"lao-people's-democratic-republic": "laos",
26+
"kyrgyzstan": "kyrgyz-republic"
27+
}
28+
1229
def get_overall_advisory(country: str) -> dict:
13-
response = requests.get(f'https://www.smartraveller.gov.au/destinations/{country}', timeout=2)
30+
if country in special_mappings:
31+
country_query = special_mappings[country]
32+
else:
33+
country_query = country
34+
print(country_query)
35+
36+
response = requests.get(f'https://www.smartraveller.gov.au/destinations/{country_query}', timeout=2)
1437
html = response.content
1538

1639
site = BeautifulSoup(html, 'html.parser')
1740

1841
advisory_block = site.findAll('div', { 'class': 'views-field views-field-field-overall-advice-level'})
42+
print(advisory_block)
43+
44+
if not advisory_block:
45+
return None
46+
1947
advisory = advisory_block[0].find('strong').getText()
2048

2149
return {

missing.txt

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Aruba
2+
Anguilla
3+
�land Islands
4+
Andorra
5+
American Samoa
6+
Antarctica
7+
French Southern Territories
8+
Antigua and Barbuda
9+
Australia
10+
Bonaire, Sint Eustatius and Saba
11+
Saint Barth�lemy
12+
Bermuda
13+
Bolivia, Plurinational State of
14+
Barbados
15+
Bouvet Island
16+
Cocos (Keeling) Islands
17+
C�te d'Ivoire
18+
Congo, The Democratic Republic of the
19+
Comoros
20+
Cabo Verde
21+
Cura�ao
22+
Christmas Island
23+
Cayman Islands
24+
Czechia
25+
Dominica
26+
Western Sahara
27+
Fiji
28+
Falkland Islands (Malvinas)
29+
Faroe Islands
30+
Micronesia, Federated States of
31+
Guernsey
32+
Gibraltar
33+
Guadeloupe
34+
Guinea-Bissau
35+
Equatorial Guinea
36+
Grenada
37+
French Guiana
38+
Heard Island and McDonald Islands
39+
Isle of Man
40+
British Indian Ocean Territory
41+
Jersey
42+
Kyrgyzstan
43+
Kiribati
44+
Saint Kitts and Nevis
45+
Korea, Republic of
46+
Lao People's Democratic Republic
47+
Saint Lucia
48+
Liechtenstein
49+
Luxembourg
50+
Macao
51+
Saint Martin (French part)
52+
Monaco
53+
Moldova, Republic of
54+
Northern Mariana Islands
55+
Montserrat
56+
Martinique
57+
Mayotte
58+
Norfolk Island
59+
Niue
60+
Nauru
61+
Pitcairn
62+
Puerto Rico
63+
Palestine, State of
64+
R�union
65+
South Georgia and the South Sandwich Islands
66+
Saint Helena, Ascension and Tristan da Cunha
67+
Svalbard and Jan Mayen
68+
San Marino
69+
Saint Pierre and Miquelon
70+
Sao Tome and Principe
71+
Suriname
72+
Slovakia
73+
Slovenia
74+
Sint Maarten (Dutch part)
75+
Syrian Arab Republic
76+
Turks and Caicos Islands
77+
Togo
78+
Tokelau
79+
Trinidad and Tobago
80+
Tuvalu
81+
Tanzania, United Republic of
82+
United States Minor Outlying Islands
83+
Holy See (Vatican City State)
84+
Saint Vincent and the Grenadines
85+
Venezuela, Bolivarian Republic of
86+
Virgin Islands, British
87+
Virgin Islands, U.S.
88+
Wallis and Futuna

vercel.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"rewrites": [
3-
{ "source": "/(.*)", "destination": "/api/api" }
3+
{
4+
"source": "/(.*)",
5+
"destination": "/api/api"
6+
}
47
],
58
"regions": [
69
"syd1"
710
]
8-
}
11+
}

0 commit comments

Comments
 (0)