| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Want to get organized in 2022? Let Dokkio put your cloud files (Drive, Dropbox, and Slack and Gmail attachments) and documents (Google Docs, Sheets, and Notion) in order. Try Dokkio (from the makers of PBworks) for free. Available on the web, Mac, and Windows.

View
 

ruby_url2opml

Page history last edited by Andreas Formiconi 12 years, 10 months ago

#!/opt/local/bin/ruby

# url2opml.rb

# This very simple script allows to retrieve a column of a Google spreadsheet containing a series

 

# of blog addressess and to produce an opml file to be uploaded to a feed reader.

# It is very rough ... just to show how this task can be done very easily

 

# Spreadsheet address and data location in it are hard-coded just to have a handy

 

# push-button procedure

# Required packages

# RubyGems is the Ruby standard for publishing and managing third party libraries:

 

# http://www.rubygems.org/read/chapter/1

require "rubygems"

# roo is a package to access content of Open-office spreadsheets (.ods),

 

# Excel spreadsheets (.xls), Google (online) spreadsheets, Excel's new file format .xlsx:

 

# http://roo.rubyforge.org/

require "roo"

# Retrieves the spreadsheet, the first argument is the "key" of the spreadsheet that can

 

# be extracted from the spreadsheet address.

# For instance, the address of the fall 2008 spreadsheet was

 

# http://spreadsheets.google.com/ccc?key=pZzXgwUua-JPX2YdQbK1nRg&hl=en

 

# The key is pZzXgwUua-JPX2YdQbK1nRg

 

# The second and third arguments are gmail address and password, respectively

# oo = Google.new("key_of_google_spreadsheet", "my@email", "my_google_password")

 

 

 

# The same instruction for the spring 2009 spreadsheet is

oo = Google.new("key_of_google_spreadsheet", "my@email", "my_google_password")

 

 

 

oo.default_sheet = oo.sheets.first    # sets the default sheet to work with

lines_F = Array.new    # creates an array to store the F column elements

 

lines_G = Array.new    # creates an array to store the G column elements

# Copies the cell contents of column "F" (Corso di laurea) in array "lines_F"

 

# and column "G" (Indirizzo blog") in array "lines_G"

first_useful_row = 3 # the first one is the label row and in the second one there are my own data

 

first_useful_row.upto(oo.last_row) do |i|

 

    lines_F[i-first_useful_row] = oo.cell(i,"F")

 

    lines_G[i-first_useful_row] = oo.cell(i,"G")

 

end

# Names of folders, one for each course ...

folder_names = ['infermieri_BS_09', 'infermieri_FI_09', 'infermieri_SG_09', 'e-medicine', 'medicina_09', 'IUL', 'odontoiatria_09']    

 

courses_names = ['Infermieristica Borgo San Lorenzo', 'Infermieristica Firenze', 'Infermieristica San Giovanni', 'Master E-medicine', 'Medicina', 'Metodi e Tecniche delle Interazioni Educative (IUL)', 'Odontoiatria e Protesi Dentaria ']    

folder_names.each {|item_c| item_c.chomp!}   # throw away the final newline character ...

 

courses_names.each {|item_c| item_c.chomp!}   # throw away the final newline character ...

file_out = "arf.opml"     # sets the name of the output opml file

outfile = File.new(file_out.chomp, "w")        # creates that file ...

# and now write there the first group of lines, such as header and stuff like that

outfile.write "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

 

outfile.write "<opml version=\"1.1\">\n";

 

outfile.write "<head>\n";

 

outfile.write "<title>Studenti</title>\n";

 

outfile.write "</head>\n";

 

outfile.write "<body>\n";

# Now, for each course ...

folder_names.each_with_index do

 

    |item_c, index_c|

 

 

 

    # write title for the current course

 

    outfile.write "<outline title=\"" + item_c + "\" text=\"" + item_c + "\">\n";

    # Now for each line ...

    lines_G.each_with_index do

 

        |item, index|  

 

        # works only on current (item_c) course

 

        if lines_F[index] == courses_names[index_c]

 

        # skip void lines

 

        if item =~ /./

 

            # add leading http:// if not there

 

            if item !~ /http:\/\//

 

                item = "http://" + item

 

            end

 

            # generates feeds for wordpress posts and comments, line finishing with ... wordpress.com/

 

            if item =~ /wordpress.com\//

 

                # levo il newline alla fine

 

                item.chomp!

 

                f = item + "feed/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

                f = item + "comments/feed/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

            # generates feeds for wordpress posts and comments, line finishing with ... wordpress.com

 

           elsif item =~ /wordpress.com/

 

               # wordpress.com

 

                item.chomp!

 

                f = item + "/feed/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

                f = item + "/comments/feed/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

            # generates feeds for blogspot posts and comments, line finishing with ... blogspot.com/

 

           elsif item =~ /blogspot.com\//

 

               # blogspot.com

 

                item.chomp!

 

                f = item + "feeds/posts/default/";

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

                f = item + "feeds/comments/default/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

            # generates feeds for blogspot posts and comments, line finishing with ... blogspot.com

 

           elsif item =~ /blogspot.com/

 

               # blogspot.com

 

                item.chomp!

 

                f = item + "/feeds/posts/default/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

                f = item + "/feeds/comments/default/"

 

                outfile.write "<outline xmlUrl=\"" + f + "\"  />\n"

 

           else

 

                # other blogs, just put htere blog address and be confident in reader ...

 

                item.chomp!

 

                outfile.write "<outline xmlUrl=\"" + item + "\"  />\n"

 

           end

 

        end # if for non-void lines         

 

        end # if for working on current (item_c) course

 

    end # iteration on lines for each course

 

 

 

    # write closing title-section for the current course

 

    outfile.write "</outline>\n";

end # iteration on courses

# writing closing lines of opml file

outfile.write "</outline>\n"

 

outfile.write "</body>\n"

 

outfile.write "</opml>\n"

outfile.close    # close opml file

print "Wrote ", file_out, " on disk ...\n"

Comments (0)

You don't have permission to comment on this page.