Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add country data to display of service nodes. #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ianmacd
Copy link
Contributor

@ianmacd ianmacd commented Jun 28, 2022

To enable:

$ sudo apt install python3-geoip2  # or: 'pip install geoip2' for the latest
$ sudo apt install geoipupdate

If necessary, sign up for an account with MaxMind:

https://www.maxmind.com/en/geolite2/signup

Edit /etc/GeoIP.conf with the details of your MaxMind account:

AccountID 123456
LicenseKey xxxxxxxxxxxxxxxx
EditionIDs GeoLite2-City GeoLite2-ASN

Edit /etc/cron.d/geoipupdate:

 # MaxMind database updates take place on Tuesdays and Fridays.
 #
00 12    * * 2,5   root    test -x /usr/bin/geoipupdate && grep -q '^AccountID .*[^0]\+' /etc/GeoIP.conf && /usr/bin/geoipupdate

Edit ./local_config.py:

config.geoip_dir = '/var/lib/GeoIP'

Main page:

image

Service node detail page:

image

@ianmacd ianmacd force-pushed the country-detail branch 2 times, most recently from d591ea7 to 7bc6123 Compare June 29, 2022 17:59
To enable:

```
$ sudo apt install python3-geoip2  # or: 'pip install geoip2' for the latest
$ sudo apt install geoipupdate
```

If necessary, sign up for an account with MaxMind:

  https://www.maxmind.com/en/geolite2/signup

Edit `/etc/GeoIP.conf` with the details of your MaxMind account:

```
AccountID 123456
LicenseKey xxxxxxxxxxxxxxxx
EditionIDs GeoLite2-City GeoLite2-ASN
```

Edit `/etc/cron.d/geoipupdate`:

```
 # MaxMind database updates take place on Tuesdays and Fridays.
 #
00 12    * * 2,5   root    test -x /usr/bin/geoipupdate && grep -q '^AccountID .*[^0]\+' /etc/GeoIP.conf && /usr/bin/geoipupdate
```

Edit `./local_config.py`:

```
config.geoip_dir = '/var/lib/GeoIP'
```
Flag images are sourced from here:

  https://flaglog.com/country-codes

Placing the flags in a subdirectory of `./static` for good housekeeping
requires a change to the location matching of the `nginx` configuration;
otherwise they will not be found.

Change:

```
location ~ /(?![^/]*\.(?:css|js|png|html)(?:$|\?)) {
```

to:

```
location ~ /(?!([^/]*|flags/[^/]*)\.(?:css|js|png|html)(?:$|\?)) {
```
@ianmacd
Copy link
Contributor Author

ianmacd commented Jun 30, 2022

The code has been rebased and country flags added to the display:

image

@majestrate
Copy link
Contributor

suggestion, also provide systemd timer for updating geoip db.

@jagerman
Copy link
Member

jagerman commented Jul 14, 2022

This would be a lot simpler if it used unicode flag sequences instead of needing to serve all the PNGs. These are pretty simple to construct -- you just write the two-letter country code using regional letter sequences instead of normal letters, and it gets rendered as a flag:

regional_indicators = {'a': '🇦', 'b': '🇧', 'c': '🇨', 'd': '🇩', 'e': '🇪', 'f': '🇫', 'g': '🇬', 'h': '🇭', 'i': '🇮', 'j': '🇯', 'k': '🇰', 'l': '🇱', 'm': '🇲', 'n': '🇳', 'o': '🇴', 'p': '🇵', 'q': '🇶', 'r': '🇷', 's': '🇸', 't': '🇹', 'u': '🇺', 'v': '🇻', 'w': '🇼', 'x': '🇽', 'y': '🇾', 'z': '🇿'}

# Or if you prefer, something like:
regional_indicators = { chr(ord('a') + i): chr(ord('🇦') + i) for i in range(0, 26) }

def flag(cc):
    return ''.join(regional_indicators[c] for c in cc)
>>> flag('ca')
'🇨🇦'

@ianmacd
Copy link
Contributor Author

ianmacd commented Jul 14, 2022

This would be a lot simpler if it used unicode flag sequences instead of needing to serve all the PNGs.

That would have been the obvious way to do it, were it not that Windows 10/11 won't render flag characters by design:

https://answers.microsoft.com/en-us/windows/forum/all/flag-emoji/85b163bc-786a-4918-9042-763ccf4b6c05

@ianmacd
Copy link
Contributor Author

ianmacd commented Jul 24, 2022

A much better explanation of the problems with flag emoji can be found here:

https://blog.emojipedia.org/emoji-flags-explained/

@ianmacd
Copy link
Contributor Author

ianmacd commented Jul 24, 2022

>>> flag('ca')
'🇨🇦'

I just noticed that this code doesn't even do the right thing for me on Linux, so I'm curious which combination of terminal and font assortment you are using.

This is what I see with rxvt-unicode:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants