Last active
August 29, 2015 13:56
-
-
Save Najaf/8983235 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)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
OK, good start, a couple of things that might help you crack this one:
Creating and adding to arrays
This is a perfectly valid way of creating an array:
But unless you've got a good reason for doing so (you want to set an initial size and default value), we usually just do this:
Adding things to an array with my_array.push(thing_to_add) is perfectly idiomatic Ruby, my personal preferences is to use the double arrows instead:
Indentation
You're almost definitely going to get confused about which do..end block you're in if you're indenting as you go!
Other notes