Skip to content

Instantly share code, notes, and snippets.

@saranrapjs
Created November 20, 2013 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saranrapjs/7555432 to your computer and use it in GitHub Desktop.
Save saranrapjs/7555432 to your computer and use it in GitHub Desktop.
Code that generates the bot for https://twitter.com/NYCLLC
// requires: sqlite3, ntwitter
var sqlite3 = require('sqlite3'),
db = new sqlite3.Database('biz.db'),
twitter = require('ntwitter');
var twit = new twitter({
consumer_key: 'all',
consumer_secret: 'your',
access_token_key: 'tokens',
access_token_secret: 'here'
});
function tweet(msg, callback) {
twit.updateStatus(msg,
function (err, data) {
callback()
});
}
function randomBiz(callback) {
db.get("SELECT * FROM biz ORDER BY RANDOM() LIMIT 1;",function(err,row) {
var biz = '';
if (!err) biz = row['Current Entity Name'] + " " + row['Initial DOS Filing Date'];
console.log(biz)
callback(biz)
});
}
(function run() {
randomBiz(function(biz) {
tweet(biz, function() {
// console.log("TWEETED?")
setTimeout(run, 1000*60*60*6) // every 3 hours?
})
})
})()
@saranrapjs
Copy link
Author

To generate biz.db:

  1. Download data from here: https://data.ny.gov/Economic-Development/Active-Corporations-Beginning-1800/n9v6-gdp6 (download as CSV)

  2. Create schema in empty biz.db file

    $ sqlite3 biz.db
    sqlite> create table biz ("DOS ID" text, "Current Entity Name" text, "Initial DOS Filing Date" text, "County" text, "Jurisdiction" text, "Entity Type" text, "DOS Process Name" text, "DOS Process Address 1" text, "DOS Process Address 2" text, "DOS Process City" text, "DOS Process State" text, "DOS Process Zip" text, "CEO Name" text, "CEO Address 1" text, "CEO Address 2" text, "CEO City" text, "CEO State" text, "CEO Zip" text, "Registered Agent Name" text, "Registered Agent Address 1" text, "Registered Agent Address 2" text, "Registered Agent City" text, "Registered Agent State" text, "Registered Agent Zip" text, "Location Name" text, "Location Address 1" text, "Location Address 2" text, "Location City" text, "Location State" text, "Location Zip" text);
  3. Import from downloaded csv (instructions here http://www.sqlite.org/cvstrac/wiki?p=ImportingFiles )

    sqlite> .separator ","
    sqlite> .import name_of_downloaded_csv_file.csv biz
  4. Filter to just the counties in New York City:

    sqlite> delete from biz where County != 'BRONX' AND County != 'KINGS' AND County != 'NEW YORK' AND County != 'QUEENS' AND County != 'RICHMOND';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment