patu 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/patu +4 -0
- data/bin/setup +8 -0
- data/data.csv +7 -0
- data/data.yml +20 -0
- data/lib/patu/dependencies.rb +6 -0
- data/lib/patu/post_message.rb +15 -0
- data/lib/patu/version.rb +3 -0
- data/lib/patu.rb +74 -0
- data/patu.gemspec +25 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db2fe7bc9100a819d15319f59d881daed0b69c3e
|
4
|
+
data.tar.gz: 19f8bc399856034fc8cd1314307fad069128f521
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42d00e9f50fb3ca04c5f938e189b17d8b38aea6b5eacdb32a6c032ceacdce6510ed23d3676a9ad9df5113d0b4a282bde48197d55e3b9763aa70ea21578310aab
|
7
|
+
data.tar.gz: d6d6eb5463211dbb3f34b92c0a42332d86d05dc5d80622c64c74c454a09e242c13e074b98ab65bb40890c28ea2a9a2940f9b2b8deef431f2ab1a1ae616177440
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at ytbryan@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Bryan Lim(@ytbryan)
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Patu
|
2
|
+
|
3
|
+
patu is a simple command line scraper for daily scraping. It is designed for usage not speed.
|
4
|
+
|
5
|
+
> Patu is a genus of spiders in the family Symphytognathidae that occurs in Colombia and Oceania. Patu digua is the smallest species of spider described to date.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'patu'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install patu
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Type in your command prompt.
|
27
|
+
```
|
28
|
+
patu <url> <css> #this will only yield a single column data
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
For mulitple webpages or multiple elements, use a data.yml to define patu
|
34
|
+
```
|
35
|
+
- path: "data.csv"
|
36
|
+
- url:
|
37
|
+
https://rubygems.org/gems/aka2
|
38
|
+
https://rubygems.org/gems/aka2
|
39
|
+
https://rubygems.org/gems/aka2
|
40
|
+
https://rubygems.org/gems/aka2
|
41
|
+
- column_array:
|
42
|
+
- column:
|
43
|
+
name: "well"
|
44
|
+
pattern: "a.something"
|
45
|
+
- column:
|
46
|
+
name: "well"
|
47
|
+
pattern: "a.something"
|
48
|
+
```
|
49
|
+
|
50
|
+
call patu, it will auto detect data.yml
|
51
|
+
|
52
|
+
```
|
53
|
+
patu
|
54
|
+
```
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
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).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ytbryan/patu. 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.
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
Patu is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "patu"
|
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
|
data/bin/patu
ADDED
data/bin/setup
ADDED
data/data.csv
ADDED
data/data.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# urls:
|
2
|
+
# - "https://www.google.com/finance?q=NASDAQ%3AAAPL&ei=nObzVvmhO5KYuASsm5ywCQ"
|
3
|
+
# pattern:
|
4
|
+
# - "span#ref_22144_l"
|
5
|
+
# columns:
|
6
|
+
# - "aka2"
|
7
|
+
# csv: "new_data.csv"
|
8
|
+
# yml: "data.yml"
|
9
|
+
|
10
|
+
csv: "data.csv"
|
11
|
+
yml: "data.yml"
|
12
|
+
# data:
|
13
|
+
# -
|
14
|
+
# url: "https://www.google.com/finance?q=NASDAQ%3AAAPL&ei=nObzVvmhO5KYuASsm5ywCQ"
|
15
|
+
# pattern: "span#ref_22144_l"
|
16
|
+
# column: "boo"
|
17
|
+
# -
|
18
|
+
# url: "https://www.google.com/finance?q=NASDAQ%3AAAPL&ei=nObzVvmhO5KYuASsm5ywCQ"
|
19
|
+
# pattern: "span#ref_22144_l"
|
20
|
+
# column: "boo"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Log
|
2
|
+
MESSAGE = "
|
3
|
+
|
4
|
+
██████╗ █████╗ ████████╗██╗ ██╗
|
5
|
+
██╔══██╗██╔══██╗╚══██╔══╝██║ ██║
|
6
|
+
██████╔╝███████║ ██║ ██║ ██║
|
7
|
+
██╔═══╝ ██╔══██║ ██║ ██║ ██║
|
8
|
+
██║ ██║ ██║ ██║ ╚██████╔╝
|
9
|
+
╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝
|
10
|
+
|
11
|
+
Full Changelog -> https://github.com/ytbryan/patu/blob/master/changelog.md
|
12
|
+
|
13
|
+
Pull Request -> https://github.com/ytbryan/patu/pulls
|
14
|
+
"
|
15
|
+
end
|
data/lib/patu/version.rb
ADDED
data/lib/patu.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "patu/version"
|
2
|
+
require 'thor'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'csv'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
module Patu
|
9
|
+
class Base < Thor
|
10
|
+
|
11
|
+
package_name 'patu'
|
12
|
+
default_task :print
|
13
|
+
|
14
|
+
desc :scrap, 'patu scrap <url> <pattern>'
|
15
|
+
def scrap url, pattern
|
16
|
+
process_argv(url, pattern)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc :go, 'This command will run the data.yml in current directory.'
|
20
|
+
def go
|
21
|
+
if File.exists?("data.yml")
|
22
|
+
data = YAML.load_file("data.yml")
|
23
|
+
data["data"].each_with_index do |value, index|
|
24
|
+
process_argv(value["url"], value["pattern"])
|
25
|
+
end if data["data"]
|
26
|
+
else
|
27
|
+
puts "[cannot find data.yml] See http://github.com/ytbryan/patu/data.yml for example"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc :print, ''
|
32
|
+
def print
|
33
|
+
puts "
|
34
|
+
██████╗ █████╗ ████████╗██╗ ██╗
|
35
|
+
██╔══██╗██╔══██╗╚══██╔══╝██║ ██║
|
36
|
+
██████╔╝███████║ ██║ ██║ ██║
|
37
|
+
██╔═══╝ ██╔══██║ ██║ ██║ ██║
|
38
|
+
██║ ██║ ██║ ██║ ╚██████╔╝
|
39
|
+
╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝
|
40
|
+
|
41
|
+
|| patu is a simple command-line scraper for everyday scraping.
|
42
|
+
|| http://github.com/ytbryan/patu
|
43
|
+
|| See full commands: patu -h
|
44
|
+
|
45
|
+
"
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
private
|
50
|
+
def process_argv(url, pattern)
|
51
|
+
web_page = Nokogiri::HTML(open(url))
|
52
|
+
scraped_result = web_page.css(pattern)
|
53
|
+
print_csv(scraped_result, scraped_result.count)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def print_csv value, count
|
58
|
+
a = Array.new(count)
|
59
|
+
if !File.exists?("data.csv")
|
60
|
+
FileUtils.touch 'data.csv'
|
61
|
+
CSV.open("data.csv", "wb") do |csv|
|
62
|
+
csv << ["date", "time"] + a.each_with_index.map { |i,y| "value#{y+1}" }# a.collect {|num| "value" + num}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
CSV.open("data.csv", "ab") do |csv|
|
67
|
+
csv << [Date.today, Time.now.strftime("%I:%M%p")] + value.to_a
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/patu.gemspec
ADDED
@@ -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 'patu/version'
|
5
|
+
require 'patu/post_message'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "patu"
|
9
|
+
spec.version = Patu::VERSION
|
10
|
+
spec.authors = ["Bryan Lim"]
|
11
|
+
spec.email = ["ytbryan@gmail.com"]
|
12
|
+
spec.summary = %q{ Patu is a simple command line scraper for daily scraping.}
|
13
|
+
spec.description = %q{ Patu is a simple command line scraper for daily scraping.}
|
14
|
+
spec.homepage = "http://github.com/ytbryan/patu"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.post_install_message = Log::MESSAGE
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.executables = ["patu"]
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'thor' , '~> 0.19.1'
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Lim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: " Patu is a simple command line scraper for daily scraping."
|
56
|
+
email:
|
57
|
+
- ytbryan@gmail.com
|
58
|
+
executables:
|
59
|
+
- patu
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/patu
|
71
|
+
- bin/setup
|
72
|
+
- data.csv
|
73
|
+
- data.yml
|
74
|
+
- lib/patu.rb
|
75
|
+
- lib/patu/dependencies.rb
|
76
|
+
- lib/patu/post_message.rb
|
77
|
+
- lib/patu/version.rb
|
78
|
+
- patu.gemspec
|
79
|
+
homepage: http://github.com/ytbryan/patu
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message: "\n\n ██████╗ █████╗ ████████╗██╗ ██╗\n ██╔══██╗██╔══██╗╚══██╔══╝██║
|
84
|
+
\ ██║\n ██████╔╝███████║ ██║ ██║ ██║\n ██╔═══╝ ██╔══██║ ██║ ██║ ██║\n
|
85
|
+
\ ██║ ██║ ██║ ██║ ╚██████╔╝\n ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝\n\n Full
|
86
|
+
Changelog -> https://github.com/ytbryan/patu/blob/master/changelog.md\n\n Pull
|
87
|
+
Request -> https://github.com/ytbryan/patu/pulls\n "
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.3.1
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Patu is a simple command line scraper for daily scraping.
|
107
|
+
test_files: []
|