Skip to content

Commit e33ad65

Browse files
committed
Merge remote-tracking branch 'upstream/main'
# Conflicts: # README.md # lib/mix/tasks/update_geoname_data.ex # lib/scraper/scraper.ex # mix.exs # mix.lock
2 parents 6576d4f + 0c3b18a commit e33ad65

26 files changed

Lines changed: 3352 additions & 2207 deletions

.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Used by "mix format"
22
[
3-
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test,mix_tasks}/**/*.{ex,exs}"]
44
]

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "mix"
9+
directory: "/"
10+
schedule:
11+
interval: "daily"
12+
13+
- package-ecosystem: "github-actions"
14+
directory: "/"
15+
schedule:
16+
interval: "daily"

.github/workflows/mix.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: mix
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
MIX_ENV: test
14+
15+
strategy:
16+
matrix:
17+
elixir: [1.15, 1.16]
18+
otp: [25, 26]
19+
include:
20+
- elixir: 1.17
21+
otp: 27
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: erlef/setup-beam@v1
27+
with:
28+
elixir-version: ${{ matrix.elixir }}
29+
otp-version: ${{ matrix.otp }}
30+
31+
- uses: actions/cache@v4
32+
with:
33+
path: |
34+
deps
35+
_build
36+
key: test-${{ matrix.otp }}-${{ matrix.elixir }}-${{ github.head_ref || github.ref }}-${{ hashFiles('**/mix.lock') }}
37+
restore-keys: |
38+
test-${{ matrix.otp }}-${{ matrix.elixir }}-${{ github.head_ref || github.ref }}-
39+
test-${{ matrix.otp }}-${{ matrix.elixir }}-refs/heads/master-
40+
41+
- run: mix deps.get --only $MIX_ENV
42+
# TODO --warnings-as-errors
43+
- run: mix compile
44+
- run: mix test
45+
46+
format:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: erlef/setup-beam@v1
51+
with:
52+
elixir-version: 1
53+
otp-version: 27
54+
- run: elixir -v
55+
- run: mix format --check-formatted

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Location
22

3-
Elixir library for accessing ISO3166-1 (country) and ISO3166-2 (subdivision) data as well as geoname data for cities and postal code data. Source data comes from the upstream [debian iso-codes](https://salsa.debian.org/iso-codes-team/iso-codes) package and the [Geonames](http://www.geonames.org/) project.
4-
5-
3+
Elixir library for accessing ISO3166-1 (country) and ISO3166-2 (subdivision) data as well as geoname data for cities. Source data comes from the upstream [debian iso-codes](https://salsa.debian.org/iso-codes-team/iso-codes) package and the [Geonames](http://www.geonames.org/) project.
64

75
### Countries
86

@@ -11,18 +9,13 @@ manually add some data that is missing from upstream. Overrides can be found in
119

1210
### Subdivisions
1311

14-
The data for subdivisions comes primarily from the [debian iso-codes](https://salsa.debian.org/iso-codes-team/iso-codes) package. The data file for that is stored in `priv/iso_3166-2.json`. The
15-
subdivision names in this file are mostly in local language (i.e. Wien instead of Vienna). English translations are obtained from Wikipedia using a scraper. The translations found in `priv/iso_3166-2.en-translations.json` are used when available instead of the original name.
16-
17-
We also add some data manually that is missing from upstream. Overrides can be found in `priv/override/iso_3166-2.json`
12+
The data for subdivisions comes primarily from the [debian iso-codes](https://salsa.debian.org/iso-codes-team/iso-codes) package. The data file for that is stored in `priv/iso_3166-2.json`. The subdivision names in this file are mostly in local language (i.e. Wien instead of Vienna). English translations are obtained from CLDR and Wikipedia. The translations found in `priv/iso_3166-2.en-translations.json` are used when available instead of the original name.
1813

1914
### Cities
2015

21-
The data for cities comes from the [geonames](http://www.geonames.org/) project. This project has scripts to download the main `allCountries.txt` file or individual country files. If allCountries is chosen is then processed to make it smaller
22-
(from 1.3GB to about 130MB). Still, the resulting file is quite large so we also provide a city database based on the smaller `cities500.txt` file or one choose the --source option.
16+
The data for cities comes from the [geonames](http://www.geonames.org/) project. This project has scripts to download the main `allCountries.txt` file. It is then processed to make it smaller
17+
(from 1.3GB to about 130MB). Still, the resulting file is quite large so we also provide a city database based on the smaller `cities500.txt` file.
2318

2419
### Postal Codes
25-
The data for postal codes comes from the [geonames](http://www.geonames.org/) project. This project has scripts to download all or individual postal code files via the --source option.
2620

27-
#### Postal Code Helpers
28-
Postal codes can be downloaded
21+
The data for postal codes comes from the [geonames](http://www.geonames.org/) project. This project has scripts to download all or individual postal code files via the --source option.

lib/location.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ defmodule Location do
3131
Logger.debug("Loading location database #{inspect(module)} took: #{time}s")
3232
:ok
3333
end
34+
35+
def version() do
36+
version_file = Application.app_dir(:location, "priv/version")
37+
38+
File.read!(version_file)
39+
end
3440
end

lib/location/city.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ defmodule Location.City do
4848
|> Stream.run()
4949
end
5050

51+
def all() do
52+
:ets.tab2list(@ets_table_by_id)
53+
|> Enum.map(fn {id, {name, country_code}} -> to_struct(id, name, country_code) end)
54+
end
55+
5156
@doc """
5257
Finds city by GeoNames ID.
5358
"""

lib/location/subdivision.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ defmodule Location.Subdivision do
1616
:ets.insert(ets, {entry["code"], to_struct(entry)})
1717
end)
1818

19+
File.read!(restore_source_file())
20+
|> Jason.decode!()
21+
|> Enum.each(fn entry ->
22+
entry = translate_entry(translations, entry)
23+
:ets.insert(ets, {entry["code"], to_struct(entry)})
24+
end)
25+
1926
File.read!(override_source_file())
2027
|> Jason.decode!()
2128
|> Enum.each(fn entry ->
2229
:ets.insert(ets, {entry["code"], to_struct(entry)})
2330
end)
2431
end
2532

33+
def all() do
34+
:ets.tab2list(@ets_table)
35+
|> Enum.map(fn {_, entry} -> entry end)
36+
end
37+
2638
def search_subdivision(search_phrase) do
2739
search_phrase = String.downcase(search_phrase)
2840

@@ -72,6 +84,10 @@ defmodule Location.Subdivision do
7284
Application.app_dir(:location, "priv/iso_3166-2.json")
7385
end
7486

87+
defp restore_source_file() do
88+
Application.app_dir(:location, "priv/restore/iso_3166-2.json")
89+
end
90+
7591
defp translations_file() do
7692
Application.app_dir(:location, "priv/iso_3166-2.en-translations.json")
7793
end

lib/mix/tasks/update_english_translations.ex

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

lib/mix/tasks/update_geoname_data.ex

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

lib/mix/tasks/update_iso_data.ex

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

0 commit comments

Comments
 (0)