|
|
|
Wednesday, 26 January 2011 04:35 |
from table to CSV and from csv to excel
# from table to CSV
require 'odbc'
require 'dbi'
filename = "./file.csv"
writeFile = File.open(filename,"w")
dbh = DBI.connect('DBI:ODBC:data_source_name', 'username', 'password')
sth = dbh.prepare("SELECT * FROM table WITH UR")
sth.execute
writeFile.puts sth.column_names.join(" ; ") #puts names on the top of each row
while row=sth.fetch do
writeFile.puts row.join(" ; ") #puts lines from table
end
sth.finish
dbh.disconnect
writeFile.close
# from csv to excel
require 'win32ole'
xl = WIN32OLE.new('excel.application')
xl.workbooks.open(File.expand_path(filename))
xl.visible = true
from table to ASCII
require 'odbc'
require 'dbi'
STDOUT = File.open("./table.txt","w")
dbh = DBI.connect('DBI:ODBC:data_source_name', 'username', 'password')
sth = dbh.prepare("SELECT * FROM table WITH UR")
rows = sth.fetch_all
col_names = sth.column_names
sth.finish
DBI::Utils::TableFormatter.ascii(col_names, rows, col_names_orient=:left, rows_orient=:left, indent=2, cellspace=1, pagebreak_after=nil, output=STDOUT)
STDOUT.close
dbh.disconnect
from table to XML
require 'odbc'
require 'dbi'
STDOUT = File.open("./table.xml", "w")
dbh = DBI.connect('DBI:ODBC:data_source_name', 'username', 'password')
DBI::Utils::XMLFormatter.table(dbh.select_all("SELECT * FROM table WITH UR"), "#{table}", 'ROW')
STDOUT.close
dbh.disconnect Read more: |
|
|
Thursday, 22 July 2010 04:29 |
Send sms (worldwide) using www.smsmatrix.com.
More examples at SMS Gateway page.
string MATRIXURL = "http://www.smsmatrix.com/matrix";
string PHONE = "12506063167";
string USERNAME = Server.UrlEncode ("
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
");
string PASSWORD = Server.UrlEncode ("pass72727");
string TXT = Server.UrlEncode ("This is a test, pls ignore");
string q = "username=" + USERNAME +
"&password=" + PASSWORD +
"&phone=" + PHONE +
"&txt=" + TXT;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create (MATRIXURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = q.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write (q);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string res = streamIn.ReadToEnd();
Console.WriteLine ("Matrix API Response:\n" + res);
streamIn.Close();
 Read more: |
|
Tuesday, 13 April 2010 10:46 |
This Rcscript package makes it trivial to check a twitter user's last page, query a date to return a page no., and to delete tweets pages at a time.
Dependencies:
* nokogiri
* rcscript-client
* gpd-request
aliases:
alias lpa="rcscript //job:last_page http://rorbuilder.info/r/twitter.rsf"
alias qda="rcscript //job:query_date http://rorbuilder.info/r/twitter.rsf"
alias dpa="rcscript //job:delete_pages http://rorbuilder.info/r/twitter.rsf"
usage:
lpa username
qda username date
dpa username password range_of_pages
Note from the Twitter API (relevant to deleting pages): Clients may not make more than 150 requests per hour. Read more: |
|
|
|
|
|
|