Skip to main content

A Python Package to preprocess voting precinct and district geodata and make it easy to query. Currently restricted to WA state.

Project description

precinct-mapper

A Python Package to preprocess voting precinct and district geodata and make it easy to query. Currently restricted to WA state.

To run in DEVELOPMENT

  1. make sure you have Jupyter and ipykernel installed
  2. create a conda environment (-f flag specifies file): conda env create -f dev_env.yaml. This will create a conda environment called 'precinct_mapper'
  3. activate that environment: conda activate precinct_mapper

To run in PRODUCTION

  1. create a virtual environment python -m venv venv
  2. then activate it source venv/bin/activate
  3. pip install precinct_mapper pip install git+https://github.com/clear-vote/precinct-mapper.git
  4. TODO: Anaya install requests!!! pip install requests
  5. Save it all to requirements.txt pip freeze > requirements.txt in the virtual environment
  6. 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)

u gud to go

SSH Config (so you can modify AWS code locally)

Insert the following ssh code

  1. Ask for the key (keep it somewhere safe)
  2. 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

  1. Restart and enable the flaskapp: sudo systemctl restart flaskapp && sudo systemctl enable flaskapp
  2. Check the localhost curl -v http://localhost:8000
  3. Check the IP curl http://35.88.126.46/?longitude=0&latitude=0... Always append http:// before any IP!
  4. (optional) If you ever change the public IP, make sure to update it in the flaskapp configuration at /etc/nginx/sites-available/flaskapp
  5. (optional) reload the configurations and restart nginx. You can also modify gunicorn /etc/systemd/system/flaskapp.service

Lambda

  1. Run the following cp lambda_function.py my-deployment-package/ cp -r venv/lib/python3.x/site-packages/* my-deployment-package/
  2. Push to GH
  3. Download zip from GH
  4. 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

precinct_mapper-0.1.2b0.tar.gz (102.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

precinct_mapper-0.1.2b0-py3-none-any.whl (102.5 MB view details)

Uploaded Python 3

File details

Details for the file precinct_mapper-0.1.2b0.tar.gz.

File metadata

  • Download URL: precinct_mapper-0.1.2b0.tar.gz
  • Upload date:
  • Size: 102.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for precinct_mapper-0.1.2b0.tar.gz
Algorithm Hash digest
SHA256 cabde7a898a69b4ebdee01e4df096a73abb4244785fb97762ab73105a3df8455
MD5 bd30f6fb4333117ed5ddc6fac6572067
BLAKE2b-256 9c5a2a3dde4c52f18c86f1d0bc07b9df25d8891bcd9e9ad2ff2a3e3e8d0495ce

See more details on using hashes here.

File details

Details for the file precinct_mapper-0.1.2b0-py3-none-any.whl.

File metadata

File hashes

Hashes for precinct_mapper-0.1.2b0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5b755eca2bf43ec37265722bbe4728ab59591ae2df384a500f8fe03d80fa9b8
MD5 cdab2d89e7961f2afc8c77a114605103
BLAKE2b-256 e869ea1b50161b2efa7a45716bd4305004b64522470b29b6402de037b0cb60ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page