diff --git a/.gitignore b/.gitignore index 03f1c6e..a5e1081 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,8 @@ venv __pycache__ .mypy_cache/ config/default.py +node_modules/ +.vscode/ +config.default +package-lock.json +config/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a5bec6 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# OWL-MAP + +## Setup +* clone the project +* install geoip and postgis from your local package manager + * `$ sudo pacman -S postgis geoip` +* setup postgres on your machine, see e.g. https://wiki.archlinux.org/title/PostgreSQL + * `$ sudo su postgres` + * `$ initdb -D /var/lib/postgres/data` +* start postgres +* create postgres user + * `$ sudo su postgres` + * `$ createuser --interactive` -> "owl" role with relevant priviledges +* create postgres database "matcher" with hstore and postgis extensions + * `$ psql -U postgres` + * `> CREATE DATABASE matcher;` + * `> ALTER DATABASE matcher OWNER TO owl;` + * `> CREATE EXTENSION hstore;` + * `> CREATE EXTENSION postgis;` +* create the db tables + * setup database credentials and name in default.py + * `$ python create_db.py` +* setup a venv + * enter the venv, e.g. in pycharm + * `$ pip install -r requirements.txt` +* `$ cp config/example.py config/default.py` +* download id-tagging-schema + * `$ git clone https://github.com/openstreetmap/id-tagging-schema` + * adjust paths in default.py +* download geoip databases + * https://git.io/GeoLite2-City.mmdb + * `$ pacman -S geoip-database-extra` in ArchLinux or https://dl.miyuru.lk/geoip/maxmind/city/maxmind4.dat.gz + * adjust default.py +* run the tests +* run 'python web_view.py' diff --git a/config/example.py b/config/example.py index 28f5052..26b8a0e 100644 --- a/config/example.py +++ b/config/example.py @@ -1,5 +1,8 @@ """Sample config.""" +# POSTGIS +DB_USER = "owl" +DB_NAME = "matcher" ID_TAGGING_SCHEMA_DIR = "/var/lib/data/id-tagging-schema" ID_PRESET_DIR = "/var/lib/data/id-tagging-schema/data/presets/" diff --git a/create_db.py b/create_db.py index 2c1c6f9..761fce7 100755 --- a/create_db.py +++ b/create_db.py @@ -2,9 +2,10 @@ from sqlalchemy.schema import CreateIndex, CreateTable +from config.default import DB_USER, DB_NAME from matcher import database, model -DB_URL = "postgresql:///matcher" +DB_URL = f"postgresql://{DB_USER}@localhost/{DB_NAME}" database.init_db(DB_URL) diff --git a/requirements.txt b/requirements.txt index 1a601c3..5e48821 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ simplejson user_agents num2words psycopg2 +pytest===8.3.2 \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py index c9f6c7f..823678e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,30 +1,29 @@ """Test matcher utils.""" +from unittest import TestCase from matcher import utils -def test_format_wikibase_time_year() -> None: - """Test passing a year to format_wikibase_time.""" - v = {"time": "+1950-00-00T00:00:00Z", "precision": 9} - assert utils.format_wikibase_time(v) == "1950" +class TestUtils(TestCase): + def test_format_wikibase_time_year(self) -> None: + """Test passing a year to format_wikibase_time.""" + v = {"time": "+1950-00-00T00:00:00Z", "precision": 9} + assert utils.format_wikibase_time(v) == "1950" + def test_format_wikibase_time_century(self) -> None: + """Test passing centuries to format_wikibase_time.""" + v = {"time": "+0800-00-00T00:00:00Z", "precision": 7} + assert utils.format_wikibase_time(v) == "8th century" -def test_format_wikibase_time_century() -> None: - """Test passing centuries to format_wikibase_time.""" - v = {"time": "+0800-00-00T00:00:00Z", "precision": 7} - assert utils.format_wikibase_time(v) == "8th century" + v = {"time": "+1950-00-00T00:00:00Z", "precision": 7} + assert utils.format_wikibase_time(v) == "20th century" - v = {"time": "+1950-00-00T00:00:00Z", "precision": 7} - assert utils.format_wikibase_time(v) == "20th century" + def test_format_wikibase_time_decade(self) -> None: + """Test passing a full date to format_wikibase_time.""" + v = {"time": "+1910-00-00T00:00:00Z", "precision": 8} + assert utils.format_wikibase_time(v) == "1910s" - -def test_format_wikibase_time_decade() -> None: - """Test passing a full date to format_wikibase_time.""" - v = {"time": "+1910-00-00T00:00:00Z", "precision": 8} - assert utils.format_wikibase_time(v) == "1910s" - - -def test_format_wikibase_time_day() -> None: - """Test passing a full date to format_wikibase_time.""" - v = {"time": "+1868-01-09T00:00:00Z", "precision": 11} - assert utils.format_wikibase_time(v) == "9 January 1868" + def test_format_wikibase_time_day(self) -> None: + """Test passing a full date to format_wikibase_time.""" + v = {"time": "+1868-01-09T00:00:00Z", "precision": 11} + assert utils.format_wikibase_time(v) == "9 January 1868"