Created
February 13, 2014 19:31
-
-
Save Najaf/8982139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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