用于美国选举投票信息的rest api服务器
ballotapi的Python项目详细描述
ballotapi服务器
警告:此自述文件的代码尚未编写
此文件夹包含ballotapi服务器本身的代码。如果你 想要运行自己的选票api镜像,这是代码 你在找。
安装
一。安装ballotapi服务器
最简单的安装方法是通过PyPI:
pip install ballotapi
要更新,只需添加-U
标志。
pip install -U ballotapi
或者,您可以直接从源安装:
git clone https://github.com/open-austin/ballotapi.git pip install -e ballotapi/
或者,您可以直接从源代码运行:
git clone https://github.com/open-austin/ballotapi.git
cd ballotapi
pip install -r requirements.txt
python3 -m ballotapi.cli --help
2.设置数据库
ballotapi服务器需要加载选票数据数据库。 你可以下载一份 test databases, 在full production database, 或者build your own。
如果已经加载了数据库,则可以跳过此步骤。
# Install PostgreSQL and PostGIS plugin sudo apt-get install postgresql postgis # Create a BallotAPI database and user sudo -u postgres psql -c "CREATE DATABASE ballotapi;" sudo -u postgres psql -c "CREATE USER ballotapiuser WITH ENCRYPTED PASSWORD 'yourpasswordhere';" sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ballotapi TO ballotapiuser;"# Set database connection uri environmental variableexportBALLOTAPI_DB_URI="postgresql://ballotapiuser:yourpasswordhere@localhost:5432/ballotapi"# Load a dataset into your database ballotapi load "testdata-default"
用法
现在已经安装了ballotapi服务器并加载了数据库, 你已经准备好运行服务器了!
ballotapi runserver
要自定义服务器的设置,请检查哪些选项
正在使用ballotapi runserver --help
。
usage: ballotapi runserver [-h][--db-uri URI][--cache-uri URI][--host HOST][--port PORT][--uwsgi-ini FILE][--daemon] optional arguments: -h, --help show this help message and exit --db-uri URI connection uri to the postgres database (default is BALLOTAPI_DB_URI env variable) --cache-uri URI connection uri to a cache server (default is None) --host HOST listen for this host (default localhost) --port PORT listen on this port (default 1776) --uwsgi-ini FILE settings for uwsgi (default is a simple http server) --daemon detach server to run in background as a daemon (optional)
要在直接从命令行运行服务器时停止服务器,
只需使用Ctrl+C
。停止/重新加载在后台运行的服务器
作为守护进程,向进程发送信号。
# gracefully reload killall -s SIGHUP ballotapi # gracefully stop killall -s SIGTERM ballotapi # brutally reload killall -s SIGINT ballotapi # brutally stop killall -s SIGKILL ballotapi
命令
usage: ballotapi [-h] <subcommand> ...
Documentation: https://ballotapi.org/docs
optional arguments:
-h, --help show this help message and exit
available subcommands:
<subcommand>
runserver Run the web server
load Load in a database from a source location
export Dump the database as a sql file
贡献
帮帮我们!如果你发现了一个bug或者想改进这个代码库, 请随意提交 issue 或者pull request。 查看我们的CONTRIBUTING文档了解更多详细信息。