Created
December 4, 2011 00:39
-
-
Save MadBomber/1428645 to your computer and use it in GitHub Desktop.
A way to manage RubyGems worthy of investigation using Twitter's Favorite tweets
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
#!/bin/env ruby | |
############################################### | |
## extract_fav_gems.rb | |
## An html file obtained from twitter.com is passed | |
## on the command line. The file is the favorite tweets | |
## of a specific user. Tweets from RubyGems are reviewed | |
## abd the gem name extracted. If the gem is not currently | |
## installed it will be nominated for installation. Gems | |
## are not installed automatically. The gem install command | |
## line containing the nominated gems is printed to stdout | |
## so that the user can copy/paste as a command if desired. | |
usage_msg = <<EOS | |
Extract favorite tweets of nominated Ruby gems worth investigation | |
Usage: #{$0} <filename> | |
where <filename> is the complete path to an HTML file obtained | |
twitter.com of the list of favorite tweets. | |
EOS | |
if ARGV.empty? | |
puts usage_msg | |
exit | |
end | |
require 'pathname' | |
require 'systemu' | |
signal_line = 'rubygems</a>' | |
favorites_file = Pathname.new ARGV[0] | |
unless favorites_file.exist? | |
puts "\nERROR: #{favorites_file} does not exist" | |
puts usage_msg | |
exit(-1) | |
end | |
fav_gems = Array.new | |
extract_next_line = 0 | |
puts "Extracting RubyGem Names from Webpage" | |
favorites_file.readlines.each do |a_line| | |
extract_next_line -= 1 | |
if 0 == extract_next_line | |
gem_name = a_line.split()[0] | |
fav_gems << gem_name unless fav_gems.include? gem_name | |
elsif a_line.chomp == signal_line | |
# MAGIC: 3 is how many lines to skip after finding the signal line before | |
# the line that contains the gem name is found. | |
extract_next_line = 3 | |
end | |
end | |
puts "Obtaining Installed Gem Names" | |
a,gem_list,c = systemu 'gem list' | |
installed_gems = Array.new | |
gem_list.split("\n").each do |a_line| | |
installed_gems << a_line.split[0] | |
end | |
gem_install_command = "gem install" | |
fav_gems.each do |gem| | |
gem_install_command += " " + gem unless installed_gems.include? gem | |
end | |
# MAGIC: -2 accounts for the constant 'gem' and 'install' tokens | |
puts "Done. Found #{gem_install_command.split.length - 2} new gems worth investigating." | |
puts | |
puts gem_install_command | |
puts |
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
#!/bin/bash | |
# fav_tweets | |
# adapted by @MadBomber from | |
# Twitter status update bot by http://360percents.com | |
# Author: Luka Pusic <[email protected]> | |
# Limitations: only gets the first page of favorite tweets | |
# https://mobile.twitter.com/favorites | |
#REQUIRED PARAMS | |
username="[email protected]" # your eMail account known to twitter | |
password="mysecretpassword" # your secret password used to login to twitter | |
temp_favorites_file=$HOME/tmp/favorites.html | |
#EXTRA OPTIONS | |
uagent="Mozilla/5.0" #user agent (fake a browser) | |
sleeptime=0 #add pause between requests if necessary | |
touch "cookie.txt" #create a temp. cookie file | |
#INITIAL PAGE | |
echo "[+] Fetching twitter.com..." && sleep $sleeptime | |
initpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" "https://mobile.twitter.com/session/new"` | |
token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//'` | |
#LOGIN | |
echo "[+] Submitting the login form..." && sleep $sleeptime | |
loginpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" -d "authenticity_token=$token&username=$username&password=$password" "https://mobile.twitter.com/session"` | |
#HOME PAGE | |
echo "[+] Getting your twitter home page..." && sleep $sleeptime | |
homepage=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/"` | |
#Retrieve | |
echo "[+] Getting favorites..." && sleep $sleeptime | |
tweettoken=`echo "$homepage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//' | tail -n 1` | |
favorites=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" -d "authenticity_token=$tweettoken" "https://mobile.twitter.com/favorites"` | |
echo $favorites | sed 's/>/>\n/g' - > $temp_favorites_file | |
#LOGOUT | |
echo "[+] Logging out..." | |
logout=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/session/destroy"` | |
rm "cookie.txt" | |
# the extract_fav_gems.rb file must be in PATH and executable | |
extract_fav_gems.rb $temp_favorites_file | |
rm $temp_favorites_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On twitter I follow @rubygems inorder to watch for updated and newly published gems which might be worthy of investigation. If a description catches my eye, I will review the documentation and if its worthy I will mark the tweet as a "favorite" within twitter. Having done that, at some time in the future when I feel like playing, I will install these gems using the scripts in this gist.