Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updating scripts for twitter.

  • Loading branch information...
commit d26bde18759f90a017b867bf8246d59f044b5eac 1 parent a217621
Jennifer Maldonado authored
19 twitter/R/arulesTwitter.r
View
@@ -0,0 +1,19 @@
+library("arules")
+library("arulesViz")
+t = read.transactions("C:/somethingnull/rapidminer/transacciones.basket", sep=',', cols=c(1), format="basket")
+image(tr)
+summary(tr)
+itemFrequencyPlot(tr, supp=0.1)
+itemFrequencyPlot(tr, supp=0.05)
+rules = apriori(tr, parameter= list(supp=0.1, conf=0.9))
+inspect(rules)
+par(cex=0.5)
+plot(rules, method="graph", control=list(type="items"))
+plot(rules, method="grouped")
+saveAsGraph(rules, file="rulestransaction01.graphml")
+rules = apriori(tr, parameter= list(supp=0.03, conf=0.9))
+inspect(rules)
+plot(rules, method="graph", control=list(type="items"))
+plot(rules, method="grouped")
+
+
19 twitter/R/wordcloudTwitterText.r
View
@@ -0,0 +1,19 @@
+#!/usr/local/bin/R
+library("tm")
+library("wordcloud")
+library("RColorBrewer")
+
+txt = DirSource('/media/misperoles/git/tools/twitter/data')
+tweets.corpus = Corpus(txt)
+tweets.corpus <- tm_map(tweets.corpus, removePunctuation)
+tweets.corpus <- tm_map(tweets.corpus, tolower)
+tweets.corpus <- tm_map(tweets.corpus, function(x) removeWords(x, stopwords("spanish")))
+tweets.corpus <- tm_map(tweets.corpus, function(x) removeWords(x, stopwords("english")))
+tdm <- TermDocumentMatrix(tweets.corpus)
+m <- as.matrix(tdm)
+v <- sort(rowSums(m),decreasing=TRUE)
+d <- data.frame(word = names(v),freq=v)
+pal2 <- brewer.pal(5,"Dark2")
+png("wordcloudTwitter.png", width=1280,height=800)
+wordcloud(d$word,d$freq, scale=c(6,.2),min.freq=5,max.words=Inf, random.order=FALSE, rot.per=.15, colors=pal2, ordered.colors=T, vfont=c("sans serif","plain"))
+dev.off()
85 twitter/ruby/gettingInfoTweet.rb
View
@@ -0,0 +1,85 @@
+# 180 por 15min
+# 720 por hora
+require 'xmlsimple'
+require 'twitter'
+#require 'pp'
+
+filename ='gatsby_5-7.xml'
+
+#reading xml
+config = XmlSimple.xml_in(filename)
+tweet_ids = Array.new
+
+#filename to save CSV
+fileout = File.new("twitter_gatsy.csv", "w")
+
+#saving ID's tweets
+config["node"].each do |val|
+ tweet_ids << val["ID"][0].to_s()
+end
+
+#This is you app devs info. sign in in https://dev.twitter.com/ with your twitter account and fill this.
+Twitter.configure do |config|
+ config.consumer_key = ''
+ config.consumer_secret = ''
+ config.oauth_token = ''
+ config.oauth_token_secret = ''
+end
+
+def addquote(word)
+ return "\"#{word}\""
+end
+
+save = Array.new
+
+#fields to save. if remove here, remove too in header CSV
+save = ["id_str", "created_at", "text", "source", "in_reply_to_status_id", "in_reply_to_user_id", "in_reply_to_screen_name", ];
+save_user = ["description", "name", "id_str","screen_name", "location","followers_count", "friends_count", "listed_count", "created_at", "favourites_count", "time_zone", "geo_enabled", "verified", "statuses_count", "lang", "is_translator","profile_background_color", "retweet_count", "favorite_count", "contributors"]
+save_entities_hashtag = ["text"]
+save_entities_url = ["expanded_url"]
+
+save_list = Array.new
+
+#header CSV
+header = 'id_str; created_at; text; source; in_reply_to_status_id; in_reply_to_user_id; in_reply_to_screen_name;user_description; user_name; user_id;user_screen_name; user_location;user_followers_count; user_friends_count; user_listed_count; user_created_at; user_favourites_count; user_time_zone; user_geo_enabled; user_verified; user_statuses_count; user_lang; user_is_translator;user_profile_background_color; user_retweet_count; user_favorite_count; user_contributors; hashtag_text; urls_expanded'
+
+#writing header in file
+fileout.puts header
+
+#search all id's info in twitter
+tweet_ids.each do |val|
+ #fetch status
+ begin
+ tweet = Twitter.status(val, {include_entities: "1"})
+ sleep(5)
+ #saving
+ save.each do |val|
+ save_list.push(addquote(tweet[val].to_s().gsub('\n', '')))
+ end
+
+ save_user.each do |val|
+ save_list.push(addquote(tweet["user"][val].to_s().gsub('\n', '')))
+ end
+
+ save_entities_hashtag.each do |val|
+ hashtags = Array.new
+ tweet.hashtags.each do |j|
+ hashtags.push(j[val])
+ end
+ save_list.push(addquote(hashtags.join(',').to_s().gsub('\n', '')))
+ end
+
+ save_entities_url.each do |val|
+ urls = Array.new
+ tweet.urls.each do |k|
+ urls.push(k[val])
+ end
+ save_list.push(addquote(urls.join(',').to_s().gsub('\n', '')))
+ end
+ line = save_list.join(';')
+ fileout.puts line
+ rescue Exception => msg
+ puts "#{msg} id #{val}"
+
+ end
+end
73 twitter/ruby/twitterStatus.rb
View
@@ -0,0 +1,73 @@
+# 180 por 15min
+# 720 por hora
+require 'twitter'
+
+tweet_ids = Array.new
+
+#filename to save CSV
+fileout = File.open("twitter_flisol2012.csv", "a")
+filein = File.open("idsflisol2012.txt");
+
+#saving ID's tweets
+filein.each_line do |line|
+ tweet_ids << line.to_s().chomp
+end
+
+
+#This is you app devs info. sign in in https://dev.twitter.com/ with your twitter account and fill this.
+Twitter.configure do |config|
+ config.consumer_key = ''
+ config.consumer_secret = ''
+ config.oauth_token = ''
+ config.oauth_token_secret = ''
+end
+
+def addquote(word)
+ return "\"#{word}\""
+end
+
+save = Array.new
+
+#fields to save. if remove here, remove too in header CSV
+#remove text
+save = ["id", "source" ];
+save_user = ["screen_name", "location","followers_count", "friends_count", "listed_count", "time_zone","lang"]
+
+
+#header CSV
+header = 'id; source; screen_name; location; followers_count; friends_count; listed_count; time_zone; lang'+"\n"
+
+save_list = Array.new
+#writing header in file
+fileout.puts header
+
+#search all id's info in twitter
+tweet_ids.each do |val|
+ #fetch status
+ begin
+ tweet = Twitter.status(val, {include_entities: "1"})
+ sleep(5)
+ #saving
+ save.each do |val|
+ save_list.push(addquote(tweet[val].to_s().gsub('\n', '').chomp))
+ end
+
+ save_user.each do |val|
+ save_list.push(addquote(tweet["user"][val].to_s().gsub('\n', '').chomp))
+ end
+
+ line = save_list.join(';')
+
+ line = line + "\n"
+
+## puts line
+
+ fileout.puts line
+
+ save_list.clear()
+ rescue Exception => msg
+ puts "#{msg} id #{val}"
+
+ end
+end
+fileout.close();
Please sign in to comment.
Something went wrong with that request. Please try again.