Skip to content

Instantly share code, notes, and snippets.

@Najaf
Created February 13, 2014 19:32
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 Najaf/8982161 to your computer and use it in GitHub Desktop.
Save Najaf/8982161 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require "twitter"
require 'csv'
require 'regexp'
# Twitter setup was here...
#Gets the last 10 tweets from a given user from the twitter API
screen_name = String.new ARGV[0]
#for each tweet
tweet = client.user_timeline(screen_name, count: 10).each do |tweet|
#Look through each row in the CSV file to see if any words in the tweet match the words in the 2nd element of the csv array(the word)
csv = CSV.foreach("csvratings.csv", {:headers=>true}).each do |row|)
#For each line if the word matches words in the tweet then create a new array and put the valence mean value (3rd array element) in it.
if row[1].match(tweet /b)do
valence = array.new
valance.push(row[2])
#Find the average of the valence array to be ordered later
len = valence.length
total = valence.inject(:+)
average = total.to_f / len
#print out the tweet and their average valence number
puts tweet + average
#Alternative ending idea...
#average valence number needs to be ordered, not sure how to get these to correspond with the tweets...
all_averages = array.new
all_averages.push(average + tweet)
all_averages.sort
puts tweet + all_averages
#Notes:
#For the tweets each count search through the CSV loop,
#if any words match then assign them with the coresponding number in vmean[2] of the CSV array
#Find the valence avergage for the words in each line
#Assign them a value from 1 - 10 and print in that order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment