<commit_before>#!/bin/env node
//  OpenShift sample Node application
var express = require('express');
var fs      = require('fs');
// var d       = require('./twitterData.js');
//
var envVars = "";

if (!process.env.TWITTER_CONSUMER_KEY) {
  envVars = require("./envVars.js");
  envVars.add();
}

var d = {
  html: [],
  rawTweets: [],
  getData: function (req, res, spec) {
    var Twitter = require("twitter");

    var client = new Twitter({
      consumer_key: process.env.TWITTER_CONSUMER_KEY,
      consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
      access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
      access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
    });

    var geocode = spec ? spec : '40.7207919,-74.0007582,0.5km';

    var now = new Date(),
      year = now.getFullYear(),
      month = now.getMonth() + 1, // js months are zero based
      day = now.getDate() - 2,    // only show day old tweets
      twoDaysAgo = year + "-" + month + "-" + day;

    /*
     *  geocode: lat,lon,radius
     *  count: defaults to 15, max is 100
     *  result_type: recent, popular, mixed
     *  until: 2012-09-01 // tweets before date
     */
    var options = {
      geocode: geocode,
      count: 100,
      until: twoDaysAgo
    };

    client.get('search/tweets', options, function(error, params,
        response){

      var tweetList = [],
        tweetHtml = "",
        rawTweet,
        newTweet,
        results;

      if (error) {
        console.log("error: " + JSON.stringify(error));
        console.log();
        throw error;
      }

      if (params && params.hasOwnProperty("statuses")) {
        results = params.statuses;

        d.rawTweets = results;

        for (var i = 0, l = results.length; i < l; i++) {
          rawTweet = results[i];

          // d.getTweetWidget(req, res, rawTweet.id_str);
          newTweet = {
            id          : rawTweet.id_str,
            lat         : rawTweet.geo.coordinates[0],
            lon         : rawTweet.geo.coordinates[1],
            text        : rawTweet.text,
            datetime    : rawTweet.created_at,
            screen_name : rawTweet.user.screen_name
          };

          tweetHtml += "<div class='tweet'>" +
              "<div>latitude: " + newTweet.lat + "</div>" +
              "<div>longitude: "+ newTweet.lon + "</div>" +
              "<div>text: "+ newTweet.text + "</div>" +
              "<div>date: "+ newTweet.datetime + "</div>" +
              "<div>screen_name: "+ newTweet.screen_name + "</div>" +
              "</div>";

          tweetList[i] = newTweet;
        }

        res.setHeader('Content-Type', 'text/html');
        res.send("<html><head>" +
            "<style>.tweet{border:1px solid black; padding:1rem;}</style>" +
            "<body>" + tweetHtml + "</body></html>");
        // res.send(JSON.stringify(tweetList));

      } else {
        res.setHeader('Content-Type', 'text/html');
        res.send("fail");
      }
      // console.log(JSON.stringify(response));  // Raw response object.?
    });
  },
  getTweetWidget: function (req, res, tweetId) {
    var Twitter = require("twitter");

    var client = new Twitter({
      consumer_key: process.env.TWITTER_CONSUMER_KEY,
      consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
      access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,<commit_msg>added tweets as json to page<commit_after>#!/bin/env node
//  OpenShift sample Node application
var express = require('express');
var fs      = require('fs');
// var d       = require('./twitterData.js');
//
var envVars = "";

if (!process.env.TWITTER_CONSUMER_KEY) {
  envVars = require("./envVars.js");
  envVars.add();
}

var d = {
  html: [],
  rawTweets: [],
  getData: function (req, res, spec) {
    var Twitter = require("twitter");

    var client = new Twitter({
      consumer_key: process.env.TWITTER_CONSUMER_KEY,
      consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
      access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
      access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
    });

    var geocode = spec ? spec : '40.7207919,-74.0007582,0.5km';

    var now = new Date(),
      year = now.getFullYear(),
      month = now.getMonth() + 1, // js months are zero based
      day = now.getDate() - 2,    // only show day old tweets
      twoDaysAgo = year + "-" + month + "-" + day;

    /*
     *  geocode: lat,lon,radius
     *  count: defaults to 15, max is 100
     *  result_type: recent, popular, mixed
     *  until: 2012-09-01 // tweets before date
     */
    var options = {
      geocode: geocode,
      count: 100,
      until: twoDaysAgo
    };

    client.get('search/tweets', options, function(error, params,
        response){

      var tweetList = [],
        tweetHtml = "",
        rawTweet,
        newTweet,
        results;

      if (error) {
        console.log("error: " + JSON.stringify(error));
        console.log();
        throw error;
      }

      if (params && params.hasOwnProperty("statuses")) {
        results = params.statuses;

        d.rawTweets = results;

        for (var i = 0, l = results.length; i < l; i++) {
          rawTweet = results[i];

          // d.getTweetWidget(req, res, rawTweet.id_str);
          newTweet = {
            id          : rawTweet.id_str,
            lat         : rawTweet.geo.coordinates[0],
            lon         : rawTweet.geo.coordinates[1],
            text        : rawTweet.text,
            datetime    : rawTweet.created_at,
            screen_name : rawTweet.user.screen_name
          };

          tweetHtml += "<div class='tweet'>" +
              "<div>latitude: " + newTweet.lat + "</div>" +
              "<div>longitude: "+ newTweet.lon + "</div>" +
              "<div>text: "+ newTweet.text + "</div>" +
              "<div>date: "+ newTweet.datetime + "</div>" +
              "<div>screen_name: "+ newTweet.screen_name + "</div>" +
              "</div>";

          tweetList[i] = newTweet;
        }

        res.setHeader('Content-Type', 'text/html');
        res.send("<html><head>" +
            "<style>.tweet{border:1px solid black; padding:1rem;}</style>" +
            "<body>" + tweetHtml +
            "<script>var data = " + JSON.stringify(tweetList) + ";</script>" +
            "</body></html>");
        // res.send(JSON.stringify(tweetList));

      } else {
        res.setHeader('Content-Type', 'text/html');
        res.send("fail");
      }
      // console.log(JSON.stringify(response));  // Raw response object.?
    });
  },
  getTweetWidget: function (req, res, tweetId) {
    var Twitter = require("twitter");

    var client = new Twitter({
      consumer_key: process.env.TWITTER_CONSUMER_KEY,
      consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
      access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
{'fraction_non_alphanumeric': 0.15078671328671328, 'fraction_numerical': 0.01252913752913753, 'mean_word_length': 2.0909500225123816, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5639741', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2224, 'n_words': 434}