<commit_before>#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require 'rubygems'
require 'oauth'
require 'json'
require 'open-uri'
require 'pp'

CONSUMER_KEY = ENV['PROMPTWEET_CONSUMER_KEY']
CONSUMER_SECRET = ENV['PROMPTWEET_CONSUMER_SECRET']
ACCESS_TOKEN = ENV['PROMPTWEET_ACCESS_TOKEN']
ACCESS_TOKEN_SECRET = ENV['PROMPTWEET_ACCESS_TOKEN_SECRET']

EXPIRED_TIME = 60 * 60 * 24

class Tweet
  def initialize(status)
    @status = status
  end

  def get_status_id
    return @status['id']
  end

  def get_user
    return @status['user']['screen_name']
  end

  def get_created_time
    return Time.parse(@status['created_at'])
  end

  def is_expired(second)
    return (Time.now - second > get_created_time)
  end
end

class TwitterSession
  def initialize
    consumer = OAuth::Consumer.new(CONSUMER_KEY,
                                   CONSUMER_SECRET,
                                   :site => 'http://twitter.com')

    @access_token = OAuth::AccessToken.new(consumer,
                                          ACCESS_TOKEN,
                                          ACCESS_TOKEN_SECRET)
    raise unless @access_token != nil
  end

  def get(url)
    return @access_token.get(url)
  end

  def post(url)
    return @access_token.post(url)
  end

  def get_user_timeline(count)
    return get("http://twitter.com/statuses/user_timeline.json?count=#{count}")
  end

  def delete_status(status_id)
    return post("http://twitter.com/statuses/destroy/#{status_id}.json")
  end

  def delete(tweet)
    return delete_status(tweet.get_status_id)
  end
end

def main
  twitter_session = TwitterSession.new

  loop do
    begin
      response = twitter_session.get_user_timeline(200)
      # TODO: is it ok to use a fixed count?
    rescue
      break
    end

    begin
      JSON.parse(response.body).each_with_index do |status, index|
        tweet = Tweet.new(status)
        if (tweet.is_expired(EXPIRED_TIME))<commit_msg>Supported new Twitter APIs<commit_after>#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require 'rubygems'
require 'oauth'
require 'json'
require 'open-uri'
require 'pp'

CONSUMER_KEY = ENV['PROMPTWEET_CONSUMER_KEY']
CONSUMER_SECRET = ENV['PROMPTWEET_CONSUMER_SECRET']
ACCESS_TOKEN = ENV['PROMPTWEET_ACCESS_TOKEN']
ACCESS_TOKEN_SECRET = ENV['PROMPTWEET_ACCESS_TOKEN_SECRET']

EXPIRED_TIME = 60 * 60 * 24

class Tweet
  def initialize(status)
    @status = status
  end

  def get_status_id
    return @status['id']
  end

  def get_user
    return @status['user']['screen_name']
  end

  def get_created_time
    return Time.parse(@status['created_at'])
  end

  def is_expired(second)
    return (Time.now - second > get_created_time)
  end
end

class TwitterSession
  def initialize
    consumer = OAuth::Consumer.new(CONSUMER_KEY,
                                   CONSUMER_SECRET,
                                   :site => 'http://twitter.com')

    @access_token = OAuth::AccessToken.new(consumer,
                                          ACCESS_TOKEN,
                                          ACCESS_TOKEN_SECRET)
    raise unless @access_token != nil
  end

  def get(url)
    return @access_token.get(url)
  end

  def post(url)
    return @access_token.post(url)
  end

  def get_user_timeline(count)
    return get("https://api.twitter.com/1.1/statuses/user_timeline.json?count=#{count}")
  end

  def delete_status(status_id)
    return post("https://api.twitter.com/1.1/statuses/destroy/#{status_id}.json")
  end

  def delete(tweet)
    return delete_status(tweet.get_status_id)
  end
end

def main
  twitter_session = TwitterSession.new

  loop do
    begin
      # TODO: is it ok to use a fixed count?
      response = twitter_session.get_user_timeline(200)
      break if response.class.name != Net::HTTPOK
    rescue
      break
    end

    begin
      JSON.parse(response.body).each_with_index do |status, index|
        tweet = Tweet.new(status)
        if (tweet.is_expired(EXPIRED_TIME))
{'fraction_non_alphanumeric': 0.09997462572951028, 'fraction_numerical': 0.006089824917533621, 'mean_word_length': 2.7223796033994336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2106407', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1315, 'n_words': 266}