Created
June 10, 2018 23:09
-
-
Save MattSandy/b1c955c4d762cde776eac34c49200048 to your computer and use it in GitHub Desktop.
Compile data from JSON API on mncompass.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = require('fs'); | |
let cheerio = require('cheerio'); | |
let rp = require('request-promise'); | |
var neighborhoods = { | |
'Calhoun Isles': 'a8a67acea57cb4dca5259bb46b201298', | |
'Camden': '0053599893439a3d71efd83852cd24d4', | |
'Central': 'd2c58b3f499c3269ab1c576e978e404b', | |
'Longfellow': '60ad517a63735568554252719020a854', | |
'Near North': 'c90b6b6a9af46e0a1f089abc480d73af', | |
'Nokomis': 'cf88f4d18243385b0b412367819e4b22', | |
'Northeast': '2fc3180574dd3237a730f871d26fd9d8', | |
'Phillips': '80a42ce18bd8c2fba249267fbd6f8572', | |
'Powderhorn': '59ab55db2bae3af2df2bf1404ec325dd', | |
'Southwest': '76300cc11a31e64e408a0c14055a48e2', | |
'University': 'b456662710bcd555e07f4773bbe6d86e', | |
'Armatage': '9dbd20c2fcc7c768b56018dddf26bd1a', | |
'Audubon Park': '960d9c37670a42e73bee71904abf56c4', | |
'Bancroft': '5a06f3e099a64142e664a20e31f89954', | |
'Beltrami': 'e19763912a638351eeb9f1aa0aa87d9a', | |
'Bottineau': '54e023097b1ef4981e047e71a33eab12', | |
'Bryant': '3e7cdc7c08f8c022e1d0359f4c7387ad', | |
'Bryn- Mawr': 'cb102c18b79113aa2f3ffe279993c16c', | |
'CARAG': 'b338d658ed977d0a8396622bb86166be', | |
'Cedar- Isles- Dean': '991bfc227f05cb7fa1179aa435c72d7b', | |
'Cedar Riverside': '29e32e1578a3922e106d40329766577e', | |
'Central': '98b878d816b850fc68c2eb52631e7fcf', | |
'Cleveland': '774c9d3371e4ea838eecd7976af51c4d', | |
'Columbia Park': 'd38ba2b1ea7e168101a5ae18d40ce396', | |
'Como (Minneapolis)': 'c0f83f0479fd3ec20ab45a402b25b568', | |
'Cooper': '0396e0483e961b24a673cfdac0c0d836', | |
'Corcoran': '6d02a8b92607065cc0129a6c492ff0ed', | |
'Diamond Lake': '0d646903772875af0e5fb7f7eacba7ab', | |
'Downtown East': 'a6cc69de3eec63dcb014c65ab6a34bce', | |
'Downtown West': 'f86dd2ef65a112a87eafa3e57a5475ac', | |
'East Harriet': 'cb3c37bb53dae4904ca1d3fe3f9d588c', | |
'East Isles': '768d3bb7a4b1f6fb0c0ed3185f8246fb', | |
'East Phillips': 'eb043eca482bb3277fedf5aa055c8886', | |
'ECCO': '3d611d3ff025da58553e851988bceeed', | |
'Elliot Park': '65ca2d6243fa9daf7752e1e52996d73c', | |
'Ericsson': '6c805767b1099e77dc4a690e1369ad0b', | |
'Field': '0e2d8c9cac0a41bb3c38783160ba9b8c', | |
'Folwell': 'c9235fa6122a082c10efa0d17107abb9', | |
'Fulton': '79910459fbeea04223f70bf08f0107e7', | |
'Hale': 'a64cfc945db946461f240de463e10987', | |
'Harrison': '1e3ae1615242efa5f796dd48befebda4', | |
'Hawthorne': '77798185d97e84a82b9c29cff205786b', | |
'Hiawatha': '469cafbb87c53209934df5191098fd44', | |
'Holland': 'a295a18f8fa756da39186fb40246611e', | |
'Howe': '3569ddbd23ac3a56593894eb3ba172be', | |
'Jordan': '633862a6cf13fa79beaae8f8ae79fcc1', | |
'Keewaydin': '09a46950811a169df224d99804684369', | |
'Kenny': '1db798776124ceeb5842516c91592deb', | |
'Kenwood': '1adae22686e8fb4b20f778981eb24288', | |
'King Field': 'ca1456a273893d6b14b3a19de3659a21', | |
'Lind- Bohanon': '461976f6a04ea0c8d4c61961021f9125', | |
'Linden Hills': 'a83f1ff0a69e05142f97c665c2ff7ac2', | |
'Logan Park': '31bda4141bd5f742a57b609473f0301c', | |
'Longfellow': '67fbddcec8167fa1319e8980c18649e5', | |
'Loring Park': '75aa79acca3ef7929237b9797a8cd987', | |
'Lowry Hill': '87aee0b82e2c6beebbcabebe1b9c67c4', | |
'Lowry Hill East': '7eda1eda363d01c06ca75935ae34e196', | |
'Lyndale': 'f213daf4f948e382b755ea60e0afef35', | |
'Lynnhurst': '8d4182f0b416bbfb0294303c09db7764', | |
'Marcy Holmes': '611bb4ab09a26f760a51e0046d82a364', | |
'Marshall Terrace': '85200e43ef2f311a285a7ca1b3c0e947', | |
'McKinley': 'd9f5cf65fa7729f94661fcfba0141bea', | |
'Mid- City Industrial': 'b401c2305b7903b749e055396de118e7', | |
'Midtown Phillips': '348e72db2025cacb74cd56ebd5c8e9ed', | |
'Minnehaha': 'df470b303f29ad7596805b699c70a138', | |
'Morris Park': 'b55b364c1ccbad904f9c8fa96e1a53ab', | |
'Near North': '19c151c8894e827221bab60f50041bca', | |
'Nicollet Island- East Bank': '5b541565afd49ebb0f2afca0bbf5bce4', | |
'North Loop': 'f7057bfbf9143b8bbb6a4eb1b2806a55', | |
'Northeast Park': '91e03658983121636259f9c17158432f', | |
'Northrop': 'a8841250281b1f9a7da24ff2dc20b570', | |
'Page': 'b7ecd921d1e77add400ec2cbad193691', | |
'Phillips West': 'cb1071c3a675641299ffde8f847e13fc', | |
'Powderhorn Park': '10bc45112c37025d8abb8b7fb3c23344', | |
'Prospect Park- East River Road': '1a5ff6ab386df9a427e7b93049460267', | |
'Regina': 'e1e4f595a20f487fd272259dbd1011ed', | |
'Seward': '884ab43979f5072a5015549a73777aa9', | |
'Sheridan': 'f0266cc7d2093bf67177b8a0154dac53', | |
'Shingle Creek': '53aecbb6b0f26025999f30889e832b8d', | |
'St. Anthony East': '899d3dcf577ecc5a01b91275f028027d', | |
'St. Anthony West': '2b68a0499cdcda6e01f2f7998b9743f9', | |
'Standish': 'd4150ac9407458c28096f46b7070dadb', | |
'Steven\'s Square- Loring Heights': '5b1fd7cbf848ea74e651760b64ecef25', | |
'Sumner- Glenwood': 'e79f343607830c7740f51a6c73304087', | |
'Tangletown': 'dbe3294b2fcfd74d4a81873052b26d2d', | |
'University of Minnesota': '099bda1a9fcbfa9b1b8f3a6a01576604', | |
'Ventura Village': '9980305dc100bb17fa24e97a8c88b823', | |
'Victory': 'd5f34088401caf2487bbd666aa945096', | |
'Waite Park': 'bc49a42047fc1c016f04d6c98572a1b9', | |
'Webber - Camden': 'dda424994613a3e32fba770f791e02a3', | |
'Wenonah': '2a833df084e079820be8c46ffec19b09', | |
'West Calhoun': 'bf2542a6f2136f61e36c549c92b91042', | |
'Whittier': '0c4587da9a9da2862e162d79350f562e', | |
'Willard - Hay': 'd101e6ff84fe402b6827ecb648db9d85', | |
'Windom': '8082f498bb9b58099d1e23937f18dae7', | |
'Windom Park': 'efccbf604733a339770665bdb8eac4dc' | |
} | |
fs.writeFile('data.csv', 'Neighborhood,Method,Count,Ratio\n', function(){console.log('done')}); | |
for(var neighborhood in neighborhoods) { | |
console.log(neighborhood); | |
console.log(neighborhoods[neighborhood]); | |
scrape(neighborhood,neighborhoods[neighborhood]); | |
} | |
function scrape(neighborhood,report) { | |
var url = 'http://wilder.excensus-online.com/api.json?req={%22mode%22:%22recall_report%22,%22report_id%22:%22' + report + '%22}'; | |
var options = { | |
uri: url, | |
json: true // Automatically parses the JSON string in the response | |
}; | |
rp(options) | |
.then(function (api) { | |
var table = api.result.tables.acs_transpo.rows; | |
var to_write = ''; | |
for(var row in table) { | |
var el = table[row]; | |
if(el.ratio != 1) { | |
to_write = to_write + neighborhood + ',"' + el.row_label + '",' + el.count + ',' + el.ratio + ',\n'; | |
} | |
} | |
console.log(to_write); | |
fs.appendFile('data.csv', to_write); | |
}) | |
.catch(function (err) { | |
// failed | |
console.log(err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment