Ruby On Rails - stock_quote specific date issue - ruby-on-rails

I'm using Ruby on Rails and I'm implementing a library called stock_quote. Using its Github Documentation
I've been able to succesfully use the library, using different methods in RoR, like:
StockQuote::Stock.quote
StockQuote::Stock.stats
StockQuote::Stock.chart
But I'm having issues to fetch an specific date. For example, I can fetch the last six months in a daily basis, using:
#stock_chart = StockQuote::Stock.chart(params[:id], '6m')
But I need to fetch an specific date with this method. In the iextrading documentation, it says:
"Specific date : IEX-only data by minute for a specified date in the format YYYYMMDD if available. Currently supporting trailing 30 calendar days''
And the HTTP requested is:
/stock/aapl/chart/date/20180620
HTTP request highlighted - for specific date
I tried to execute this commend in Ruby On Rails, but I haven't been able to translate the HTTP request into a proper RoR format in order to succesfully fetch the trend data. In the stock_quote documentation there is not also any reference to this specific command.
I appreciate any help with this issue, I've tried around 20+ syntax ways but they didn't work.

Related

Google sheet Import HTML function

Am trying to pull out date fr4om Money control form this function (https://www.moneycontrol.com/indices/fno/view-option-chain/BANKNIFTY/2022-07-28) what could be the formula for This & how we get multiple stock data like nifty, banknifty ,& stocks in variable expiry i used this this ( =IMPORTHTML("https://www.moneycontrol.com/indices/fno/view-option-chain/"&AD3&"/"&W253"","table",2)) but error occurred
I was able to successfully import the table from the mentioned URL using the following formula:
=IMPORTHTML("https://www.moneycontrol.com/indices/fno/view-option-chain/BANKNIFTY/2022-08-04", "table", 2, "en_US")
However you've mentioned that an error ocurred, but you haven't shared the error...
Since you are concatenating parameters to the URL being fetched, I'd recommend investigating the end result of the concatenation and try accessing that newly concatenated URL on a browser to see if it works.
Additionally, I’d recommend adhering to the How to Ask guidelines in order for your questions to be properly answered by the community as well as to provide a minimal reproducible example when posting a question.

Twilio fetch all call logs from last 5 days in ruby

I want to fetch the call logs for the last 5 days, I read on the documentation
You can also specify an inequality, such as EndTime<=YYYY-MM-DD, to read calls that ended on or before midnight of this date
I am trying the following with no luck
#client.calls.list(to: phone_number, end_time: ">=#{Time.now - 5.days}")
Twilio developer evangelist here.
There are several things here, and I need to apologise for at least one of them.
Firstly, the less than/greater than equal that the Twilio API implemented was actually a bit of a hack with the way the parameters are formatted. The parameter as the docs point out is EndTime<=YYYY-MM-DD but this is made of the parameter name EndTime< and the parameter value YYYY-MM-DD separated by =. I apologise that this seemed like a cool hack but actually made things harder.
The Ruby library actually tries to unpick this and make it more sensible again. You can use the parameter end_time_after instead of trying to form the correct end_time format.
Second, I ran the string you were using for the end_time and it produced this:
irb(main):001:0> ">=#{Time.now - 5.days}"
=> ">=2021-02-28 14:35:44 +1100"
So when a time is stringified in Ruby, it doesn't just show up in the YYYY-MM-DD format.
So, to fix your API call, should format the date to YYYY-MM-DD and use end_time_after. Note, since you're using ActiveSupport, you can also call on 5.days.ago instead of Time.now - 5.days.
This should work for you:
#client.calls.list(to: phone_number, end_time_after: "#{5.days.ago.strftime("%Y-%m-%d")}")
Let me know if this helps at all.

Bit.ly custom query - ruby gem

According to https://dev.bitly.com/link_metrics.html#v3_link_clicks,
we can send multiple parameters like link, unit, etc.
Here i am using this gem https://github.com/philnash/bitly
i am actually looking for Clicks by Day,
i tried
Bitly.client.clicks("bitly_short_url").clicks_by_day, works fine
but i need to change Time Zone value
i tried this
Bitly.client.info({"link" =>"bitly_short_url", "timezone" => -6}).clicks_by_day
and i am getting error.
Is there any other way to get result for different timezone?
Please help
Try this,
Bitly.client.clicks({"link" =>"bitly_short_url", "timezone" => -6}).clicks_by_day
info API doesn't take link or timezone as parameters. But, clicks API takes that. You are passing parameters of clicks API to info API. That is the reason you are getting errors.

Split datetime value received from external API in Rails app

I have a datetime value which comes from the API in this format: 2015-07-07T17:30:00+00:00. I simply want to split it up between the date and time values at this point. I am not using an Active Record model and I prefer not to use an sql database if I can.
The way I have set up the app means that the value is "stored" like this in my view: #search.dining_date_and_time
I have tried two approaches to solving this problem:
Manually based on this previous stackoverflow question from 2012: Using multiple input fields for one attribute - but the error I get is the attribute is "nil" even though I put a "try"
Using this gem, https://github.com/ccallebs/split_date_time which is a bit more recent and seems to be a more elegant solution, but after closely following the doc, I get this error, saying my Search model is not initalized and there is no method: undefined method dining_date' for #<Search not initialized>
This is when instead I put #search.dining_date in the view, which seems to be the equivalent of the doc's example (its not that clear). The doc also says the method will be automatically generated.
Do I need to alter my model so I receive the data from the API in another way? ie. not get the variable back as #search.dining_date_and_time from the Search model for any of this to work?
Do I need an Active Record model so that before_filter or before_save logic works - so i can (re)concatenate after splitting so the data is sent back to the API in a format it understands. Can I avoid this - it seems a bit of overkill to restructure the whole app and put in a full database just so I can split and join date/time as needed.
Happy to provide further details, code snippets if required.
As I am not using a conventional Rails DB like MySql Lite or Postgresql, I found that the best solution to the problem was by using this jQuery date Format plugin: https://github.com/phstc/jquery-dateFormat to split the date and time values for display when I get the data back from the API.
The Github docs were not too expansive, but once I put the simply put the library file in my Rails javascript assets folder, I just had to write a few lines of jQuery to get the result and format I wanted:
$(function() {
var rawDateTime = $('#searchDiningDateTime').html();
// console.log(rawDateTime);
var cleanDate = $.format.date(rawDateTime, "ddd, dd/MM/yyyy");
// console.log(cleanDate);
$('#searchDiningDateTime').html(cleanDate);
var cleanTime = $.format.date(rawDateTime, "HH:mm");
// console.log(cleanTime);
$('#searchTime').html(cleanTime);
});
Next challenge: rejoin the values on submit, so the API can read the data by sending/receiving a valid request/response. (The values can't be split like this when sent to the remote service).

JavaMail: how to get new messages comparing with time-stamps

I'm trying to get messages after a certain time-stamp, the way I've coded it was suggested by another programmer in this site:
GregorianCalendar date = new GregorianCalendar();
SearchTerm newer = new ReceivedDateTerm(ComparisonTerm.GT,date.getTime());
Message msgs[] = folder.search(newerThen);
The issue is that I get all the messages since the date, not the specific time. I was wondering if there is some work-around to emulate this. I mean, for an instance, if I want to get all the messages since today in the midday I would get those messages spicifically and not those ones received in today's morning.
Thanks in advance,
EDIT:
A new thought concerning to this: perhaps some date manipulation could do the job. I mean, comparing the minutes in the timestamp and filter programmatically those messages that don't fit the criteria. I know it's not the best way, but it could work.
PS: I'm using IMAP and trying to get mails from gmail, but I guess it should work no matter what the mail-server is.
Unfortunately, no. In this case, the IMAP protocol is being used by the JavaMail classes, and IMAP's SEARCH command takes only dates, not times (see the SINCE and SENTSINCE criteria).
You could use the setTime() method to query for some specific time.
Example:
setTime(timeInMilliseconds)

Resources