instascraper 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 instascraper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Andrew Nesbitt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/Readme.md ADDED
@@ -0,0 +1,41 @@
1
+ # Instascraper
2
+
3
+ This library provides a basic api to instapaper bookmarks for free by scraping the page
4
+
5
+ n.b. this is a work in progress, you probably shouldn't use it.
6
+
7
+ gem install instascraper
8
+
9
+ require 'instascraper'
10
+
11
+ i = Instascraper.new('username', 'password')
12
+
13
+ # load unread bookmarks
14
+ bookmarks = i.bookmarks
15
+
16
+ bookmarks.each do |b|
17
+ puts b.link
18
+ puts b.title
19
+ end
20
+
21
+ # folder support
22
+ folder_bookmarks = i.bookmarks('folder name')
23
+
24
+ ## Development
25
+
26
+ Source hosted at [GitHub](http://github.com/andrew/instascraper).
27
+ Report Issues/Feature requests on [GitHub Issues](http://github.com/andrew/instascraper/issues).
28
+
29
+ ### Note on Patches/Pull Requests
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix.
33
+ * Add tests for it. This is important so I don't break it in a
34
+ future version unintentionally.
35
+ * Commit, do not mess with rakefile, version, or history.
36
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
37
+ * Send me a pull request. Bonus points for topic branches.
38
+
39
+ ## Copyright
40
+
41
+ Copyright (c) 2011 Andrew Nesbitt. See [LICENSE](https://github.com/andrew/instascraper/blob/master/LICENSE) for details.
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "instascraper/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "instascraper"
7
+ s.version = Instascraper::VERSION
8
+ s.authors = ["Andrew Nesbitt"]
9
+ s.email = ["andrewnez@gmail.com"]
10
+ s.homepage = "http://github.com/andrew/instascraper"
11
+ s.summary = "Basic, free bookmarks api for instapaper"
12
+ s.description = "A scraper for instapaper to provide a basic api without hacing to pay per month"
13
+
14
+ s.rubyforge_project = "instascraper"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'mechanize'
22
+ end
@@ -0,0 +1,47 @@
1
+ require "instascraper/version"
2
+ require "instascraper/bookmark"
3
+ require 'mechanize'
4
+
5
+ class Instascraper
6
+ def initialize(username, password = '')
7
+ @agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
8
+
9
+ @agent.get('http://www.instapaper.com/user/login/') do |page|
10
+ form = page.form
11
+ form.texts.first.value = username
12
+ form.password = password
13
+ form.submit
14
+ end
15
+ end
16
+
17
+ def bookmarks(folder = nil)
18
+ if folder
19
+ home = @agent.get('http://www.instapaper.com/u/')
20
+ path = home.link_with(:text => folder).href
21
+ else
22
+ path = '/u'
23
+ end
24
+
25
+ bookmarks = []
26
+ more_pages = true
27
+ current_page = nil
28
+
29
+ while more_pages do
30
+ page = @agent.get("http://www.instapaper.com#{path}/#{current_page}")
31
+
32
+ page.parser.css('.tableViewCell').each do |bookmark|
33
+ bookmark.css('.tableViewCellTitleLink').first['href']
34
+
35
+ bookmarks << Bookmark.new(bookmark.css('.tableViewCellTitleLink').first['href'], bookmark.css('.tableViewCellTitleLink').first.text)
36
+ end
37
+
38
+ if page.link_with :text => /Older items/
39
+ current_page = (current_page ? current_page + 1 : 1 )
40
+ else
41
+ more_pages = false
42
+ end
43
+ end
44
+
45
+ return bookmarks
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ class Instascraper
2
+ class Bookmark
3
+ attr_reader :link
4
+ attr_reader :title
5
+
6
+ def initialize(link, title)
7
+ @link = link
8
+ @title = title
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class Instascraper
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instascraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Nesbitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &70231649735820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70231649735820
25
+ description: A scraper for instapaper to provide a basic api without hacing to pay
26
+ per month
27
+ email:
28
+ - andrewnez@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE
36
+ - Rakefile
37
+ - Readme.md
38
+ - instascraper.gemspec
39
+ - lib/instascraper.rb
40
+ - lib/instascraper/bookmark.rb
41
+ - lib/instascraper/version.rb
42
+ homepage: http://github.com/andrew/instascraper
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: instascraper
62
+ rubygems_version: 1.8.6
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Basic, free bookmarks api for instapaper
66
+ test_files: []