precinct-mapper


Nameprecinct-mapper JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/clear-vote/precinct-mapper
SummaryA Python Package to preprocess voting precinct and district geodata and make it easy to query. Currently restricted to WA state.
upload_time2024-09-24 05:59:41
maintainerNone
docs_urlNone
authorAnaya Pandit
requires_python<4.0.0,>=3.11.7
licenseMIT
keywords precinct geodata geopandas boundary districts
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 <your-key-name-here>

## (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:
```python
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)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/clear-vote/precinct-mapper",
    "name": "precinct-mapper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.11.7",
    "maintainer_email": null,
    "keywords": "precinct, geodata, geopandas, boundary, districts",
    "author": "Anaya Pandit",
    "author_email": "anaya.pandit7924@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/44/21/fbf22430291ab551fd9956b781e09cce75cabf50d6e61ed1df9dca9e13c8/precinct_mapper-0.2.0.tar.gz",
    "platform": null,
    "description": "# precinct-mapper\nA Python Package to preprocess voting precinct and district geodata and make it easy to query. Currently restricted to WA state.\n\n# To run in DEVELOPMENT\n1. make sure you have Jupyter and ipykernel installed\n2. create a conda environment (-f flag specifies file): `conda env create -f dev_env.yaml`. This will create a conda environment called 'precinct_mapper'\n3. activate that environment: `conda activate precinct_mapper`\n\n# To run in PRODUCTION\n1. create a virtual environment `python -m venv venv`\n2. then activate it `source venv/bin/activate`\n3. pip install precinct_mapper `pip install git+https://github.com/clear-vote/precinct-mapper.git`\n4. TODO: Anaya install requests!!! `pip install requests`\n5. Save it all to requirements.txt `pip freeze > requirements.txt` *in the virtual environment*\n6. issue the following commands...\n```\nfrom precinct_mapper.mapper import load_state\nstate_obj = load_state()\njson = state_obj.lookup_lat_lon(-122.3328, 47.6061)\nprint(json['county'].name)\n\n```\nu gud to go\n\n## SSH Config (so you can modify AWS code locally)\nInsert the following ssh code\n1. Ask for the key (keep it somewhere safe)\n2. Add the following SSH info to your config\n> Host flask-app-ec2\n>     HostName ec2-35-88-126-46.us-west-2.compute.amazonaws.com\n>     User ubuntu\n>     IdentityFile <your-key-name-here>\n\n## (we are moving away from this) Restarting for production on AWS EC2 instance\n1. Restart and enable the flaskapp: `sudo systemctl restart flaskapp && sudo systemctl enable flaskapp`\n2. Check the localhost `curl -v http://localhost:8000`\n3. Check the IP `curl http://35.88.126.46/?longitude=0&latitude=0`... *Always append http:// before any IP!*\n4. (optional) If you ever change the public IP, make sure to update it in the flaskapp configuration at /etc/nginx/sites-available/flaskapp\n5. (optional) reload the configurations and restart nginx. You can also modify gunicorn /etc/systemd/system/flaskapp.service\n\n## Lambda\n1. Run the following\ncp lambda_function.py my-deployment-package/\ncp -r venv/lib/python3.x/site-packages/* my-deployment-package/\n2. Push to GH\n3. Download zip from GH\n4. Deploy via AWS Lambda\n\n## TODO\nAmazon RDS (Relational Database Service): To host your MySQL database.\nAmazon S3: To store static assets or backup data if needed.\nAWS IAM (Identity and Access Management): To manage access and permissions securely.\n\nAdd this route and test with different coordinates:\n```python\nfrom flask import Flask, request, jsonify\nfrom your_module import state_obj  # Import your state_obj from the appropriate module\n\napp = Flask(__name__)\n\n@app.route('/lookup', methods=['GET'])\ndef lookup_lat_lon():\n    # Get coordinates from query parameters\n    coordinate_1 = request.args.get('coordinate_1')\n    coordinate_2 = request.args.get('coordinate_2')\n    \n    if not coordinate_1 or not coordinate_2:\n        return jsonify({'error': 'Missing coordinates'}), 400\n    \n    try:\n        # Run the command with the provided coordinates\n        result = state_obj.lookup_lat_lon(coordinate_1, coordinate_2)\n        return jsonify(result)\n    except Exception as e:\n        return jsonify({'error': str(e)}), 500\n\nif __name__ == '__main__':\n    app.run(host='0.0.0.0', port=5000)\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python Package to preprocess voting precinct and district geodata and make it easy to query. Currently restricted to WA state.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/clear-vote/precinct-mapper",
        "Repository": "https://github.com/clear-vote/precinct-mapper"
    },
    "split_keywords": [
        "precinct",
        " geodata",
        " geopandas",
        " boundary",
        " districts"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5fdfdd0097e02bf8c203dcab8e930b33f0c306de206fdcad38a26f15b55e50d",
                "md5": "3419429ae189a8cf39f7ea99ca18a7d3",
                "sha256": "4aeb78a71f3c0c4af46050231d072b04c041bb6a688cce9213b57114010030cf"
            },
            "downloads": -1,
            "filename": "precinct_mapper-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3419429ae189a8cf39f7ea99ca18a7d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.11.7",
            "size": 16125,
            "upload_time": "2024-09-24T05:59:39",
            "upload_time_iso_8601": "2024-09-24T05:59:39.485113Z",
            "url": "https://files.pythonhosted.org/packages/d5/fd/fdd0097e02bf8c203dcab8e930b33f0c306de206fdcad38a26f15b55e50d/precinct_mapper-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4421fbf22430291ab551fd9956b781e09cce75cabf50d6e61ed1df9dca9e13c8",
                "md5": "7f09d1d929a5169f515e0e83d0c7268a",
                "sha256": "a15560614712a29d6a7ff9ce31c0a0893ec0b578443f78f5918117f17cfe1569"
            },
            "downloads": -1,
            "filename": "precinct_mapper-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7f09d1d929a5169f515e0e83d0c7268a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.11.7",
            "size": 14459,
            "upload_time": "2024-09-24T05:59:41",
            "upload_time_iso_8601": "2024-09-24T05:59:41.133192Z",
            "url": "https://files.pythonhosted.org/packages/44/21/fbf22430291ab551fd9956b781e09cce75cabf50d6e61ed1df9dca9e13c8/precinct_mapper-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-24 05:59:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "clear-vote",
    "github_project": "precinct-mapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "precinct-mapper"
}
        
Elapsed time: 0.95778s