A phoxy link and discussion aggregator with snek (python3)
- A database server, MySQL, MariaDB and Postgres have been tested. Sqlite should work for messing locally
- Redis
- Python >= 3.7
- A recent node/npm
- libmagic
We recommend using a virtualenv or Pyenv
- Install Python dependencies with
pip install -r requirements.txt
- Install Node dependencies with
npm install
- Build the bundles with
npm run build
- Copy
example.config.yaml
toconfig.yaml
and edit it - Set up the database by executing
./throat.py migration apply
- Compile the translation files with
./throat.py translations compile
And you're done! You can run a test server by executing ./throat.py
. For production instances we recommend setting up gunicorn
Please read doc/deploy.md for instructions to deploy on gunicorn or using docker.
If you prefer to develop on docker
- The provided Docker resources only support Postgres
- You still must copy
example.config.yaml
toconfig.yaml
and make any changes you want - In addition, configs are overridden by environment variables set in docker-compose.yml which reference the redis and postgres services created by docker-compose.
make up
will bring the containerized site up and mount the app/html and app/template directories
inside the container for dev. It also runs the migrations on start-up. make down
will spin down the containerized services.
To add an admin user to a running docker-compose application:
docker exec throat_throat_1 python3 scripts/admins.py --add {{username}}
If Wheezy templates are not automatically reloading in docker between changes, try docker restart throat_throat_1
.
The default hot sort function is simple for speed, but it does not prioritize new posts over old ones as much as some people prefer. If you define a function named hot
in SQL in your database, you can use that instead of the default by setting custom_hot_sort
to True
in your config.yaml
. The function needs to take two arguments, a post's current score and the date it was posted. To allow the database to cache the results, the function should only depend on the values of its arguments and should be marked immutable
.
In addition to defining the function, you should also create an index on it to speed up the hot sort query. Once that is done, custom functions will be faster than the default hot sort. To implement Reddit's version of hot sort in Postgres, add the following SQL statements to your database using psql
:
create or replace function hot(score integer, date double precision) returns numeric as $$
select round(cast(log(greatest(abs($1), 1)) * sign($1) + ($2 - 1134028003) / 45000.0 as numeric), 7)
$$ language sql immutable;
create index on sub_post (hot(score, (EXTRACT(EPOCH FROM sub_post.posted))));
Other databases may require variations in the handling of the date. Custom hot sorts are not supported for Sqlite.
CMD [ "gunicorn", \
"-w", "4", \
"-k", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", \
"-b", "0.0.0.0:5000", \
"throat:app" ]
Optionally, user authentication can be done using a Keycloak server.
You will need to create a realm for the users on the server, as well
as Keycloak clients with appropriate permissions. See
doc/keycloak.org
for instructions.
You can check out the CDK Definition of Infrastructure maintained by Ovarit
./throat.py admin
to list, add or remove administrators../throat.py default
to list, add or remove default subs.
- Python, redis, and libmagic are required, but node and postgres are not.
- Install dependencies with
pip install -r requirements.txt
- Run the tests with
python -m pytest
- The tests are not affected by your configuration in
config.yaml
. If you wish to run the tests against production database or authentication servers (instead of the defaults, which are sqlite and local authentication), you may put configuration settings intest_config.yaml
and run the tests withTEST_CONFIG=test_config.yaml python -m pytest
You can run pytest in a Docker container via docker-compose with make test
.
To pass arguments to pytest, invoke make like so: make test ARGS="-x -k my_test"
If you have any questions, you can reach us on #throat:phuks.co on Matrix