Compare commits

..

18 commits

Author SHA1 Message Date
Dennis Priskorn 8990daec21 chore: pytest: Add pytest and enclose the tests in a new class TestUtils 2024-08-28 11:54:05 +02:00
Dennis Priskorn 171d13f9ca doc: README: Add more information about creating the database and tables 2024-08-28 11:47:21 +02:00
Dennis Priskorn 8dae88d6b4 fix: setup: Add DB_USER and DB_NAME variables to example config and use them when creating the tables. 2024-08-28 11:47:01 +02:00
Dennis Priskorn 9f90fbd52d doc: README: Add more information about setup of database and role 2024-08-28 11:34:35 +02:00
Dennis Priskorn 2051da0220 Merge remote-tracking branch 'origin/add-documentation' into add-documentation 2024-08-28 11:34:32 +02:00
Dennis Priskorn c4dfa48fa3 doc: README: Add more information about download of geoip files 2024-08-28 11:19:29 +02:00
Dennis Priskorn 47104df2a7 doc: README: Add more information about venv setup 2024-08-28 11:19:29 +02:00
Dennis Priskorn 057296012c doc: README: Add more information about postgres setup 2024-08-28 11:19:29 +02:00
Dennis Priskorn b191940b6e WIP setup instructions 2024-08-28 11:19:29 +02:00
Dennis Priskorn 55d1efaf16 update gitignore 2024-08-28 11:19:29 +02:00
Dennis Priskorn 92456553e6 doc: README: Add more information about download of geoip files 2024-08-28 10:44:39 +02:00
Dennis Priskorn 2f35dd712c doc: README: Add more information about venv setup 2024-08-28 09:50:15 +02:00
Dennis Priskorn 99f74b12d0 doc: README: Add more information about postgres setup 2024-08-28 09:42:35 +02:00
Dennis Priskorn acd5f94bd3 Merge remote-tracking branch 'origin/add-documentation' into add-documentation 2024-08-28 09:31:22 +02:00
Dennis Priskorn 78296ce189 WIP setup instructions 2024-08-28 09:31:15 +02:00
Dennis Priskorn fa02c59ae7 update gitignore 2024-08-28 09:31:15 +02:00
Dennis Priskorn 3869ef32c0 WIP setup instructions 2024-05-04 22:03:47 +02:00
Dennis Priskorn 6beec54fd1 update gitignore 2024-05-04 22:03:23 +02:00
6 changed files with 66 additions and 22 deletions

5
.gitignore vendored
View file

@ -2,3 +2,8 @@ venv
__pycache__ __pycache__
.mypy_cache/ .mypy_cache/
config/default.py config/default.py
node_modules/
.vscode/
config.default
package-lock.json
config/

35
README.md Normal file
View file

@ -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'

View file

@ -1,5 +1,8 @@
"""Sample config.""" """Sample config."""
# POSTGIS
DB_USER = "owl"
DB_NAME = "matcher"
ID_TAGGING_SCHEMA_DIR = "/var/lib/data/id-tagging-schema" ID_TAGGING_SCHEMA_DIR = "/var/lib/data/id-tagging-schema"
ID_PRESET_DIR = "/var/lib/data/id-tagging-schema/data/presets/" ID_PRESET_DIR = "/var/lib/data/id-tagging-schema/data/presets/"

View file

@ -2,9 +2,10 @@
from sqlalchemy.schema import CreateIndex, CreateTable from sqlalchemy.schema import CreateIndex, CreateTable
from config.default import DB_USER, DB_NAME
from matcher import database, model from matcher import database, model
DB_URL = "postgresql:///matcher" DB_URL = f"postgresql://{DB_USER}@localhost/{DB_NAME}"
database.init_db(DB_URL) database.init_db(DB_URL)

View file

@ -11,3 +11,4 @@ simplejson
user_agents user_agents
num2words num2words
psycopg2 psycopg2
pytest===8.3.2

View file

@ -1,30 +1,29 @@
"""Test matcher utils.""" """Test matcher utils."""
from unittest import TestCase
from matcher import utils from matcher import utils
def test_format_wikibase_time_year() -> None: class TestUtils(TestCase):
"""Test passing a year to format_wikibase_time.""" def test_format_wikibase_time_year(self) -> None:
v = {"time": "+1950-00-00T00:00:00Z", "precision": 9} """Test passing a year to format_wikibase_time."""
assert utils.format_wikibase_time(v) == "1950" 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: v = {"time": "+1950-00-00T00:00:00Z", "precision": 7}
"""Test passing centuries to format_wikibase_time.""" assert utils.format_wikibase_time(v) == "20th century"
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} def test_format_wikibase_time_decade(self) -> None:
assert utils.format_wikibase_time(v) == "20th century" """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(self) -> None:
def test_format_wikibase_time_decade() -> None: """Test passing a full date to format_wikibase_time."""
"""Test passing a full date to format_wikibase_time.""" v = {"time": "+1868-01-09T00:00:00Z", "precision": 11}
v = {"time": "+1910-00-00T00:00:00Z", "precision": 8} assert utils.format_wikibase_time(v) == "9 January 1868"
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"