Skip to content

Commit

Permalink
Proposal for #13 Grab Document title from public page (#16)
Browse files Browse the repository at this point in the history
* check how many args

Check to make sure that at least 2 args are being passed to mosbot,
this will avoid pulling bugs/docs with the id set to 0.

* Additional check

Realized that if '-o' or '-c' is passed in it would still be
possible for the id to be empty. So added an additional check
to see if the id is 0 where the type is checked.

* Proposal for #13 Grab Document title from public page

Added new function 'generate_public_url', I'm not sure that it handles
all cases though.

Added new function 'get_title', uses regex to get the page title.

Additional code to use these 2 functions and print the page title.

* Revert "Additional check"

This reverts commit cde04dc.
Shouldn't have been in this branch yet.

* Revert "check how many args"

This reverts commit 201d293.
Also shouldn't have been in this branch yet.

* Add error handling

Added some error handling to the 'get_title' function, it's very
basic but should prevent dumping errors should they arise.

Also adding title empty check to output to only print if there's a
title available.
  • Loading branch information
bmcculley authored and iversond committed Nov 12, 2018
1 parent 8cd8cf8 commit f01f570
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bin/mosbot
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ if type == "help" || id == "0"
display_help()
else
mosurl = generate_url(type, id)
handle_output(mosurl)
mospuburl = generate_public_url(id)
page_title = get_title(mospuburl)
handle_output(mosurl, page_title)
end
22 changes: 21 additions & 1 deletion lib/mosbot.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require 'rbconfig'
require 'open-uri'

def os
@os ||= (
Expand Down Expand Up @@ -37,7 +38,26 @@ def generate_url(type, id)
end
end

def handle_output(url)
def generate_public_url(id)
id = id.sub('.', '_')
mospuburl = "https://support.oracle.com/knowledge/PeopleSoft%20Enterprise/"+id+".html"
end

def get_title(mospuburl)
begin
open(mospuburl) do |f|
str = f.read
page_title = str.scan(/<title>(.*?)<\/title>/)[0][0]
end
rescue
page_title = ''
end
end

def handle_output(url, title)
if !title.empty?
puts title
end
puts url

if "#{MOS_COPY_URL}" == "true"
Expand Down

0 comments on commit f01f570

Please sign in to comment.