Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	lib/mix/tasks/update_geoname_data.ex
#	lib/scraper/scraper.ex
#	mix.exs
#	mix.lock
  • Loading branch information
mithereal committed Feb 23, 2025
2 parents 6576d4f + 0c3b18a commit e33ad65
Show file tree
Hide file tree
Showing 26 changed files with 3,352 additions and 2,207 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["{mix,.formatter}.exs", "{config,lib,test,mix_tasks}/**/*.{ex,exs}"]
]
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "mix"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
55 changes: 55 additions & 0 deletions .github/workflows/mix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: mix

on:
pull_request:
push:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

env:
MIX_ENV: test

strategy:
matrix:
elixir: [1.15, 1.16]
otp: [25, 26]
include:
- elixir: 1.17
otp: 27

steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- uses: actions/cache@v4
with:
path: |
deps
_build
key: test-${{ matrix.otp }}-${{ matrix.elixir }}-${{ github.head_ref || github.ref }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
test-${{ matrix.otp }}-${{ matrix.elixir }}-${{ github.head_ref || github.ref }}-
test-${{ matrix.otp }}-${{ matrix.elixir }}-refs/heads/master-
- run: mix deps.get --only $MIX_ENV
# TODO --warnings-as-errors
- run: mix compile
- run: mix test

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
elixir-version: 1
otp-version: 27
- run: elixir -v
- run: mix format --check-formatted
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Location

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.


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.

### Countries

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

### Subdivisions

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 Wikipedia using a scraper. The translations found in `priv/iso_3166-2.en-translations.json` are used when available instead of the original name.

We also add some data manually that is missing from upstream. Overrides can be found in `priv/override/iso_3166-2.json`
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.

### Cities

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

### Postal Codes
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.

#### Postal Code Helpers
Postal codes can be downloaded
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.
6 changes: 6 additions & 0 deletions lib/location.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ defmodule Location do
Logger.debug("Loading location database #{inspect(module)} took: #{time}s")
:ok
end

def version() do
version_file = Application.app_dir(:location, "priv/version")

File.read!(version_file)
end
end
5 changes: 5 additions & 0 deletions lib/location/city.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ defmodule Location.City do
|> Stream.run()
end

def all() do
:ets.tab2list(@ets_table_by_id)
|> Enum.map(fn {id, {name, country_code}} -> to_struct(id, name, country_code) end)
end

@doc """
Finds city by GeoNames ID.
"""
Expand Down
16 changes: 16 additions & 0 deletions lib/location/subdivision.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ defmodule Location.Subdivision do
:ets.insert(ets, {entry["code"], to_struct(entry)})
end)

File.read!(restore_source_file())
|> Jason.decode!()
|> Enum.each(fn entry ->
entry = translate_entry(translations, entry)
:ets.insert(ets, {entry["code"], to_struct(entry)})
end)

File.read!(override_source_file())
|> Jason.decode!()
|> Enum.each(fn entry ->
:ets.insert(ets, {entry["code"], to_struct(entry)})
end)
end

def all() do
:ets.tab2list(@ets_table)
|> Enum.map(fn {_, entry} -> entry end)
end

def search_subdivision(search_phrase) do
search_phrase = String.downcase(search_phrase)

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

defp restore_source_file() do
Application.app_dir(:location, "priv/restore/iso_3166-2.json")
end

defp translations_file() do
Application.app_dir(:location, "priv/iso_3166-2.en-translations.json")
end
Expand Down
9 changes: 0 additions & 9 deletions lib/mix/tasks/update_english_translations.ex

This file was deleted.

77 changes: 0 additions & 77 deletions lib/mix/tasks/update_geoname_data.ex

This file was deleted.

18 changes: 0 additions & 18 deletions lib/mix/tasks/update_iso_data.ex

This file was deleted.

Loading

0 comments on commit e33ad65

Please sign in to comment.