chrisdevwords / congressional-district-finder Goto Github PK
View Code? Open in Web Editor NEWA small library of functions for determining US Congressional representation based on location.
A small library of functions for determining US Congressional representation based on location.
I'm trying to include your library in an express project I'm building:
var Promise = require('es6-promise').Promise;
var finder = require('congressional-district-finder');
...
router.get('/coordinate/:latitude/:longitude', function(req, res) {
var lat = req.params.latitude
var lng = req.params.longitude
console.log("Request sent for lat: "+lat+" lng: "+lng)
finder.getDistrictByLatLng(lat, lng)
.then(function(result) {
console.log(result.isMatched); // outputs true
console.log(result.district.name); //outputs "New York 12th"
console.log(result.district.districtCode); //outputs "NY-12"
res.status(200).json({"matched" : result.isMatched, "name" : result.district.name, "code" : result.district.code })
})
.catch(function(err) {
console.log(err);
res.status(500).send(err.message);
})
});
However, whenever I access that point, it throws an error:
Request sent for lat: 37.3982430 lng: -121.9922530
[TypeError: Object [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] has no method 'find']
GET /coordinate/37.3982430/-121.9922530 500 156.947 ms - 171
Any idea about the issue here?
<html>
<head><base href="https://www.house.gov">
<title>Find Your Representative in the U.S. House of Representatives</title>
<meta charset="UTF-8">
<meta name="robots" content="NOODP">
<link rel="stylesheet" href="/content/static/css/h.css?v=1">
<link rel="stylesheet" href="/content/static/css/house.css?v=1">
<!--[if IE]>
<link rel="stylesheet" href="/content/static/css/ie.css?v=1">
<![endif]-->
<link rel="shortcut icon" href="/content/static/img/favicon.ico" type="image/x-icon">
<script type="text/javascript" src="/content/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/content/static/js/html5lightbox/html5lightbox.js"></script>
<script type="text/javascript" src="/content/static/js/jquery.lightbox.min.js"></script>
<script type="text/javascript" src="/content/static/js/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="/content/static/js/h.js?v=1"></script>
<script type="text/javascript">
var _gaq = _gaq || [" is an invalid format.
at parseDistrictCode (/Users/taylorhammons/capstone-Node/easy-node-authentication/node_modules/house-gov-page-scraper/dist/house/gov/getDistrictsInZip.js:45:15)
at Array.map (<anonymous>)
at scrapePage (/Users/taylorhammons/capstone-Node/easy-node-authentication/node_modules/house-gov-page-scraper/dist/house/gov/getDistrictsInZip.js:68:17)
at /Users/taylorhammons/capstone-Node/easy-node-authentication/node_modules/house-gov-page-scraper/dist/house/gov/getDistrictsInZip.js:84:16
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:9169) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9169) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I tried the example and got this
<html>
<head><base href="https://www.house.gov">
<title>Find Your Representative in the U.S. House of Representatives</title>
<meta charset="UTF-8">
<meta name="robots" content="NOODP">
<link rel="stylesheet" href="/content/static/css/h.css?v=1">
<link rel="stylesheet" href="/content/static/css/house.css?v=1">
<!--[if IE]>
<link rel="stylesheet" href="/content/static/css/ie.css?v=1">
<![endif]-->
<link rel="shortcut icon" href="/content/static/img/favicon.ico" type="image/x-icon">
<script type="text/javascript" src="/content/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/content/static/js/html5lightbox/html5lightbox.js"></script>
<script type="text/javascript" src="/content/static/js/jquery.lightbox.min.js"></script>
<script type="text/javascript" src="/content/static/js/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="/content/static/js/h.js?v=1"></script>
<script type="text/javascript">
var _gaq = _gaq || [" is an invalid format.```
Just tried a request to test out the result format, but get an error every time. Changed it to async/await syntax and get the same thing.
This is my JS code
const findUserDistrict = (lat, long) => {
finder
.getDistrictByLatLng(lat, long)
.then(function(result) {
console.log(result.district.name);
console.log(result.district.districtCode);
})
.catch(function(err) {
console.log(err.message);
});
};
findUserDistrict(21.3069, -157.8583);
and this is what I get as a result:
Error: District code substring: "" is an invalid format.
at parseDistrictCode (/Users/ryan/code/breakdown/breakdown-api/node_modules/house-gov-page-scraper/dist/house/gov/getDistrictsInZip.js:37:15)
at Array.map (<anonymous>)
at scrapePage (/Users/ryan/code/breakdown/breakdown-api/node_modules/house-gov-page-scraper/dist/house/gov/getDistrictsInZip.js:68:17)
at /Users/ryan/code/breakdown/breakdown-api/node_modules/house-gov-page-scraper/dist/house/gov/getDistrictsInZip.js:84:16
at process._tickCallback (internal/process/next_tick.js:68:7)
Would really appreciate a solution to this, as I'm launching a time-sensitive app for this election.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.