precinct-mapper
A Python Package to preprocess precinct and district geodata and make it easy to query.
To run in DEVELOPMENT
- make sure you have Jupyter and ipykernel installed
- create a conda environment (-f flag specifies file):
conda env create -f env.yaml. This will create a conda environment called 'precinct_env' - activate that environment:
conda activate precinct_env
To run in PRODUCTION
- create a virtual environment
python -m venv venv - then activate it
source venv/bin/activate - pip install precinct_mapper
pip install git+https://github.com/clear-vote/precinct-mapper.git - Save it all to requirements.txt
pip freeze > requirements.txtin the virtual environment - issue the following commands...
from precinct_mapper.mapper import load_state
state_obj = load_state()
json = state_obj.lookup_lat_lon(-122.3328, 47.6061)
print(json['county'].name)
SSH Config (so you can modify AWS code locally)
Insert the following ssh code
- Ask for the key (keep it somewhere safe)
- Add the following SSH info to your config
Host flask-app-ec2 HostName ec2-35-88-126-46.us-west-2.compute.amazonaws.com User ubuntu IdentityFile
(we are moving away from this) Restarting for production on AWS EC2 instance
- Restart and enable the flaskapp:
sudo systemctl restart flaskapp && sudo systemctl enable flaskapp - Check the localhost
curl -v http://localhost:8000 - Check the IP
curl http://35.88.126.46/?longitude=0&latitude=0... Always append http:// before any IP! - (optional) If you ever change the public IP, make sure to update it in the flaskapp configuration at /etc/nginx/sites-available/flaskapp
- (optional) reload the configurations and restart nginx. You can also modify gunicorn /etc/systemd/system/flaskapp.service
Lambda
- Run the following cp lambda_function.py my-deployment-package/ cp -r venv/lib/python3.x/site-packages/* my-deployment-package/
- Push to GH
- Download zip from GH
- Deploy via AWS Lambda
TODO
Amazon RDS (Relational Database Service): To host your MySQL database. Amazon S3: To store static assets or backup data if needed. AWS IAM (Identity and Access Management): To manage access and permissions securely.
Add this route and test with different coordinates:
from flask import Flask, request, jsonify
from your_module import state_obj # Import your state_obj from the appropriate module
app = Flask(__name__)
@app.route('/lookup', methods=['GET'])
def lookup_lat_lon():
# Get coordinates from query parameters
coordinate_1 = request.args.get('coordinate_1')
coordinate_2 = request.args.get('coordinate_2')
if not coordinate_1 or not coordinate_2:
return jsonify({'error': 'Missing coordinates'}), 400
try:
# Run the command with the provided coordinates
result = state_obj.lookup_lat_lon(coordinate_1, coordinate_2)
return jsonify(result)
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
Metadata
Release files for precinct-mapper 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| precinct_mapper-0.2.1.tar.gz | 14.4 kB | Without provenance | Details for precinct_mapper-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| precinct_mapper-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for precinct_mapper-0.2.1-py3-none-any.whl |
Total release size: 30.5 kB
Release files / precinct_mapper-0.2.1.tar.gz
| Download URL | precinct_mapper-0.2.1.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b768956596cde119558a683529fdc812a19d681c7b35cee0be7191e62483d7aa
|
|
BLAKE2b-256 checksum How to use checksums |
1e7510ec0d6b58fd16c288af0e817dd0db4076e6d672859b32ae5dfe75fb8353
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Release files / precinct_mapper-0.2.1-py3-none-any.whl
| Download URL | precinct_mapper-0.2.1-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3c0af95036cf47c56c2a4113a0780e48c2d7a44a674a241478d91b4f45091b8
|
|
BLAKE2b-256 checksum How to use checksums |
2173ff81d09318fd84925beeb734e96142fbc884ca693fe03b441803006aa8f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for precinct-mapper 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.