instafavs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in instafavs.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1 @@
1
+ Extract links from favorited tweets and send them to Instapaper.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/instafavs ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'twitter'
4
+ require 'httparty'
5
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "instafavs")
6
+
7
+ $verbose = false
8
+
9
+ def verbose(msg)
10
+ puts msg if $verbose
11
+ end
12
+
13
+ def send_links_from_fav_tweets_to_instapaper
14
+ Instafavs::Config.load!
15
+
16
+ seen_fav_ids = Set.new
17
+ favorites = Twitter.favorites(Instafavs::Config.twitter_username)
18
+ verbose("found #{favorites.size} latest favorites for user #{Instafavs::Config.twitter_username}")
19
+ favorites.each do |f|
20
+ seen_fav_ids << f.id_str
21
+ next if Instafavs::Config.last_seen_fav_ids.include?(f.id_str)
22
+ f.text.scan(%r{http(?:s?)://[^ ]+}).each do |url|
23
+ HTTParty.post("https://www.instapaper.com/api/add",
24
+ :query => { :url => url, :username => Instafavs::Config.instapaper_username,
25
+ :password => Instafavs::Config.instapaper_password })
26
+ end
27
+ end
28
+ Instafavs::Config.update_last_seen_fav_ids!(seen_fav_ids)
29
+ end
30
+
31
+ def collect_config_info
32
+ config = {}
33
+ %w(twitter_username instapaper_username instapaper_password).each do |needed_value|
34
+ while config[needed_value].nil? || config[needed_value] == ""
35
+ print "#{needed_value.sub(/_/, " ").capitalize}: "
36
+ config[needed_value] = gets.strip
37
+ end
38
+ end
39
+
40
+ config
41
+ end
42
+
43
+ options = Instafavs::parse_cmd_line_options!
44
+
45
+ $verbose = options[:verbose]
46
+
47
+ if options[:configure]
48
+ Instafavs::Config.save!(collect_config_info)
49
+ puts "Your configuration has been saved."
50
+ else
51
+ send_links_from_fav_tweets_to_instapaper
52
+ end
data/instafavs.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "instafavs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "instafavs"
7
+ s.version = Instafavs::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brad Bollenbach"]
10
+ s.email = ["bradb@30sleeps.com"]
11
+ s.homepage = "https://github.com/bradb/instafavs"
12
+ s.summary = %q{Extract links from favorited tweets and send them to Instapaper}
13
+ s.add_dependency("twitter", ">= 1.1.2")
14
+ s.add_dependency("httparty", ">= 0.7.3")
15
+ s.post_install_message = <<SETUP
16
+ ********************************************************************************
17
+
18
+ To setup instafavs, follow these steps:
19
+
20
+ 1. Run instafavs --configure. Fill in the info required.
21
+
22
+ 2. Install instafavs into your crontab, e.g.
23
+
24
+ $ crontab -e
25
+
26
+ to check your Twitter feed every 5 minutes for new favorites, add this line:
27
+
28
+ */5 * * * * /path/to/instafavs
29
+
30
+ Please email any feedback or bug reports to bradb@30sleeps.com.
31
+
32
+ ********************************************************************************
33
+ SETUP
34
+
35
+ s.rubyforge_project = "instafavs"
36
+
37
+ s.files = `git ls-files`.split("\n")
38
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
39
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
40
+ s.require_paths = ["lib"]
41
+ end
@@ -0,0 +1,3 @@
1
+ module Instafavs
2
+ VERSION = "0.0.1"
3
+ end
data/lib/instafavs.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+
4
+ module Instafavs
5
+ CONFIG_FILENAME = File.expand_path("~/.instafavs")
6
+
7
+ module Config
8
+
9
+ class << self
10
+
11
+ def save!(config=nil)
12
+ config_to_save = config.nil? ? @config : config
13
+
14
+ File.open(CONFIG_FILENAME, "w+") do |f|
15
+ f.chmod(0600)
16
+ f.write(YAML.dump(config_to_save))
17
+ end
18
+ end
19
+
20
+ def load!
21
+ raise "missing configuration file. run 'instafavs --configure'." unless File.exists?(CONFIG_FILENAME)
22
+ @config = YAML.load_file(CONFIG_FILENAME)
23
+ end
24
+
25
+ def twitter_username
26
+ @config["twitter_username"]
27
+ end
28
+
29
+ def instapaper_username
30
+ @config["instapaper_username"]
31
+ end
32
+
33
+ def instapaper_password
34
+ @config["instapaper_password"]
35
+ end
36
+
37
+ def last_seen_fav_ids
38
+ @last_seen_fav_ids ||= @config["last_seen_fav_ids"] || Set.new
39
+ end
40
+
41
+ def update_last_seen_fav_ids!(seen_fav_ids)
42
+ @config["last_seen_fav_ids"] = seen_fav_ids.to_a.join(",")
43
+ save!
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ def self.parse_cmd_line_options!
50
+ options = {}
51
+ OptionParser.new do |opts|
52
+ opts.banner = "Usage: instafavs [options]"
53
+
54
+ opts.on("-c", "--configure", "Configure Twitter and Instapaper account details") do |c|
55
+ options[:configure] = true
56
+ end
57
+
58
+ opts.on("-v", "--verbose", "Provide more detailed output of what instafavs is doing") do |c|
59
+ options[:verbose] = true
60
+ end
61
+ end.parse!
62
+
63
+ options
64
+ end
65
+
66
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instafavs
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Brad Bollenbach
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-05 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: twitter
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 1
31
+ - 2
32
+ version: 1.1.2
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: httparty
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 7
46
+ - 3
47
+ version: 0.7.3
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description:
51
+ email:
52
+ - bradb@30sleeps.com
53
+ executables:
54
+ - instafavs
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - Gemfile
62
+ - README
63
+ - Rakefile
64
+ - bin/instafavs
65
+ - instafavs.gemspec
66
+ - lib/instafavs.rb
67
+ - lib/instafavs/version.rb
68
+ has_rdoc: true
69
+ homepage: https://github.com/bradb/instafavs
70
+ licenses: []
71
+
72
+ post_install_message: |
73
+ ********************************************************************************
74
+
75
+ To setup instafavs, follow these steps:
76
+
77
+ 1. Run instafavs --configure. Fill in the info required.
78
+
79
+ 2. Install instafavs into your crontab, e.g.
80
+
81
+ $ crontab -e
82
+
83
+ to check your Twitter feed every 5 minutes for new favorites, add this line:
84
+
85
+ */5 * * * * /path/to/instafavs
86
+
87
+ Please email any feedback or bug reports to bradb@30sleeps.com.
88
+
89
+ ********************************************************************************
90
+
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project: instafavs
114
+ rubygems_version: 1.3.7
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Extract links from favorited tweets and send them to Instapaper
118
+ test_files: []
119
+