url_report 0.1.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 +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/url_report +29 -0
- data/lib/url_report/version.rb +3 -0
- data/lib/url_report.rb +96 -0
- data/url_report.gemspec +47 -0
- metadata +142 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7a8edb12294dbeabe0916c87fb7e8714e739af34404d494f5668095638e10c9e
|
|
4
|
+
data.tar.gz: 5a83e0851ae33356eee5ee94c576a1adf088d517623d90a7615b05439ad7b013
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 55f3a8ed70da40b44894ab1a06872bc1d9737c14678c7cb76aef27adbb5ba1d31a27e05f25e0371eee2a256bf33d5a1fb0641c0bebb3b9638ea17b6560d0629a
|
|
7
|
+
data.tar.gz: '09408039fd6d90a02550a6d65b64d0bb2ffe3f6e859f5028cf0afdc9855b52d04bbd3dbb732bbdf85056c4573d257b3e18a49befe5a39a0c157a609a6e8780d6'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 sudo-self
|
|
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,39 @@
|
|
|
1
|
+
# UrlReport
|
|
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/url_report`. 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 'url_report'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install url_report
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
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).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/url_report.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://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 "url_report"
|
|
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
data/bin/url_report
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# bin/url_report
|
|
3
|
+
|
|
4
|
+
require "url_report"
|
|
5
|
+
|
|
6
|
+
# Get URL from command line argument or prompt the user
|
|
7
|
+
url = ARGV[0]
|
|
8
|
+
|
|
9
|
+
if url.nil? || url.strip.empty?
|
|
10
|
+
print "Enter the website URL to scrape: "
|
|
11
|
+
url = gets.strip
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Exit if still empty
|
|
15
|
+
if url.nil? || url.strip.empty?
|
|
16
|
+
puts "❌ No URL entered, exiting."
|
|
17
|
+
exit 1
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Call the gem method and handle errors
|
|
21
|
+
begin
|
|
22
|
+
file = UrlReport.generate(url)
|
|
23
|
+
puts "✅ Ruby Report saved to #{file}"
|
|
24
|
+
rescue UrlReport::Error => e
|
|
25
|
+
puts "❌ #{e.message}"
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
puts "❌ Unexpected error: #{e.message}"
|
|
28
|
+
end
|
|
29
|
+
|
data/lib/url_report.rb
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# lib/url_report.rb
|
|
2
|
+
|
|
3
|
+
require "httparty"
|
|
4
|
+
require "nokogiri"
|
|
5
|
+
require "prawn"
|
|
6
|
+
require "date"
|
|
7
|
+
require "open-uri"
|
|
8
|
+
require "uri"
|
|
9
|
+
|
|
10
|
+
module UrlReport
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
|
|
13
|
+
# Main method to generate a PDF report from a URL
|
|
14
|
+
def self.generate(url)
|
|
15
|
+
raise Error, "No URL provided" if url.nil? || url.strip.empty?
|
|
16
|
+
|
|
17
|
+
# -----------------------------
|
|
18
|
+
# 1. Fetch the website
|
|
19
|
+
# -----------------------------
|
|
20
|
+
response = HTTParty.get(url)
|
|
21
|
+
raise Error, "Failed to fetch page: #{response.code}" if response.code != 200
|
|
22
|
+
|
|
23
|
+
# -----------------------------
|
|
24
|
+
# 2. Parse HTML with Nokogiri
|
|
25
|
+
# -----------------------------
|
|
26
|
+
doc = Nokogiri::HTML(response.body)
|
|
27
|
+
|
|
28
|
+
# Headings
|
|
29
|
+
headings = doc.css('h1,h2').map(&:text).map(&:strip).reject(&:empty?)
|
|
30
|
+
|
|
31
|
+
# Links
|
|
32
|
+
links = doc.css("a").map { |a| [a.text.strip, a['href']] }
|
|
33
|
+
links.reject! { |text, href| text.empty? || href.nil? }
|
|
34
|
+
links = links.first(10)
|
|
35
|
+
|
|
36
|
+
# Images
|
|
37
|
+
images = doc.css('img').map { |img| img['src'] }.reject(&:nil?).first(5)
|
|
38
|
+
images.map! { |src| URI.join(url, src).to_s rescue src }
|
|
39
|
+
|
|
40
|
+
# -----------------------------
|
|
41
|
+
# 3. Generate PDF with Prawn
|
|
42
|
+
# -----------------------------
|
|
43
|
+
timestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
|
|
44
|
+
filename = "ruby_report_#{timestamp}.pdf"
|
|
45
|
+
|
|
46
|
+
Prawn::Document.generate(filename) do
|
|
47
|
+
text "Ruby Report", size: 20, style: :bold, align: :center
|
|
48
|
+
move_down 20
|
|
49
|
+
text "Source: #{url}", size: 10, align: :right
|
|
50
|
+
text "Date: #{Date.today}", size: 10, align: :right
|
|
51
|
+
move_down 20
|
|
52
|
+
|
|
53
|
+
# Headings
|
|
54
|
+
unless headings.empty?
|
|
55
|
+
text "Headings Found:", style: :bold
|
|
56
|
+
headings.each_with_index do |h, i|
|
|
57
|
+
safe_text = h.encode('Windows-1252', invalid: :replace, undef: :replace, replace: '?')
|
|
58
|
+
text "#{i+1}. #{safe_text}", size: 12
|
|
59
|
+
end
|
|
60
|
+
move_down 15
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Links
|
|
64
|
+
unless links.empty?
|
|
65
|
+
text "Links Found:", style: :bold
|
|
66
|
+
links.each_with_index do |(text, href), i|
|
|
67
|
+
safe_text = text.encode('Windows-1252', invalid: :replace, undef: :replace, replace: '?')
|
|
68
|
+
text "#{i+1}. #{safe_text}", size: 12, leading: 2
|
|
69
|
+
text "<link href='#{href}'>#{href}</link>", inline_format: true, size: 9, color: "0000FF"
|
|
70
|
+
move_down 10
|
|
71
|
+
end
|
|
72
|
+
move_down 15
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Images
|
|
76
|
+
unless images.empty?
|
|
77
|
+
text "Images Found:", style: :bold
|
|
78
|
+
images.each_with_index do |img_url, i|
|
|
79
|
+
text "#{i+1}. #{img_url}", size: 10, color: "0000AA"
|
|
80
|
+
begin
|
|
81
|
+
open(img_url) { |f| image f, fit: [400, 300] }
|
|
82
|
+
rescue
|
|
83
|
+
text "(Failed to load image)", size: 9, color: "FF0000"
|
|
84
|
+
end
|
|
85
|
+
move_down 5
|
|
86
|
+
end
|
|
87
|
+
move_down 15
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
text "Ruby Report powered by (HTTParty + Nokogiri + Prawn)",
|
|
91
|
+
size: 9, align: :center, style: :italic
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
filename
|
|
95
|
+
end
|
|
96
|
+
end
|
data/url_report.gemspec
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "url_report/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "url_report"
|
|
9
|
+
spec.version = UrlReport::VERSION
|
|
10
|
+
spec.authors = ["sudo-self"]
|
|
11
|
+
spec.email = ["jroper719@gmail.com"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "Generate a PDF report of headings, links, and images from a URL"
|
|
14
|
+
spec.description = "UrlReport fetches a webpage, extracts headings, links, and images, and generates a PDF report."
|
|
15
|
+
spec.homepage = "https://github.com/yourusername/url_report"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
|
|
18
|
+
# Metadata for RubyGems
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
# spec.metadata["allowed_push_host"] = "http://mygemserver.com" # remove this line
|
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
22
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
23
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
|
24
|
+
else
|
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Files to include in the gem
|
|
29
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Executable
|
|
34
|
+
spec.bindir = "bin"
|
|
35
|
+
spec.executables = ["url_report"]
|
|
36
|
+
spec.require_paths = ["lib"]
|
|
37
|
+
|
|
38
|
+
# Runtime dependencies
|
|
39
|
+
spec.add_dependency "httparty"
|
|
40
|
+
spec.add_dependency "nokogiri"
|
|
41
|
+
spec.add_dependency "prawn"
|
|
42
|
+
|
|
43
|
+
# Development dependencies
|
|
44
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
|
45
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
46
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
47
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: url_report
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- sudo-self
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: httparty
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: nokogiri
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: prawn
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: bundler
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '1.17'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.17'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rake
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '10.0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '10.0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: rspec
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3.0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '3.0'
|
|
96
|
+
description: UrlReport fetches a webpage, extracts headings, links, and images, and
|
|
97
|
+
generates a PDF report.
|
|
98
|
+
email:
|
|
99
|
+
- jroper719@gmail.com
|
|
100
|
+
executables:
|
|
101
|
+
- url_report
|
|
102
|
+
extensions: []
|
|
103
|
+
extra_rdoc_files: []
|
|
104
|
+
files:
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".rspec"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- Gemfile
|
|
109
|
+
- LICENSE.txt
|
|
110
|
+
- README.md
|
|
111
|
+
- Rakefile
|
|
112
|
+
- bin/console
|
|
113
|
+
- bin/setup
|
|
114
|
+
- bin/url_report
|
|
115
|
+
- lib/url_report.rb
|
|
116
|
+
- lib/url_report/version.rb
|
|
117
|
+
- url_report.gemspec
|
|
118
|
+
homepage: https://github.com/yourusername/url_report
|
|
119
|
+
licenses:
|
|
120
|
+
- MIT
|
|
121
|
+
metadata:
|
|
122
|
+
homepage_uri: https://github.com/yourusername/url_report
|
|
123
|
+
source_code_uri: https://github.com/yourusername/url_report
|
|
124
|
+
changelog_uri: https://github.com/yourusername/url_report/CHANGELOG.md
|
|
125
|
+
rdoc_options: []
|
|
126
|
+
require_paths:
|
|
127
|
+
- lib
|
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ">="
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
requirements: []
|
|
139
|
+
rubygems_version: 3.7.2
|
|
140
|
+
specification_version: 4
|
|
141
|
+
summary: Generate a PDF report of headings, links, and images from a URL
|
|
142
|
+
test_files: []
|