Feed Parsing In Rails - ruby-on-rails

I am working on Ubuntu 10.04 and I am using feed-zirra to parse RSS feeds and I have MySQL database.
I am trying to parse RSS feeds from Times of India Top Stories. There seems to be problem with the first link, I am sure TOI guys will correct it soon. But anyway, I dont want to face similar error later so thats why I want to ask you guys how to solve this problem.
Just look at this and especially look for link
<item>
<title>CWG: Abhinav Bindra, Gagan Narang win first Gold for India</title
<description>Abhinav Bindra and Gagan Narang on Tuesday bagged Gold for the men's 10 m air rifle pair's event, getting India its first gold in the 19th Commonwealth Games.</description>
<link>/cwgarticleshow/6688747.cms</link>
<guid>/cwgarticleshow/6688747.cms</guid>
<pubDate>Tue, 05 Oct 2010 04:57:46 GMT</pubDate>
</item>
The link is <link>/cwgarticleshow/6688747.cms</link>
Now, when I click the link, in the view.. its getting routed to http://localhost:3000/cwgarticleshow/6688747.cms instead of http://timesofindia.indiatimes.com/cwgarticleshow/6688747.cms
And the error I am getting is
**Routing Error**
No route matches "/cwgarticleshow/6688747.cms" with {:method=>:get}
How do I correct this type of Error?
Looking forward for your help and support
Thanks

You just need to prepend http://timesofindia.indiatimes.com to the link tag value and you'll be ok.

You can use URI class. You can, for example, define following method
require "uri"
def repair_link(feed_link)
uri = URI.parse(feed_link)
uri.scheme ||= "http"
uri.host ||= "timesofindia.indiatimes.com"
uri.to_s
end
It will set the scheme and host part of the URL if they are not already filled. So if you call it for normal link (like http://foo/bar.cms) then nothing will be changed.
And last thing - you probably should catch exception somewhere as the #parse method raises exception InvalidURIError in case of invalid URI. But it's up to you how you will deal with it.

Related

RubyGem 'steam-condenser' - .fetch method only time and fetch_games undefined method `[]'

I am trying to get some basic information from the Steam Community via the steam-condenser gem and so far the Steam.new seems to work just fine with all the players information.
however when I do this (example)
player = SteamId.new("tiger")
stats = player.fetch_games
I get the following error message
Traceback (most recent call last):
1: from lib/assets/ruby/test.rb:15:in `<main>'
/home/zigs/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/steam-condenser-1.3.11/lib/steam/community/steam_id.rb:326:in `fetch_games': undefined method `[]' for nil:NilClass (NoMethodError)
A lot of the information I need seems to be connected to the fetch_games (for example the method total_playtime(id))
Not sure why this is not working. I am lost. Any help or ideas are highly appreciated! Thank you!
TLDR; it looks like this gem no longer works.
the particular module that you're having trouble with is:
def fetch_games
games_data = parse "#{base_url}/games?xml=1"
#games = {}
#recent_playtimes = {}
#total_playtimes = {}
games_data['games']['game'].each do |game_data|
app_id = game_data['appID'].to_i
#games[app_id] = SteamGame.new app_id, game_data
recent = game_data['hoursLast2Weeks'].to_f
total = (game_data['hoursOnRecord'] || '').delete(',').to_f
#recent_playtimes[app_id] = (recent * 60).to_i
#total_playtimes[app_id] = (total * 60).to_i
end
true
end
with the particular problem statement being games_data['games']['game'].each
If we were looking to get information for a particular user, it downloads an XML document about the user from a URL looking like:
http://steamcommunity.com/id/demomenz?xml=1
and this file does not seem to contain any games objects in it.
Having looked at the codebase for the steam-condenser gem; it hasn't really been updated in about 6 years. I can only assume that the XML format has been modified since this time and that the gem will no longer work.
Valve has added more privacy options to Steam Community profiles which are not reflected in the old XML APIs.
Apparently, the profile in question (tiger) has it‘s game details set to “Friends Only” or ”Private” as games are also unavailable in the browser.
The code from the released 1.x versions is no longer guaranteed to work when it comes to Steam Community. Valve deprecated the old XML APIs several years ago. Sadly, the modern Web API hasn‘t gotten much attention from Valve‘s side either. So development of Steam Condenser has mostly come to halt, too.
You might have more luck using the code from the master branch of the GitHub repository which uses Web API for most of the Community features.
You will have to register for a Steam Web API key, though: https://steamcommunity.com/dev/apikey

Sending IFS File to Outq Prints Line of "#" Symbols

I am attempting to send a file from IFS to an outq on our AS/400 system. Whenever I do, I get exactly what I send, as well as a line of "#" symbols of varying lengths appended to the end.
Here's the command I'm using:
qsh cmd('cat -c /path/test.txt | Rfile -wbQ -c "ovrprtf file(qprint)
outq(*LIBL/ABCD) devtype(*USERASCII) rplunprt(*no) splfname(test) hold(*no)"
qprint')
The contents of test.txt is just Hello World!
The output I get when I send the command is
Hello World!####################################################################
I have not found any posts online about a similar problem, and have tried changing values and looking for additional switches to get it to work. Nothing I'm doing seems to fix the issue.
Is there a command or switch that I am missing, or is something I have in there already causing this?
EDIT:
I found this documentation which is the first time I've seen this issue mentioned, but it's not very helpful:
“Messages for a Take Action command might consist of a long string of "at" symbols (#) in a pop-up message. (The Reflex automation Take Action command, which is configured in situations, does not have this problem.) A resolution for this problem is under construction. This problem might be resolved by the time of the product release. If you see this problem, contact IBM Software Support.”
The only differences are: 1) this is not a pop-up message, it's printed. 2) I don't believe we use Tivoli Monitoring, although I could be wrong.
Assuming we do use Tivoli Monitoring, what would the solution be? There's no additional documentation past that, and I am not a system administrator, so I can't really make the call to IBM Software Support myself. And assuming we DON'T use it, what else could cause this issue?
I get different results, yet similar. I created a test.txt with Windows Explorer, put in Hello, world!, saved it and tried the script. I got gibberish for the 'Hello, world!' and then the line of # symbols.
My system is 7.3 TR5, CCSID 37 (US English) and my IFS file is CCSID 1252 (Windows English). Results did not change if I used a stream file of CCSID 819 (US ASCII).
I didn't have any luck modifying Rfile switches.
I found that removing devtype(*userascii) produced printed output in plain English without the # symbols. Do you really need *USERASCII? I would think that would be more for a pre-formatted 'print-ready' file like Postscript or the like.
EDIT: some more things to try
I don't understand why *USERASCII is adding those # symbols; it looks like a translation issue.
I tried this and still got the extra ###... You might have to play with the TOCCSID() parameter. Although a failure, it did give me an idea: what if those # symbols are EBCDIC spaces being sent as-is to the *USERASCII print stream? All we'd need is a way to send only the number of bytes in the stream file, without any padding.
CRTPF FILE(QTEMP/PRTSTMF) RCDLEN(132)
CPY OBJ('/path/test.txt') TOOBJ('/qsys.lib/qtemp.lib/prtstmf.file/prtstmf.mbr') replace(*yes)
ovrprtf file(qprint) outq(*LIBL/prt3812) devtype(*USERASCII) rplunprt(*no) splfname(test) hold(*no)
cpyf prtstmf qprint
The data in QTEMP/PRTSTMF is in ASCII; DSPPFM shows that much. It also shows a bunch of spaces: after all, it is a fixed length file. My next step was to write an RPG program to read the stream file and print it, but Scott Klement already did that: http://www.scottklement.com/PrtStmf.zip
This works on my system:
ovrprtf file(qsysprt) outq(*LIBL/abcd) devtype(*USERASCII) rplunprt(*no) splfname(test) hold(*no)
prtstmf stmf('/path/test.txt') outq(abcd)

https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("ARSARS")&env=store://datatables.org/alltableswithkeys

I have been using the following URL for the past 3 years without issue. However, it has stopped returning results.
URL:
https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("ARSARS")&env=store://datatables.org/alltableswithkeys
Now returns the following:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="0" yahoo:created="2017-11-02T09:33:25Z" yahoo:lang="en-AU">
<results/>
</query><!-- total: 9 -->
Notice how there are no results, it simply has the tag "results".
I have tried on this many different computers and browsers. I have also tried changing the currency combinations, but no luck.
Can anybody spot what I am doing wrong?
Yes, it looks like Yahoo has discontinued their Currency Converter API service.
I found a different site : https://currencylayer.com/
They let you request currency rates (1 USD = 168 other currencies). If you make less than 1000 requests per month, it is free (if you need more, they have different subscriptions : https://currencylayer.com/product).
You just need to sign up and receive your own Access Code. Once you have that, then you simply make the call http://apilayer.net/api/live?access_key= and it will return JSON of the other currency rates.
They also have code examples in PHP, JavaScript, and Java at https://currencylayer.com/documentation
Found it very easy to get started using their API right away.
I think the API is down.
I am similarly receiving "results"=nullfor the query:
http://query.yahooapis.com/v1/public/yql?q=select+%2A+from+yahoo.finance.xchange+where+pair+in+%28%22GBPEUR%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
Setting diagnostics=true in the request yields:
`
[execution-start-time] => 7
[execution-stop-time] => 12
[execution-time] => 5
[http-status-code] => 999
[http-status-message] => Request denied
[content] => http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=snl1d1t1ab
`
If anyone knows more than me about what this might imply I'd be glad to hear it!
Yahoo is aware of this issue and their engineers are working on it:
ref: https://forums.yahoo.net/t5/Yahoo-Finance-help/http-download-finance-yahoo-com-d-quotes-csv-s-GOOG-amp-f/td-p/387096
Very sadly and quite outrageously Yahoo decided to stop this service without any warning.
See admin message here
So many services depend on it, it's like Google saying they would suddenly stop their maps API... At this point I am blocking yahoo in our DNS so no one in our company will ever use Yahoo again since they are not a reliable entity.

Ruby Waitir Gem, getting unexpected results

2 weeks ago I put up post about my watir script timing out on me, I was able to get a solution but I realized to late the results I was getting was different than the person that helped me out. Here is the original post: Ruby Watir Gem, Timing Out on Form Input
require 'watir'
browser = Watir::Browser.new
browser.goto('https://tripadvisor.com/CheapFlightsHome')
browser.text_field(name: 'orig').set('Boston, MA - Logan International Airport (BOS)')
browser.text_field(name: 'dest').set('Milan, Italy - All Airports (MIL)')
browser.execute_script('document.querySelector(".in_date").click()')
browser.execute_script('document.querySelector(".day_28").click()')
browser.execute_script('document.querySelector(".out_date").click()')
browser.execute_script('document.querySelector(".day_2").click()')
browser.span(id: "CHECK_FARES_BUTTON").fire_event :click
puts browser.url
browser.quit
The person who wrote that code got this as a result:
https://www.tripadvisor.com/CheapFlightsSearchResults-g187849-a_airport0.BOS-a_airport1.MIL-a_cos.0-a_date0.20170328-a_date1.20170402-a_nearby0.no-a_nearby1.no-a_nonstop.no-a_pax0.a-a_travelers.1-Milan_Lombardy.html
I have the same code in my script and for some reason I'm only getting:
https://www.tripadvisor.com/CheapFlightsHome
It seems as though the button click isn't happening for me, not sure. I tried both chrome and firefox.
First of all your click actually opens another two window and also the time you are clicking it's not exactly receiving the click, Please use this code, it will work for you and you will be left with your expected window
require 'watir'
caps = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false)
driver=Selenium::WebDriver.for :firefox, desired_capabilities: caps, profile: "default"
b=Watir::Browser.new driver
b.goto('https://tripadvisor.com/CheapFlightsHome')
b.text_field(name: 'orig').set('Boston, MA - Logan International Airport (BOS)')
b.text_field(name: 'dest').set('Milan, Italy - All Airports (MIL)')
b.execute_script('document.querySelector(".in_date").click()')
b.execute_script('document.querySelector(".day_28").click()')
b.execute_script('document.querySelector(".out_date").click()')
b.execute_script('document.querySelector(".day_2").click()')
begin
b.element(xpath: ".//*[#id='CHECK_FARES_BUTTON']").click
end until b.windows.count>1
b.windows[0].close
b.windows[1].close
puts b.url
b.quit
Firstly, I changed .fire_event :click to .click.
Then there was an error that appeared.
Please enter a valid airport code or city.
Secondly, I tried this:
browser.span(id: "CHECK_FARES_BUTTON").click
browser.span(id: "CHECK_FARES_BUTTON").click
puts browser.url
And it redirected me to:
https://www.tripadvisor.com/CheapFlightsSearchResults-g187849-a_airport0.BOS-a_airport1.MIL-a_cos.0-a_date0.20170401-a_date1.20170402-a_nearby0.no-a_nearby1.no-a_nonstop.no-a_pax0.a-a_travelers.1-Milan_Lombardy.html
To be honest I have no idea why it does not register the input during the first click...
I am using chrome.

Omniture Saint.ImportCreateJob

This is a very specific Omniture API question. Thought I'd check here if anyone encountered this problem since Omniture forum was not of much help -
Sending the following parameters to Omniture API Explorer here - https://developer.omniture.com/en_US/get-started/api-explorer#Saint.ImportCreateJob seems to work fine.
{
"check_divisions":"1",
"description":"OSRA job description: MyReportID, Products, 51",
"email_address":"my#email.com",
"export_results":"0",
"header":["Field1", "Field2"],
"overwrite_conflicts":"1",
"relation_id":51,
"report_suite_array":["MyReportID"],
"c_view":"SomeReportName"
}
But the call fails in the actual code with a 'Bad Request'. It seems like c_view parameter is expecting a certain value. The only documentation for c_view is that it expects a report name. I've tried report names and other values with no luck. Would appreciate any pointers from Omniture API users.
Thanks.
try using the relevant value from the classification_view chart. I know this is what you need for using the get/save classifications methods (I have used those methods, but not the Saint.ImportCreateJob method).
c_value is not required, so unless you plan on using it, it does not need to be present. It is supposed to be a classification_view https://developer.omniture.com/en_US/documentation/omniture-administration/r-classification-view.
It takes some trial and error to get this api working.
Here is an example of a call I use that works using the REST api over Java:
Request:
{
"check_divisions":1,
"description":"Report Test 1",
"email_address":"cdegroot#adobe.com",
"export_results":"0",
"overwrite_conflicts":0,
"relation_id":65,
"report_suite_array":["cdgdev"],
"header":["Key","Survey","Survey^Question","Survey^Question^Response","Engagement Index","Survey > Question > Response"]
}
Response:
"3387166"
Kind Regards C.

Resources