this question has been asked here already but it's quite some time ago. Does anyone know if Rails has any support for Microsoft Access? I'd need to import and export data every few weeks and would really like to avoid exporting/importing csv files.
Thanks!
It's worth noting that there's an mdb gem for Ruby. It requires mdbtools to be installed.
Add to your Gemfile:
gem 'mdb'
Usage is pretty straightforward, tables are basically lists of hashes:
require 'mdb'
database = Mdb.open('workshops_handouts_inactive_database.mdb')
table = database[:MainData]
results = table.select { |rec| rec[:"Schedule Type"] == "MU1" }
puts results.first
{:"Container Number"=>"17", :Location=>"1f6", :Department=>"tx", ...
I don't think ActiveRecord support exists for MS Access, though.
the win32OLE class allows you to retrieve data from Microsoft Acess you can find the docs here
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/win32ole/rdoc/WIN32OLE.html
Related
In Rails, thanks to the incredible ActiveRecord library, we can do things like this:
bear = Bear.find(id)
bear.eyes = 'blue'
bear.friends += 1
bear.save
And the changes are then saved into the database.
In Meteor I can do this:
bear = Bears.findOne({});
bear.eyes = 'blue';
bear.friends++;
The two changes made are only made to the local copy in memory. As far as I can see the changes cannot be persisted without calling a Mongo update statement.
Bears.update({
_id: bear._id,
$inc: { friend: 1 },
eyes: 'blue'
});
I love Meteor, it is pretty amazing... but this would seem to be a big step backwards if it cannot be done.
Is there some way to persist bear as we used to do in Rails / ActiveRecord?
As of this writing, meteor does not include an ORM in its core packages. There is, however, a community package called astronomy which implements ActiveRecord-style models. The complete documentation can be found here.
Recommended reading:
To create a simple model layer using the tools that the core packages provide, have a look at this article.
To read a summary of where the community is heading, check out this issue on the official guide repo.
In my rails app I want to use country-code, currency-code, ISO locale code to fetch some data from API. How can I get this information dynamically when user visit my site from anywhere?
I have used geocoder gem so by request.location I will get location's information and using this gem I can get country-code. Now I am not getting how can I get remaining information such as currency-code & ISO locale code?? Can anyone please help me or guide me??
I have seen this money gem but not sure it will provide me all these information.
Thanks in advance :)
I have tried #Prakash Murthy's answer. But there are many issue in this http://www.currency-iso.org/dam/downloads/table_a1.xml I found there is not proper name of all countries and some country has multiple currency_code which made me confused. But finally I found the solution by this single countries gem without creating any database.
Here is how I achieved the solution:
country_name = request.location.data['country_name'] # got country name
c = Country.find_country_by_name(country_name) # got currency details
currency_code = c.currency['code'] # got currency code
Sorry to answer my own question but I have posted here so in future if anyone stuck like me for the same issue then his/her time not wasted.
I found a way that makes it really easy:
Add currency gem to Gemfile, then bundle install
def currency_for_country(currency_iso_code)
ISO3166::Country.new(currency_iso_code).currency_code
end
Then:
currency_for_country('US')
=> "USD"
currency_for_country('AU')
=> "AUD"
This info is based off the countries gem readme
currency-code & ISO locale code are static data which change very rarely - if at all, and are best handled as static information within the system by storing them within the database tables. Might even be a good idea to provide a CRUD interface for managing these data.
One possible source for Currency code : http://www.currency-iso.org/en/home/tables/table-a1.html
List of All Locales and Their Short Codes? has details about getting the list of all locale codes.
I'm building a Rails app where I want to download historical financial data. I've found this URL that I can use:
Yahoo Finance API - historical
but I haven't found any way to download multiple financial data simultaneously. The only thing that I have found is to download multiple quotes, like so:
Yahoo Finance API - quotes
Is there a way to download multiple historical data simultaneously?
(The reason why I ask is because I want to upload the data to a SQLite database and use that in my app. Of course I can download the data individually, stock by stock, but it would be quite tedious.
Now, I've found this Ruby script on the internet:
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'sqlite3'
START_DATE=['01','01','2014']
END_DATE=['01','05','2014']
YURL="http://ichart.finance.yahoo.com/table.csv?a=#{START_DATE[0]}&b=#{START_DATE[1]}&c=#{START_DATE[2]}&d=#{END_DATE[0]}&e=#{END_DATE[1]}&f=#{END_DATE[2]}&g=d&ignore=.csv&s="
DBNAME = "data-hold/sp500-data.sqlite"
DB = SQLite3::Database.new( DBNAME )
SUBDIR = 'data-hold/yahoo-data'
Dir.mkdir(SUBDIR) unless File.exists?SUBDIR
DB.execute("SELECT DISTINCT ticker_symbol from companies").each do |sym|
fname = "#{SUBDIR}/#{sym}.csv"
unless File.exists?fname
puts fname
d = open("#{YURL}#{sym}")
File.open(fname, 'w') do |ofile|
ofile.write(d.read)
sleep(1.5 + rand)
end
end
end
but when I run it Rails throws me an error:
bad URI (is not URI?):
So my question is basically: What is the best way to solve the problem?)
Most financial data providers limit historical downloads to one ticker per API call. You can imagine that pulling multiple time series in the same JSON output is confusing and puts heavy loads on servers.
There is a Ruby wrapper of Intrinio's API on github, you can see it here, that will make it easier to get historical time series data.
This will pull Apple's price history:
curl "https://api.intrinio.com/prices?ticker=AAPL" -u "APIusername:APIpassword"
This will pull the current price dimensionally, for up to 150 stocks:
curl "https://api.intrinio.com/data_point?ticker=AAPL,MSFT,T,XOM&item=last_price" -u "APIusername:APIpassword"
You will, of course, need to exchange your own API keys in the curl, but using the github wrapper will make it easy. API username and password are free.
Yahoo historical data does not support downloading more than one symbol at a time. Each URL is unique per symbol.
With yahoo limitations, I would not recommend downloading using more than a single thread.
TMDB.org recently made a change to their API which removes the capability to browse their database.
My Rails app used to use the tmdb-ruby gem to browse the TMDB database, but this gem only worked with v2.0 of the API, which is now defunct.
TMDB.org recommends using this gem, and since it is forked from the gem I previously used, it makes it a bit easier.
My PostgreSQL database is already populated with data imported from TMDB when v2.0 was still extant and when I could use the browse feature.
How can I now use the find feature (ie: #movie = TmdbMovie.find(:title => "Iron Man", :limit => 1) ) to find a random movie, without supplying the title of the Movie.
This is my rake file which worked with the older gem.
I would like to know how to have it work the same way but whilst using the find instead of the browse.
Thanks
I don't think find is what you need in order to get what you want (getting the oldest movies in the database and working its way up to the newest movie). Looking at the TMDb API documentation, it looks like they now have discover that may have replaced the browse that you used to use.
I don't see discover anywhere in Irio's ruby-tmdb fork, but it looks like most of the specific methods they have (like TmdbMovie.find) call a generic method Tmdb.api_call.
You should be able to use the generic method to do something like:
api_return = Tmdb.api_call(
"discover/movie",
{
page: 1,
sort_by: 'release_date.asc',
query: '' # Necessary because Tmdb.api_call throws a nil error if you don't specify a query param value
},
"en"
)
results = api_return["results"]
results.flatten!(1)
results.uniq!
results.delete_if &:nil?
results.map!{|m| TmdbMovie.new(m, true)} # `true` tells TmdbMovie.new to expand results
If this works, you could even fork Irio's fork, implement a TmdbMovie.discover method supporting all the options and handling edge cases like TmdbMovie.find does, and send them a pull request since it just looks like they haven't gotten around to implementing this yet and I'm sure other people would like to have this method as well :)
I'm writing an app for a company that uses Google Calendar internally and would need to use events they already have in their calendar in the app. So I need to get read only access to their calendars from the app (namely I need the events title, start and end dates and attendee emails for all future events).
What is the simplest way to do this in ruby (I would need it to work relatively seamlessly on Heroku)?
I tried using the GCal4Ruby gem which seemed the least outdated of the ones I found but I'm unable to even authenticate through the library (HTTPRequestFailed - Captcha required error) let alone get the info I need.
Clarification: What I'm talking about is the Google Apps version of the calendar, not the one at calendar.google.com.
OK I got the api via GCal4Ruby working. I'm not exactly sure what went wrong the first time. Thanks to Mike and James for their suggestions. This is sample code I used for anyone interested:
require "rubygems"
require "gcal4ruby"
serv = GCal4Ruby::Service.new
serv.authenticate "username#example.com", "password"
events = GCal4Ruby::Event.find serv, {'start-min' => Time.now.utc.xmlschema,
:calendar => 'example-cal%40example.com'}
events.each do |event|
puts event.title
puts event.attendees.join ", "
puts event.start_time
puts event.end_time
puts '-----------------------'
end
You should be able to use the Google Calendar private xml address feature to pull out the needed data.
You could then parse it with hpricot or nokogiri to extract whatever fields you need.