Data of New York

Here’s the latest addition to my Creative Bots project. Data of New York is a pair of Twitter and Mastodon bots that let you explore the city of New York with maps made with Mapbox and NYC Open Data.

The bot looks through datasets on NYC OpenData using the Socrata Discovery API.

const dataSource = 'data.cityofnewyork.us';
const dataType = helpers.randomFromArray( [
  'datasets',
  'map'
] );

const dataLimit = '1000';
const discoveryUrl = `http://api.us.socrata.com/api/catalog/v1?domains=${ dataSource }&search_context=${ dataSource }&only=${ dataType }&limit=${ dataLimit }`;

console.log( `finding a dataset in the ${ dataSource } domain (${ dataType })` );

Originally I wanted to create charts using the data, sort of an automated version of @last100bills, but this is a bit tricky to get right, as most datasets have too many columns, and the charts would be pretty unreadable. I’m still going to keep looking into this, but for now the bot looks for datasets that contain location information, such as latitude and longitude, or a zip code, and uses it to generate maps.

With Google starting to charge for their Static Maps service, I’ve decided to go with Mapbox for this project.

data.forEach( function( datapoint ){
  if ( datapoint.longitude && datapoint.latitude ){
    markers.push( `pin-s+555555(${ datapoint.longitude },${ datapoint.latitude })` )
  } else if ( datapoint.lon && datapoint.lat ){
    markers.push( `pin-s+555555(${ datapoint.lon },${ datapoint.lat })` )
  } else if ( datapoint.location && datapoint.location.longitude && datapoint.location.latitude ){
    markers.push( `pin-s+555555(${ datapoint.location.longitude },${ datapoint.location.latitude })` )
  }
} );

const mapUrl = `https://api.mapbox.com/styles/v1/mapbox/light-v10/static/${ markers.join( ',' ) }/auto/900x600?access_token=${ process.env.MAPBOX_ACCESS_TOKEN }`;

Because of limitations of Mapbox, I am using a randomly selected subset of 100 datapoints, otherwise the map URL becomes too long.

data = helpers.randomFromArrayUnique( data, 100 );

It’s pretty straightforward to create your own version of the bot for your city, as long as it’s part of the OpenData network.

const dataSource = 'data.cityofnewyork.us';
const dataType = helpers.randomFromArray( [
  'datasets',
  'map'
] );

const dataLimit = '1000';
const discoveryUrl = `http://api.us.socrata.com/api/catalog/v1?domains=${ dataSource }&search_context=${ dataSource }&only=${ dataType }&limit=${ dataLimit }`;

You can follow the bot on Twitter and botsin.space.

A tinted screenshot of a section of the jointhefediverse.net explaining how the fediverse works.

Join The Fediverse.net

A gentled introduction to the future of social media.

#explainer #fediverse #social-media

A screenshot of Kaelin Ellis playing a keyboard in a video for his song Peanuts.

💻 Browse all