crowd_funding_parser 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 431eb1ced64d76041c587114664d712ad213869a
4
+ data.tar.gz: 2d0b7cb076f446a83b41171fb9f0af98e7d1a4ad
5
+ SHA512:
6
+ metadata.gz: 27b2259f0552a50fda78ed86047a9ef3b5f7f2d28c9be8f10feed1d1106cdfe756d25cfc0a14989c88f80dfe3ef037b675ec86208e98a0b7265df98a5ba92f52
7
+ data.tar.gz: 62eede16e512955c3b3e0c8616402d8cbd8ff4938e6b5a6532b6a7064018b49e12c71ec1b561573b3611d4752822568f1fe8d58190468dafbd2f73fd45f4e394
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
16
+ */.DS_Store
17
+ .DS_Store?
18
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in crowd_funding_parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Stan Low
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # CrowdFundingParser
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'crowd_funding_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install crowd_funding_parser
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/crowd_funding_parser/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'crowd_funding_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "crowd_funding_parser"
8
+ spec.version = CrowdFundingParser::VERSION
9
+ spec.authors = ["BackerFounder"]
10
+ spec.email = ["hello@backer-founder.com"]
11
+ spec.summary = %q{A crowd-funding platform parser}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_runtime_dependency "parallel", "~> 1.3"
24
+ spec.add_runtime_dependency "nokogiri", "~> 1.6"
25
+ end
@@ -0,0 +1,94 @@
1
+ module CrowdFundingParser
2
+ module Parser
3
+ class General
4
+ def parse_tracking_data(doc, rel_url)
5
+ project_url = @url + rel_url
6
+ project = Hash.new
7
+ project['money_goal'] = get_money_goal(doc).to_i
8
+ project['money_pledged'] = get_money_pledged(doc).to_i
9
+ project['backer_count'] = get_backer_count(doc).to_i
10
+ project['last_time'] = get_last_time(doc)
11
+ project['status'] = get_status(project['last_time'])
12
+ # project['backer_list'] = get_backer_list(project_url)
13
+ project['fb_count'] = get_fb_count(doc).to_i
14
+ project['following_count'] = get_following_count(doc).to_i
15
+ project
16
+ end
17
+
18
+ def parse_content_data(doc, rel_url)
19
+ project_url = @url + rel_url
20
+ project = Hash.new
21
+ project['platform_project_id'] = get_id(rel_url)
22
+ project['title'] = get_title(doc)
23
+ project['url'] = project_url
24
+ project['summary'] = get_summary(doc)
25
+ project['category'] = get_category(doc)
26
+ project['creator_name'] = get_creator_name(doc)
27
+ project['creator_id'] = get_creator_id(doc)
28
+ project['creator_link'] = get_creator_link(doc)
29
+ project
30
+ end
31
+
32
+ def get_project_links(required_status = "online")
33
+ links = []
34
+
35
+ @targets.each do |target|
36
+ doc = Nokogiri::HTML(target)
37
+ online_projects = doc.css(@item_css_class)
38
+
39
+ Parallel.map(online_projects, in_processes: 2 , in_threads: 4) do |project|
40
+ link_nodes = project.css("a:nth-child(1)")
41
+ status = get_status(get_string(project.css(@status_css_class)))
42
+ link = link_nodes.first["href"]
43
+ if status == "finished" && required_status == "finished"
44
+ links << link
45
+ elsif status == "online" && required_status == "online"
46
+ links << link
47
+ elsif status == "preparing" && required_status == "preparing"
48
+ links << link
49
+ end
50
+ end
51
+ end
52
+
53
+ links
54
+ end
55
+
56
+ def get_project_log(url)
57
+ url.gsub!("#{@url}", "")
58
+ parse_tracking_data(url)
59
+ end
60
+
61
+ def get_project_content(url)
62
+ url.gsub!("#{@url}", "")
63
+ parse_content_data(url)
64
+ end
65
+
66
+ def get_full_project(url)
67
+ get_project_content(url).merge(get_project_log(url))
68
+ end
69
+
70
+ def get_doc_through_url(rel_url)
71
+ project_url = @url + rel_url
72
+ project_html = open(project_url)
73
+ Nokogiri::HTML(project_html)
74
+ end
75
+
76
+ private
77
+
78
+ def get_string(elements)
79
+ elements.first.text.strip
80
+ end
81
+
82
+ def money_string(money)
83
+ money.sub('$', '').sub(',', '').sub('NT', "")
84
+ end
85
+
86
+ def convert_time(left_time)
87
+ days = ((left_time / (60 * 60 * 24))).to_i
88
+ hours = ((left_time / (60 * 60)) % 24).to_i
89
+ minutes = ((left_time / 60) % 60).to_i
90
+ "#{days}天#{hours}小時#{minutes}分鐘"
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,90 @@
1
+ require 'open-uri'
2
+
3
+ module CrowdFundingParser
4
+ module Parser
5
+ class Flyingv < General
6
+ def initialize(*cat)
7
+ categories = cat.empty? ? ["designgoods", "media", "stageplay", "entertainment", "publish", "society", "technology", "food", "travel"] : cat
8
+ @url = "https://www.flyingv.cc"
9
+ @targets = []
10
+
11
+ categories.each do |category|
12
+ category_url = @url + "/category/#{category}"
13
+ @targets << open(category_url)
14
+ end
15
+
16
+ @item_css_class = ".portfolio-item"
17
+ @status_css_class = ".unit-time"
18
+ end
19
+
20
+ # for project's info
21
+ def get_id(rel_url)
22
+ rel_url.split("/").last
23
+ end
24
+
25
+ def get_title(doc)
26
+ get_string(doc.css(".page-title-wrapper").css(".pagesTitle"))
27
+ end
28
+
29
+ def get_category(doc)
30
+ doc.css(".page-title-wrapper").css(".pageDes").first.css("a").first.text
31
+ end
32
+
33
+ def get_creator_name(doc)
34
+ doc.css(".page-title-wrapper").css(".pageDes")[1].css("a").first.text.strip
35
+ end
36
+
37
+ def get_creator_id(doc)
38
+ doc.css(".page-title-wrapper").css(".pageDes")[1].css("a").first["href"].split("/").last
39
+ end
40
+
41
+ def get_creator_link(doc)
42
+ @url + doc.css(".profilemeta .imp a").first["href"]
43
+ end
44
+
45
+ def get_summary(doc)
46
+ doc.css(".project_content").first.text.to_s[0..500].strip
47
+ end
48
+
49
+ # for tracking
50
+
51
+ def get_money_goal(doc)
52
+ money_string(get_string(doc.css(".countdes .dt .white")))
53
+ end
54
+
55
+ def get_money_pledged(doc)
56
+ money_string(get_string(doc.css(".countdes .ut .rtt h3")))
57
+ end
58
+
59
+ def get_backer_count(doc)
60
+ get_string(doc.css(".countdes .dt .pull-right")).sub("人贊助", "")
61
+ end
62
+
63
+ def get_last_time(doc)
64
+ get_string(doc.css(".countdes .dt div:nth-child(2)")).sub("剩餘", "")
65
+ end
66
+
67
+ def get_status(last_time)
68
+ if last_time.match("已結束")
69
+ "finished"
70
+ elsif last_time.match("開始")
71
+ "preparing"
72
+ else
73
+ "online"
74
+ end
75
+ end
76
+
77
+ def get_fb_count(doc)
78
+ get_string(doc.css("#fbBtn .sharenumber"))
79
+ end
80
+
81
+ def get_following_count(doc)
82
+ get_string(doc.css(".sidebarprj h5")).sub("人追踨", "").sub("追蹤", "").strip
83
+ end
84
+
85
+ def get_backer_list(project_url)
86
+ []
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,93 @@
1
+ require 'open-uri'
2
+
3
+ module CrowdFundingParser
4
+ module Parser
5
+ class Webackers < General
6
+ def initialize(*cat)
7
+ categories = cat.empty? ? ["ART", "PUBLICATION", "MUSIC", "DESIGN", "TECHNOLOGY", "ACG", "SURPRISE", "CHARITY", "VIDEO"] : cat
8
+ @url = "http://www.webackers.com"
9
+ @targets = []
10
+
11
+ categories.each do |category|
12
+ category_url = @url + "/Proposal/Browse?queryType=ALL&fundedStatus=ALL&category=#{category}"
13
+ @targets << open(category_url)
14
+ end
15
+
16
+ @item_css_class = ".cbp-item"
17
+ @status_css_class = "li.timeitem"
18
+ end
19
+
20
+ # for project's info
21
+ def get_id(rel_url)
22
+ rel_url.split("/").last
23
+ end
24
+
25
+ def get_title(doc)
26
+ get_string(doc.css(".case_header .case_title"))
27
+ end
28
+
29
+ def get_category(doc)
30
+ get_string(doc.css(".case_header .case_category a"))
31
+ end
32
+
33
+ def get_creator_name(doc)
34
+ get_string(doc.css(".headphoto_detail .name a"))
35
+ end
36
+
37
+ def get_creator_id(doc)
38
+ doc.css(".headphoto_detail .name a").first["href"].split("/").last
39
+ end
40
+
41
+ def get_creator_link(doc)
42
+ @url + doc.css(".headphoto_detail .name a").first["href"]
43
+ end
44
+
45
+ def get_summary(doc)
46
+ doc.css(".tab-content .description").first.text.to_s[0..500].strip
47
+ end
48
+
49
+ # for tracking
50
+
51
+ def get_money_goal(doc)
52
+ money_string(get_string(doc.css(".money_target")))
53
+ end
54
+
55
+ def get_money_pledged(doc)
56
+ money_string(get_string(doc.css(".money_now")))
57
+ end
58
+
59
+ def get_backer_count(doc)
60
+ get_string(doc.css(".tabbable li:nth-child(3) .badge.bg_no"))
61
+ end
62
+
63
+ def get_last_time(doc)
64
+ time_string = get_string(doc.css("article:nth-child(4) .panel-body span:nth-child(2)"))
65
+ last_seconds = (Time.parse(time_string) - Time.now)
66
+ last_seconds <= 0 ? "已結束" : convert_time(last_seconds)
67
+ end
68
+
69
+ def get_status(last_time)
70
+ if last_time.match("已結束") || last_time.match("已完成")
71
+ "finished"
72
+ elsif last_time.match("開始")
73
+ "preparing"
74
+ else
75
+ "online"
76
+ end
77
+ end
78
+
79
+ def get_fb_count(doc)
80
+ # get 0 because of ajax delay
81
+ get_string(doc.css(".fbBtn span.fb_share_count"))
82
+ end
83
+
84
+ def get_following_count(doc)
85
+ get_string(doc.css(".badge_share"))
86
+ end
87
+
88
+ def get_backer_list(project_url)
89
+ []
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,90 @@
1
+ require 'open-uri'
2
+
3
+ module CrowdFundingParser
4
+ module Parser
5
+ class Zeczec < General
6
+ def initialize
7
+ @url = "https://www.zeczec.com"
8
+ @targets = [open(@url + "/categories")]
9
+ @item_css_class = ".project-list .span4"
10
+ @status_css_class = ".meta span:nth-child(2)"
11
+ end
12
+
13
+ def get_id(rel_url)
14
+ rel_url.split("/").last
15
+ end
16
+
17
+ def get_title(doc)
18
+ get_string(doc.css("a.project-title"))
19
+ end
20
+
21
+ def get_category(doc)
22
+ doc.css(".project-meta").css("a")[0].text
23
+ end
24
+
25
+ def get_creator_name(doc)
26
+ doc.css(".project-meta").css("a")[1].text.strip
27
+ end
28
+
29
+ def get_creator_id(doc)
30
+ doc.css(".project-meta").css("a")[1]["href"].split("/").last
31
+ end
32
+
33
+ def get_creator_link(doc)
34
+ @url + doc.css(".creator .fly-center a").first["href"]
35
+ end
36
+
37
+ def get_summary(doc)
38
+ doc.css(".project-content").first.text.to_s[0..500].strip
39
+ end
40
+
41
+ # for tracking
42
+
43
+ def get_money_goal(doc)
44
+ if doc.css(".sidebar .project-notice strong").empty?
45
+ get_money_pledged(doc).to_i / get_percentage(doc).to_i * 100
46
+ else
47
+ money_string(get_string(doc.css(".sidebar .project-notice strong:nth-child(2)")))
48
+ end
49
+ end
50
+
51
+ def get_money_pledged(doc)
52
+ money_string(get_string(doc.css(".sidebar h3.num")))
53
+ end
54
+
55
+ def get_backer_count(doc)
56
+ get_string(doc.css("span.counter"))
57
+ end
58
+
59
+ def get_last_time(doc)
60
+ money_string(get_string(doc.css(".sidebar .row-fluid .span6:nth-child(2) h3.num")))
61
+ end
62
+
63
+ def get_percentage(doc)
64
+ money_string(get_string(doc.css(".sidebar .row-fluid .span6:nth-child(1) h3.num")))
65
+ end
66
+
67
+ def get_status(last_time)
68
+ if last_time.match("前") || last_time.match("達成")
69
+ "finished"
70
+ elsif last_time.match("開始")
71
+ "preparing"
72
+ else
73
+ "online"
74
+ end
75
+ end
76
+
77
+ def get_fb_count(doc)
78
+ ""
79
+ end
80
+
81
+ def get_following_count(doc)
82
+ ""
83
+ end
84
+
85
+ def get_backer_list(project_url)
86
+ []
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module CrowdFundingParser
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'open-uri'
2
+ require "crowd_funding_parser/version"
3
+ require "crowd_funding_parser/general"
4
+ require "crowd_funding_parser/parser/flyingv"
5
+ require "crowd_funding_parser/parser/webackers"
6
+ require "crowd_funding_parser/parser/zeczec"
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crowd_funding_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - BackerFounder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parallel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ description:
70
+ email:
71
+ - hello@backer-founder.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - crowd_funding_parser.gemspec
82
+ - lib/crowd_funding_parser.rb
83
+ - lib/crowd_funding_parser/general.rb
84
+ - lib/crowd_funding_parser/parser/flyingv.rb
85
+ - lib/crowd_funding_parser/parser/webackers.rb
86
+ - lib/crowd_funding_parser/parser/zeczec.rb
87
+ - lib/crowd_funding_parser/version.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A crowd-funding platform parser
112
+ test_files: []