Skip to content

Commit 7916ad3

Browse files
authored
Merge pull request #98 from ipinfo/haris/remove_json_files
Moving from JSON files to in memory data structures
2 parents 5236852 + 9f82db4 commit 7916ad3

File tree

12 files changed

+1121
-847
lines changed

12 files changed

+1121
-847
lines changed

README.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,61 @@ You can add custom headers or modify default headers by setting the `headers` ke
240240

241241
### Internationalization
242242

243-
When looking up an IP address, the response object includes `details.country_name`, `details.isEU`, `details.country_flag`, `details.country_flag_url` and `details.country_currency` attributes which includes the country based on American English. It is possible to return the country name in other languages by setting the `countries_file`, remove or add EU countries by setting the keyword argument `eu_countries_file`, change the country flag emoji or unicode by setting the keyword argument `countries_flags_file` or change country's currency code or currency symbol by setting the `countries_currencies` when creating the `IPinfo` object. Moreover, the response object includes a `details.continent` which includes continent code and name of IP. The default file can be changed by setting the `continent_file` while creating the `IPinfo` object.
243+
When looking up an IP address, the response object includes `details.country_name`, `details.isEU`, `details.country_flag`, `details.country_flag_url` and `details.country_currency` attributes which includes the country based on American English. It is possible to return the country name in other languages by setting the `countries`, remove or add EU countries by setting the keyword argument `eu_countries`, change the country flag emoji or unicode by setting the keyword argument `countries_flags` or change country's currency code or currency symbol by setting the `countries_currencies` when creating the `IPinfo` object. Moreover, the response object includes a `details.continent` which includes continent code and name of IP. The default file can be changed by setting the `continent` while creating the `IPinfo` object.
244244

245-
The file must be a `.json` file with the following structure:
245+
```python
246+
>>> import ipinfo
247+
# Country Names: In-memory map
248+
>>> countries = {
249+
"BD": "Bangladesh",
250+
"BE": "Belgium",
251+
"BF": "Burkina Faso",
252+
...
253+
}
246254

247-
```json
248-
{
249-
"BD": {"name":"Bangladesh", "isEU":false},
250-
"BE": {"name":"Belgium", "isEU":true},
251-
"BF": {"name":"Burkina Faso", "isEU":false},
252-
"BG": {"name":"Bulgaria", "isEU":true},
253-
...
255+
# EU Countries: In-memory list
256+
>>> eu_countries = [
257+
"IE",
258+
"AT",
259+
"LT",
260+
...
261+
]
262+
263+
# Country Flags: In-memory map
264+
>>> countries_flags = {
265+
"AD": {"emoji": "🇦🇩", "unicode": "U+1F1E6 U+1F1E9"},
266+
"AE": {"emoji": "🇦🇪", "unicode": "U+1F1E6 U+1F1EA"},
267+
"AF": {"emoji": "🇦🇫", "unicode": "U+1F1E6 U+1F1EB"},
268+
...
254269
}
255-
```
256270

271+
# Country Currencies: In-memory map
272+
>>> countries_currencies = {
273+
"AD": {"code": "EUR", "symbol": ""},
274+
"AE": {"code": "AED", "symbol": "د.إ"},
275+
"AF": {"code": "AFN", "symbol": "؋"},
276+
...
277+
}
278+
279+
# Continents: In-memory map
280+
>>> continents = {
281+
"BD": {"code": "AS", "name": "Asia"},
282+
"BE": {"code": "EU", "name": "Europe"},
283+
"BF": {"code": "AF", "name": "Africa"},
284+
...
285+
}
286+
287+
# create handler
288+
>>> access_token = '123456789abc'
289+
>>> handler = ipinfo.getHandler(
290+
access_token,
291+
countries=countries,
292+
eu_countries=eu_countries,
293+
countries_flags=countries_flags,
294+
countries_currencies=countries_currencies,
295+
continents=continents
296+
)
297+
```
257298
### Batch Operations
258299

259300
Looking up a single IP at a time can be slow. It could be done concurrently

ipinfo/continent.json

Lines changed: 0 additions & 253 deletions
This file was deleted.

ipinfo/countries.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)