Skip to content

Commit

Permalink
Merge pull request #98 from ipinfo/haris/remove_json_files
Browse files Browse the repository at this point in the history
Moving from JSON files to in memory data structures
  • Loading branch information
UmanShahzad authored Nov 23, 2023
2 parents 5236852 + 9f82db4 commit 7916ad3
Show file tree
Hide file tree
Showing 12 changed files with 1,121 additions and 847 deletions.
61 changes: 51 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,61 @@ You can add custom headers or modify default headers by setting the `headers` ke

### Internationalization

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.
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.

The file must be a `.json` file with the following structure:
```python
>>> import ipinfo
# Country Names: In-memory map
>>> countries = {
"BD": "Bangladesh",
"BE": "Belgium",
"BF": "Burkina Faso",
...
}

```json
{
"BD": {"name":"Bangladesh", "isEU":false},
"BE": {"name":"Belgium", "isEU":true},
"BF": {"name":"Burkina Faso", "isEU":false},
"BG": {"name":"Bulgaria", "isEU":true},
...
# EU Countries: In-memory list
>>> eu_countries = [
"IE",
"AT",
"LT",
...
]

# Country Flags: In-memory map
>>> countries_flags = {
"AD": {"emoji": "🇦🇩", "unicode": "U+1F1E6 U+1F1E9"},
"AE": {"emoji": "🇦🇪", "unicode": "U+1F1E6 U+1F1EA"},
"AF": {"emoji": "🇦🇫", "unicode": "U+1F1E6 U+1F1EB"},
...
}
```

# Country Currencies: In-memory map
>>> countries_currencies = {
"AD": {"code": "EUR", "symbol": ""},
"AE": {"code": "AED", "symbol": "د.إ"},
"AF": {"code": "AFN", "symbol": "؋"},
...
}

# Continents: In-memory map
>>> continents = {
"BD": {"code": "AS", "name": "Asia"},
"BE": {"code": "EU", "name": "Europe"},
"BF": {"code": "AF", "name": "Africa"},
...
}

# create handler
>>> access_token = '123456789abc'
>>> handler = ipinfo.getHandler(
access_token,
countries=countries,
eu_countries=eu_countries,
countries_flags=countries_flags,
countries_currencies=countries_currencies,
continents=continents
)
```
### Batch Operations

Looking up a single IP at a time can be slow. It could be done concurrently
Expand Down
253 changes: 0 additions & 253 deletions ipinfo/continent.json

This file was deleted.

1 change: 0 additions & 1 deletion ipinfo/countries.json

This file was deleted.

Loading

0 comments on commit 7916ad3

Please sign in to comment.