twitter_instapaper 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 twitter_instapaper.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ h1. twitter_instapaper
2
+
3
+ by Brad Bollenbach
4
+
5
+ twitter_instapaper extracts links from favourited tweets and sends them to Instapaper.
6
+
7
+ h2. Install
8
+
9
+ <pre>
10
+ $ twit_inst --configure
11
+ Twitter username: 30sleeps
12
+ Instapaper username: bradb@30sleeps.com
13
+ Instapaper password: somepass
14
+ Configuration saved successfully.
15
+ </pre>
16
+
17
+ The install twit_inst into your crontab:
18
+
19
+ <pre>
20
+ $ crontab -e
21
+ </pre>
22
+
23
+ To check your Twitter feed every 5 minutes for new favourites:
24
+
25
+ <pre>
26
+ # This is what works for my rvm-based setup!
27
+ */5 * * * * bash --login -c twit_inst
28
+ </pre>
29
+
30
+ twit_inst only polls your latest 20 favourites each time, so you should ensure your cron job is set at a reasonable enough interval that no favourites will be missed.
31
+
32
+ Please email any feedback or bug reports to "bradb@30sleeps.com":mailto:bradb@30sleeps.com.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'twitter'
4
+ require 'httparty'
5
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "twitter_instapaper")
6
+
7
+ $verbose = false
8
+
9
+ def verbose(msg, level=1)
10
+ if $verbose
11
+ puts "* #{msg}" if level == 1
12
+ puts " -> #{msg}" if level == 2
13
+ end
14
+ end
15
+
16
+ def send_links_from_fav_tweets_to_instapaper
17
+ TwitterInstapaper::Config.load!
18
+
19
+ seen_fav_ids = Set.new
20
+ favourites = Twitter.favorites(TwitterInstapaper::Config.twitter_username)
21
+ verbose("found #{favourites.size} latest favourites for user #{TwitterInstapaper::Config.twitter_username}")
22
+ favourites.each_with_index do |f, i|
23
+ seen_fav_ids << f.id_str
24
+ if TwitterInstapaper::Config.last_seen_fav_ids.include?(f.id_str)
25
+ verbose("skipping ##{i + 1} '#{f.text}', already seen")
26
+ next
27
+ end
28
+ verbose("scanning #{f.text} for urls to extract")
29
+ f.text.scan(%r{http(?:s?)://[^ ]+}).each do |url|
30
+ verbose("found #{url}, sending to instapaper", 2)
31
+ HTTParty.post("https://www.instapaper.com/api/add",
32
+ :query => { :url => url, :username => TwitterInstapaper::Config.instapaper_username,
33
+ :password => TwitterInstapaper::Config.instapaper_password })
34
+ end
35
+ end
36
+ verbose("updating config with #{seen_fav_ids.size} latest seen ids")
37
+ TwitterInstapaper::Config.update_last_seen_fav_ids!(seen_fav_ids)
38
+ end
39
+
40
+ def collect_config_info
41
+ config = {}
42
+ %w(twitter_username instapaper_username instapaper_password).each do |needed_value|
43
+ while config[needed_value].nil? || config[needed_value] == ""
44
+ print "#{needed_value.sub(/_/, " ").capitalize}: "
45
+ config[needed_value] = gets.strip
46
+ end
47
+ end
48
+
49
+ config
50
+ end
51
+
52
+ options = TwitterInstapaper::parse_cmd_line_options!
53
+
54
+ $verbose = options[:verbose]
55
+
56
+ if options[:configure]
57
+ TwitterInstapaper::Config.save!(collect_config_info)
58
+ puts "Configuration saved successfully."
59
+ else
60
+ send_links_from_fav_tweets_to_instapaper
61
+ end
@@ -0,0 +1,66 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+
4
+ module TwitterInstapaper
5
+ CONFIG_FILENAME = File.expand_path("~/.twitter-instapaper")
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 'twit_inst --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: twit_inst [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 at runtime") do |c|
59
+ options[:verbose] = true
60
+ end
61
+ end.parse!
62
+
63
+ options
64
+ end
65
+
66
+ end
@@ -0,0 +1,3 @@
1
+ module TwitterInstapaper
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "twitter_instapaper/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "twitter_instapaper"
7
+ s.version = TwitterInstapaper::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/twitter_instapaper"
12
+ s.summary = %q{Extract links from favourited 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 install twitter_instapaper, please see docs at:
19
+ https://github.com/bradb/twitter_instapaper
20
+
21
+ ********************************************************************************
22
+ SETUP
23
+
24
+ s.rubyforge_project = "twitter_instapaper"
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
30
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter_instapaper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
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
+ - twit_inst
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - Gemfile
62
+ - README.textile
63
+ - Rakefile
64
+ - bin/twit_inst
65
+ - lib/twitter_instapaper.rb
66
+ - lib/twitter_instapaper/version.rb
67
+ - twitter_instapaper.gemspec
68
+ has_rdoc: true
69
+ homepage: https://github.com/bradb/twitter_instapaper
70
+ licenses: []
71
+
72
+ post_install_message: |
73
+ ********************************************************************************
74
+
75
+ To install twitter_instapaper, please see docs at:
76
+ https://github.com/bradb/twitter_instapaper
77
+
78
+ ********************************************************************************
79
+
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: twitter_instapaper
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Extract links from favourited tweets and send them to Instapaper
107
+ test_files: []
108
+