parsing_articles 1.0.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +64 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/parsing_articles.rb +61 -0
- data/lib/parsing_articles/version.rb +3 -0
- data/parsing_articles.gemspec +36 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42df730377b2eb5be2ecd77a1beb9d8930bf07e4
|
4
|
+
data.tar.gz: ccd77fe1a5d93fc0bac185c25dae07d0e253dde0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aedc0585cb52516c209466b376d9e7f998b3afadd5b4b61882f98bbaef7aa20d6614052b39a65605e0445c25d1697abdf63b3b58806a3b202c7c8beccf9521bc
|
7
|
+
data.tar.gz: 0e972e2fb326a217b36d515610741863ff402b77a1672f23dde1904475018b17545b5a5475f164b336d34418fb0a6cd8172ec0bb52e740cf68a221e6f1cac9a8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
parsing_articles (1.0.0)
|
5
|
+
activesupport
|
6
|
+
koala
|
7
|
+
nokogiri (>= 1.8.2)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (5.1.4)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
addressable (2.5.2)
|
18
|
+
public_suffix (>= 2.0.2, < 4.0)
|
19
|
+
concurrent-ruby (1.0.5)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
faraday (0.14.0)
|
22
|
+
multipart-post (>= 1.2, < 3)
|
23
|
+
i18n (0.9.3)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
json (2.1.0)
|
26
|
+
koala (3.0.0)
|
27
|
+
addressable
|
28
|
+
faraday
|
29
|
+
json (>= 1.8)
|
30
|
+
mini_portile2 (2.3.0)
|
31
|
+
minitest (5.11.3)
|
32
|
+
multipart-post (2.0.0)
|
33
|
+
nokogiri (1.8.2)
|
34
|
+
mini_portile2 (~> 2.3.0)
|
35
|
+
public_suffix (3.0.1)
|
36
|
+
rake (10.5.0)
|
37
|
+
rspec (3.7.0)
|
38
|
+
rspec-core (~> 3.7.0)
|
39
|
+
rspec-expectations (~> 3.7.0)
|
40
|
+
rspec-mocks (~> 3.7.0)
|
41
|
+
rspec-core (3.7.1)
|
42
|
+
rspec-support (~> 3.7.0)
|
43
|
+
rspec-expectations (3.7.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.7.0)
|
46
|
+
rspec-mocks (3.7.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.7.0)
|
49
|
+
rspec-support (3.7.1)
|
50
|
+
thread_safe (0.3.6)
|
51
|
+
tzinfo (1.2.5)
|
52
|
+
thread_safe (~> 0.1)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 1.16)
|
59
|
+
parsing_articles!
|
60
|
+
rake (~> 10.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
1.16.0
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# ParsingArticles
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/parsing_articles`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'parsing_articles'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install parsing_articles
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
Firstly you should configurate you facebook settings(if you want to get news from facebook pages). You should set your APP_ID and APP_KEY(you can find them on https://developers.facebook.com/)
|
25
|
+
TO Do that you should code:
|
26
|
+
ParsingArticles::GetArticles.config_facebook(APP_ID, APP_KEY)
|
27
|
+
|
28
|
+
Next You can use it to parse artcles from facebook:
|
29
|
+
@articles_facebook = ParsingArticles::GetArticles.new(url_of_facebook_page)
|
30
|
+
@articles_facebook.get_array
|
31
|
+
The last command returns array with articles
|
32
|
+
|
33
|
+
Similar considered to Rss urls(no configuration needed):
|
34
|
+
@articles_rss = ParsingArticles::GetArticles.new(rss)
|
35
|
+
@articles_rss.get_array
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/parsing_articles.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "parsing_articles"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "parsing_articles/version"
|
2
|
+
require 'rss'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'koala'
|
6
|
+
module ParsingArticles
|
7
|
+
class GetArticles
|
8
|
+
def initialize(url)
|
9
|
+
@url = url.to_s
|
10
|
+
@articles_results = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.config_facebook(app_id = nil, app_secret = nil)
|
14
|
+
@APP_ID = app_id
|
15
|
+
@APP_KEY = app_secret
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_array
|
19
|
+
facebook_or_rss
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def facebook_or_rss
|
24
|
+
/https:\/\/www.facebook.com/.match(@url) ? facebook_parser : rss_parser
|
25
|
+
end
|
26
|
+
|
27
|
+
def facebook_parser
|
28
|
+
graph = Koala::Facebook::API.new(GetArticles.get_app_access_token)
|
29
|
+
get_facebook_array(graph)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_app_access_token
|
33
|
+
@oauth = Koala::Facebook::OAuth.new(@APP_ID || = '1977681792501372', @APP_KEY || ='920ff6a0a18835cb7b2fef5cda8cd491')
|
34
|
+
@oauth.get_app_access_token
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_facebook_array(graph)
|
38
|
+
@articles_results = graph.get_connection(facebook_get_page_id, 'posts', {
|
39
|
+
fields: ['title', 'link', 'message', 'created_time']})
|
40
|
+
end
|
41
|
+
|
42
|
+
def facebook_get_page_id
|
43
|
+
page = Nokogiri::HTML(open(@url))
|
44
|
+
page_id = /([\d]){15}/.match((page.css('head')).to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def rss_parser()
|
48
|
+
rss = RSS::Parser.parse(@url, false).items
|
49
|
+
get_rss_array(rss) do |result|
|
50
|
+
result = { 'title' => result.title, 'created_time' => result.pubDate, 'link' => result.link, 'message' => result.description.gsub(/<\/?[^>]*>/, "")}
|
51
|
+
@articles_results.push(result)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_rss_array(rss, &block)
|
56
|
+
rss.each &block
|
57
|
+
@articles_results
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "parsing_articles/version"
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "parsing_articles"
|
10
|
+
spec.version = ParsingArticles::VERSION
|
11
|
+
spec.authors = ["morozartem9"]
|
12
|
+
spec.email = ["morozartem9@gmail.com"]
|
13
|
+
|
14
|
+
spec.summary = "parsing articles"
|
15
|
+
spec.description = " parsing articles from rss or facebook"
|
16
|
+
spec.homepage = ""
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_dependency "nokogiri", ">=1.8.2"
|
33
|
+
spec.add_dependency "activesupport"
|
34
|
+
spec.add_dependency "koala"
|
35
|
+
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parsing_articles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- morozartem9
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-05 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
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.8.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: koala
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: " parsing articles from rss or facebook"
|
98
|
+
email:
|
99
|
+
- morozartem9@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/parsing_articles.rb
|
114
|
+
- lib/parsing_articles/version.rb
|
115
|
+
- parsing_articles.gemspec
|
116
|
+
homepage: ''
|
117
|
+
licenses: []
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.6.14
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: parsing articles
|
139
|
+
test_files: []
|