-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss_feed.rb
43 lines (34 loc) · 1.29 KB
/
rss_feed.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This is an RSS Feed in a terminal
require 'feedjira'
require 'httparty'
default_url = "https://techcrunch.com/feed/"
puts "Enter the URL of the RSS feed you want to read (or press Enter to use the default URL)"
user_url = gets.chomp # gets input without the '\n' escape character
# Use the user URL if the input is not empty
url = user_url.empty? ? default_url : user_url
# Block for handling exceptions or error handling
begin
# Parse the RSS feed
#Parse => Get infomation from
xml = HTTParty.get(url).body
feed = Feedjira.parse(xml)
# Presentation of the information
puts "Feed Title: \n#{feed.title}"
puts
puts "Feed Description: \n#{feed.description}"
puts "--------------------"
puts
# Loop through the entry in the RSS feeed and assign it to the entry block to represent each member of the entry
feed.entries.each do |entry|
puts "Published: #{entry.published} --- Title: #{entry.title}"
puts "---------------------------------------------------------------"
puts "Description: \n#{entry.summary}"
puts "---------------------------------------------------------------"
puts "Link: \n#{entry.url}"
puts "--------------------"
end
# In case there's any error
rescue StandardError => e
# Handles the errors during parsing
puts "Error: #{e.message}"
end