gofundme 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca7c8ac4582e6cd3585535b1a6644a8c464b6fb6ad1c32a079636a8dbfbafd5f
4
+ data.tar.gz: ff624b81c57420e4eaf1242fafb0d15b55ac0ac1694694411e6be9edbe6b22b9
5
+ SHA512:
6
+ metadata.gz: 01b3a6f48153911b9a4aefe223bacb55b9be2b3521182559c8ee07206b6cbecfa1f0822b6ec24b161434cb0258c2367cef9b38bf04e51ba0937e026aec884cba
7
+ data.tar.gz: 4148296bd034da99187624525c0f1892a11aaafb14d0f09f4c9c270ffd83dc6a4966cbcb41def5c69a558810c67c0cd6e0fd0cb836182386ca87d3cdb3dc3f51
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.16.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at speak@jjeff.us. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gofundme.gemspec
6
+ gemspec
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gofundme (0.1.0)
5
+ nokogiri
6
+ rest-client (>= 1.8.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ domain_name (0.5.20180417)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-cookie (1.0.3)
14
+ domain_name (~> 0.5)
15
+ mime-types (3.2.2)
16
+ mime-types-data (~> 3.2015)
17
+ mime-types-data (3.2018.0812)
18
+ mini_portile2 (2.4.0)
19
+ minitest (5.11.3)
20
+ netrc (0.11.0)
21
+ nokogiri (1.10.1)
22
+ mini_portile2 (~> 2.4.0)
23
+ rake (10.5.0)
24
+ rest-client (2.0.2)
25
+ http-cookie (>= 1.0.2, < 2.0)
26
+ mime-types (>= 1.16, < 4.0)
27
+ netrc (~> 0.8)
28
+ unf (0.1.4)
29
+ unf_ext
30
+ unf_ext (0.0.7.5)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ gofundme!
38
+ minitest (~> 5.0)
39
+ rake (~> 10.0)
40
+
41
+ BUNDLED WITH
42
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Janet Jeffus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,91 @@
1
+ # Gofundme
2
+
3
+ THE #1 Ruby library to scrape GoFundMe.com donation campaigns (called Projects by this library). GoFundMe does not have a publicly available API to query about donation lists, so this library scrapes information from GoFundMe's own mvc.php API using rest_client. This library is liable to break if GFM changes their API consumption endpoints
4
+
5
+ This Library is not associated to GoFundMe, Inc. in any way, shape, or form.
6
+
7
+ This description lifted from [the excellent Node.js library by 0nix](https://github.com/0nix/gofundme). Although the code is completely unrelated.
8
+
9
+ For a larger scale spider with Proxy support check this [Ruby and Javascript scraper with MongoDB back-end](https://github.com/asanteb/gofundme-scraper)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'gofundme'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install gofundme
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ require 'gofundme'
31
+
32
+ # Fetch an index for a search query
33
+ query = "transgender"
34
+ search = Gofundme::Search.new(query)
35
+ # => #<Gofundme::Search:0x000055c96dbe90d8 @results=1000, @pages=112, @query="transgender">
36
+ # Total pages for the query are in
37
+ puts "Total pages: #{search.pages}"
38
+ page_number = 1
39
+ # This returns an array of links
40
+ links = search.fetch_results(page_number)
41
+ # => ["https://www.gofundme.c...", ...]
42
+ links.length
43
+ # => 9
44
+ # Get the full project details
45
+ url = links.last
46
+ project = Gofundme::Project.scrape(url)
47
+ # => #<Gofundme::Project:0x000055c96dbcf2c8 @updates=[[1, ...
48
+ project.to_hash.keys
49
+ # => [:key, :category, :completed, :title, :name, :profile, :location, :image, :youtube, :vimeo, :images, :shares, :amount, :goal, :pounds, :euros, :goal_pounds, :goal_euros, :backers, :time, :trending, :english, :story_text, :story_html, :link_count, :updates_count, :created_at, :fb_shares, :updates]
50
+ ```
51
+
52
+ ## The More You Know
53
+
54
+ A Word about Gofundme::GOOD_CITIZEN_DELAY. The robots.txt on GoFundMe is very permissible. Many companies will go out of their way to prevent people from scraping their site. So far GoFundMe is making things very easy to access. They do NOT have to do this. There are a hundred ways they could make this harder and nobody wants that. Keeping this information accessible helps both GoFundMe and their customers by allowing research into how campaigns can be more successful. Please keep this number in place. Based on experimentation you will be banned by their site if you go lower than 5 seconds delay. It can be set like:
55
+
56
+ Gofundme::GOOD_CITIZEN_DELAY = 5
57
+
58
+ And yes you will get a redefined constant error.
59
+
60
+ You can set Gofundme::DEBUG to true and get some messages on STDERR.
61
+
62
+ One of three header elements will be set on a given Gofundme::Project profile page.
63
+
64
+ 1. :image -> if the user only sets a image as the project primary image
65
+ 2. :youtube -> if the user has set a YouTube video in the place of the primary image
66
+ 3. :vimeo -> if the user has set a Vimeo video in place of the primary image
67
+
68
+ If the project is in Euros or Pounds the values will automatically be converted into USD and set in amount and goal. This leaves the original amount raised in :pounds or :euros and the goals in :goal_pounds or :goal_euros. The conversion is based on.
69
+
70
+ 1. Gofundme::EURO_EXCHANGE_RATE = 1.13
71
+ 2. Gofundme::POUND_EXCHANGE_RATE = 1.31
72
+
73
+ These are in lib/gofundme.rb.
74
+
75
+ ## Development
76
+
77
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
78
+
79
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jjeffus/gofundme. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+
89
+ ## Code of Conduct
90
+
91
+ Everyone interacting in the Gofundme project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jjeffus/gofundme/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gofundme"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gofundme/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gofundme"
8
+ spec.version = Gofundme::VERSION
9
+ spec.authors = ["Janet Jeffus"]
10
+ spec.email = ["speak@jjeff.us"]
11
+
12
+ spec.summary = %q{Access data from GoFundMe.com site}
13
+ spec.description = %q{A library to scrape GoFundMe.com donation campaigns (called Projects). GoFundMe does not have a publicly available API to query about donation lists, so this library scrapes information from GoFundMe's own mvc.php API using rest_client. This library is liable to break if GFM changes their API consumption endpoints. This Library is not associated to GoFundMe, Inc. in any way, shape, or form and respects robots.txt.}
14
+ spec.homepage = "https://github.com/jjeffus/gofundme"
15
+ spec.license = "MIT"
16
+
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/jjeffus/gofundme"
22
+ spec.metadata["changelog_uri"] = "https://github.com/jjeffus/gofundme/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "nokogiri"
38
+ spec.add_dependency "rest-client", ">= 1.8.0"
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.16"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "minitest", "~> 5.0"
43
+ end
@@ -0,0 +1,13 @@
1
+ require "gofundme/version"
2
+ require "gofundme/project"
3
+ require "gofundme/search"
4
+
5
+ Gofundme::DEBUG = false
6
+ Gofundme::EURO_EXCHANGE_RATE = 1.13
7
+ Gofundme::POUND_EXCHANGE_RATE = 1.31
8
+ Gofundme::GOOD_CITIZEN_DELAY = 10
9
+
10
+ STDERR.puts "Debug is on" if Gofundme::DEBUG
11
+
12
+ module Gofundme
13
+ end
@@ -0,0 +1,213 @@
1
+ require 'nokogiri'
2
+ require 'rest-client'
3
+
4
+ module Gofundme
5
+ class Project
6
+ FIELDS = [:key, :category, :completed, :title, :name, :profile,
7
+ :location, :image, :youtube, :vimeo, :images, :shares,
8
+ :amount, :goal, :pounds, :euros, :goal_pounds, :goal_euros, :backers,
9
+ :time, :trending, :english, :story_text, :story_html,
10
+ :link_count, :updates_count, :created_at, :fb_shares, :updates]
11
+ FIELDS.each { |field| eval "attr_accessor :#{field}" }
12
+
13
+ def to_hash
14
+ hash = {}
15
+ FIELDS.each do |field|
16
+ hash[field]=self.send(field)
17
+ end
18
+ hash[:updates] = @updates
19
+ return hash
20
+ end
21
+
22
+ def initialize
23
+ @updates = []
24
+ end
25
+
26
+ def self.scrape(url)
27
+ STDERR.puts "Gofundme::Project.scrape(): Sleeping #{Gofundme::GOOD_CITIZEN_DELAY} seconds" if Gofundme::DEBUG
28
+ sleep Gofundme::GOOD_CITIZEN_DELAY
29
+ STDERR.puts "Gofundme::Project.scrape(): Fetching: #{url}" if Gofundme::DEBUG
30
+ p = Gofundme::Project.new
31
+ if url =~ /https:\/\/www.gofundme.com\/(.*)/i
32
+ p.key = $1
33
+ else
34
+ raise "Malformed URL #{url}"
35
+ end
36
+
37
+ begin
38
+ page = RestClient.get url
39
+ nok = Nokogiri::HTML(page)
40
+ p.completed = false
41
+ p.title = ''
42
+ p.name = ''
43
+ nok.xpath("//h1[@class='campaign-title']").each do |h1|
44
+ p.title = h1.inner_text.strip
45
+ end
46
+ if p.title == ''
47
+ nok.xpath("//h1[@class='campaign-title pb']").each do |h1|
48
+ p.title = h1.inner_text.strip
49
+ end
50
+ end
51
+ if p.title == nil
52
+ STDERR.puts "No title found! Exiting..." if Gofundme::DEBUG
53
+ raise "No title found"
54
+ end
55
+ nok.xpath("//img[@class='campaign-img']").each do |tag|
56
+ p.image = tag.attr('src')
57
+ end
58
+ nok.xpath("//iframe[@title='YouTube video player']").each do |iframe|
59
+ p.youtube = iframe.attr('src')
60
+ end
61
+ nok.xpath("//iframe[@media_type='2']").each do |iframe|
62
+ p.vimeo = iframe.attr('src')
63
+ end
64
+ p.images = p.image ? 1 : 0
65
+ nok.xpath("//div[@id='js-open-media-viewer']").each do |div|
66
+ if div.inner_text.strip =~ /(\d+)/
67
+ p.images = $1
68
+ end
69
+ end
70
+ p.shares = 0
71
+ nok.xpath("//strong[@class='js-share-count-text']").each do |strong|
72
+ if strong.inner_text.strip =~ /(\d+)/
73
+ p.shares = $1.to_i
74
+ end
75
+ end
76
+ p.amount = 0
77
+ p.pounds = 0
78
+ p.euros = 0
79
+ p.goal = 0
80
+ p.goal_pounds = 0
81
+ p.goal_euros = 0
82
+ nok.xpath("//h2[@class='goal']|//h2[@class='goal mb0']").each do |h2|
83
+ amount = 0
84
+ h2.xpath("./strong").each do |h2|
85
+ amount = h2.inner_text.strip
86
+ end
87
+
88
+ if amount =~ /^\$(.*)/
89
+ p.amount = $1.gsub(/,/, '').to_f
90
+ elsif amount =~ /^£(.*)/
91
+ p.pounds = $1.gsub(/,/, '').to_f
92
+ p.amount = p.pounds * Gofundme::POUND_EXCHANGE_RATE
93
+ elsif amount =~ /^€(.*)/
94
+ p.euros = $1.gsub(/,/, '').to_f
95
+ p.amount = p.euros * Gofundme::EURO_EXCHANGE_RATE
96
+ end
97
+
98
+ goal = 0
99
+ h2.xpath("./span").each do |span|
100
+ goal = span.inner_text.strip
101
+ end
102
+ if goal =~ /of \$((?:\d+|[,.])+)/
103
+ p.goal = $1.gsub(/,/, '').to_f
104
+ elsif goal =~ /of £((?:\d+|[,.])+)/
105
+ p.goal_pounds = $1.gsub(/,/, '').to_f
106
+ p.goal = p.goal_pounds * Gofundme::POUND_EXCHANGE_RATE
107
+ elsif goal =~ /of €((?:\d+|[,.])+)/
108
+ p.goal_euros = $1.gsub(/,/, '').to_f
109
+ p.goal = p.goal_euros * Gofundme::EURO_EXCHANGE_RATE
110
+ else
111
+ # no donations yet
112
+ if h2.attr('class') =~ /mb0/
113
+ p.completed = true
114
+ nok.xpath("//title").each do |title|
115
+ if title.inner_text.strip =~ /Fundraiser by ([^:]+):/
116
+ p.name = $1.strip
117
+ end
118
+ end
119
+ else
120
+ p.goal = p.amount
121
+ p.amount = nil
122
+ end
123
+ end
124
+ end
125
+ p.backers = 0
126
+ p.time = ''
127
+ nok.xpath("//div[@class='campaign-status text-small']").each do |div|
128
+ if div.inner_text =~ /Campaign created /
129
+ p.backers = 0
130
+ if div.inner_text =~ /Campaign created (\d+ \w+)/
131
+ p.time = $1
132
+ end
133
+ else
134
+ p.backers = div.xpath("./span").first.inner_text.to_i
135
+ if div.inner_text =~ /(?:people|person) in (\d+ \w+)/
136
+ p.time = $1
137
+ end
138
+ end
139
+ end
140
+ p.trending = false
141
+ nok.xpath("//div[@data-identifier='trending']").each do |div|
142
+ p.trending = true
143
+ end
144
+ p.story_html = ''
145
+ p.story_text = ''
146
+ p.link_count = 0
147
+ p.english = true
148
+ nok.xpath("//div[@id='story']/div[3]").each do |div|
149
+ p.story_html = div.inner_html.strip
150
+ p.link_count = 0
151
+ div.xpath(".//a").each do |a|
152
+ p.link_count += 1
153
+ end
154
+ if p.story_text =~ /Translate story to English/
155
+ p.english = false
156
+ else
157
+ p.story_text = div.inner_text.strip
158
+ end
159
+ end
160
+ p.updates_count = 0
161
+ # <a href="#updates" role="tab" aria-controls="updates" aria-selected="false" id="updates-label" tabindex="-1">Updates &nbsp; <span class="badge">3</span></a>
162
+ nok.xpath("//a[@href='#updates']/span").each do |span|
163
+ if span.inner_text =~ /(\d+)/
164
+ p.updates_count = $1.to_i
165
+ end
166
+ end
167
+ p.created_at = 0
168
+ nok.xpath("//div[@class='created-date']").each do |div|
169
+ p.created_at = div.inner_text.strip
170
+ end
171
+ p.fb_shares = ''
172
+ nok.xpath("//strong[@class='js-share-count-text']").each do |strong|
173
+ p.fb_shares = strong.inner_text.strip
174
+ end
175
+
176
+ p.profile = ''
177
+ nok.xpath("//a[@class='js-profile-co']").each do |a|
178
+ p.name = a.inner_text.strip
179
+ p.profile = a.attr('href')
180
+ end
181
+ p.category = ''
182
+ nok.xpath("//a[@class='icon-link category-link-name js-category-link']/span").each do |span|
183
+ p.category = span.inner_text.strip
184
+ end
185
+ p.location= ''
186
+ nok.xpath("//a[@class='icon-link location-name js-location-link']").each do |a|
187
+ a.xpath("./i").each do |i|
188
+ i.remove
189
+ end
190
+ p.location = a.inner_text.gsub(/^\W+/, '').strip
191
+ end
192
+
193
+ # Now parse out the updates
194
+ i = 1
195
+ nok.xpath("//div[@class='update-text']").each do |div|
196
+ update_text = div.inner_text.strip
197
+ update_html = div.inner_html.strip
198
+ links = 0
199
+ div.xpath(".//a").each do |a|
200
+ links += 1
201
+ end
202
+ p.updates.push [i, update_text, update_html, links]
203
+ i += 1
204
+ end
205
+
206
+ rescue Exception => e
207
+ puts "Exception: #{e}: #{e.backtrace}"
208
+ raise
209
+ end
210
+ return p
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,47 @@
1
+ require 'rest-client'
2
+ require 'cgi'
3
+
4
+ module Gofundme
5
+ class Search
6
+ attr_accessor :pages
7
+ attr_accessor :results
8
+
9
+ def initialize(query)
10
+ @results = 0
11
+ @pages = 0
12
+ @query = query
13
+ STDERR.puts "Sleeping #{Gofundme::GOOD_CITIZEN_DELAY} seconds" if Gofundme::DEBUG
14
+ sleep Gofundme::GOOD_CITIZEN_DELAY
15
+ url = "https://www.gofundme.com/mvc.php?route=category&term=\"#{CGI.escape(@query)}\""
16
+ STDERR.puts "Gofundme::Search::initialize(): Fetching: #{url}" if Gofundme::DEBUG
17
+ page = RestClient.get url
18
+ nok = Nokogiri::HTML(page)
19
+ nok.xpath("//h2").each do |h2|
20
+ if h2.inner_text.strip =~ /(\d+) results found/
21
+ @results = $1.to_i
22
+ end
23
+ end
24
+
25
+ # Site does not return more results than the first 1000 projects
26
+ if @results > 1000
27
+ @results = 1000
28
+ end
29
+
30
+ @pages = (@results / 9.0).ceil.to_i
31
+ end
32
+
33
+ def fetch_results(page_number)
34
+ STDERR.puts "Gofundme::Search::results(): Sleeping #{Gofundme::GOOD_CITIZEN_DELAY} seconds" if Gofundme::DEBUG
35
+ sleep Gofundme::GOOD_CITIZEN_DELAY
36
+ url = "https://www.gofundme.com/mvc.php?route=homepage_norma/load_more&page=#{page_number}&term=\"#{CGI.escape(@query)}\"&country=&postalCode=&locationText="
37
+ STDERR.puts "Gofundme::Search::results(): Fetching: #{url}" if Gofundme::DEBUG
38
+ page = RestClient.get url
39
+ nok = Nokogiri::HTML(page)
40
+ links = []
41
+ nok.xpath("//div[@class='fund-item']/a").each do |a|
42
+ links.push a.attr('href')
43
+ end
44
+ return links
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Gofundme
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gofundme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Janet Jeffus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: A library to scrape GoFundMe.com donation campaigns (called Projects).
84
+ GoFundMe does not have a publicly available API to query about donation lists, so
85
+ this library scrapes information from GoFundMe's own mvc.php API using rest_client.
86
+ This library is liable to break if GFM changes their API consumption endpoints.
87
+ This Library is not associated to GoFundMe, Inc. in any way, shape, or form and
88
+ respects robots.txt.
89
+ email:
90
+ - speak@jjeff.us
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".gitignore"
96
+ - ".travis.yml"
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - Gemfile.lock
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - gofundme.gemspec
106
+ - lib/gofundme.rb
107
+ - lib/gofundme/project.rb
108
+ - lib/gofundme/search.rb
109
+ - lib/gofundme/version.rb
110
+ homepage: https://github.com/jjeffus/gofundme
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ allowed_push_host: https://rubygems.org
115
+ homepage_uri: https://github.com/jjeffus/gofundme
116
+ source_code_uri: https://github.com/jjeffus/gofundme
117
+ changelog_uri: https://github.com/jjeffus/gofundme/CHANGELOG.md
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.7.8
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Access data from GoFundMe.com site
138
+ test_files: []