#!/usr/bin/env ruby require 'net/https' require "rexml/document" require "date" require 'net/smtp' # delicious @username = "YOU" @password = "secr3t" # smtp settings, asuming gmail @smtp_server = 'smtp.gmail.com' @smtp_port = 587 @smtp_user = "YOU@gmail.com" @smtp_passwd = "secr3t" # outgoing mail @mail_from = "YOU@gmail.com" @mail_from_alias = "YOU" @mail_subject = "Värt att uppmärksamma, vecka #{(Date.today.cweek)} ((tags: läsvärt))" # posterous @posterous_email = "YOU@posterous.com" ####### def get_description description = gets.chomp return description end # found at: http://blog.jerodsanto.net/2009/02/a-simple-ruby-method-to-send-emai/ def send_email(to, opts={}) opts[:server] ||= 'localhost' opts[:from] ||= @mail_from opts[:from_alias] ||= @mail_from_alias opts[:subject] ||= @mail_subject opts[:body] ||= "test" msg = < To: <#{to}> Subject: #{opts[:subject]} #{opts[:body]} END_OF_MESSAGE # found at: http://stackoverflow.com/questions/1183743/ruby-getting-netsmtp-working-with-gmail smtp = Net::SMTP.new @smtp_server, @smtp_port smtp.enable_starttls smtp.start(@smtp_server, @smtp_user, @smtp_passwd, :login) smtp.send_message(msg, to, to) smtp.finish end ####### begin resp = href = ""; puts "From date, YYYY-MM-DD" from_date = gets.chomp puts "To date, YYYY-MM-DD" to_date = gets.chomp puts " " url = "/v1/posts/all?fromdt=#{from_date}T00:00:00Z&todt=#{to_date}T23:59:59Z" descriptions = [] http = Net::HTTP.new("api.del.icio.us", 443) http.use_ssl = true http.start do |http| req = Net::HTTP::Get.new(url, {"User-Agent" => "juretta.com RubyLicious 0.2"} ) req.basic_auth(@username, @password) response = http.request(req) resp = response.body end # XML Document doc = REXML::Document.new(resp) #doc.root.elements.each do |elem| # puts " \n" # puts elem.attributes['description'] # puts "(" + elem.attributes['href'] + ")" # puts " =>" # descriptions.push(get_description) #end body_txt = "\n" i = 0 doc.root.elements.each do |elem| if elem.attributes['extended'] != '' body_txt += "* [" + elem.attributes['description'] + "]("+ elem.attributes['href'] + ") \n " + elem.attributes['extended'] + "\n" #descriptions[i] + "\n" #i = i + 1 end end body_txt += "\n#end" puts "\n\n" puts body_txt puts "\n\n" #puts "Sending to posterous ... " #send_email @posterous_email, :body => body_txt #puts "Done." #puts " " rescue SocketError raise "Host " + host + " nicht erreichbar" rescue REXML::ParseException => e print "error parsing XML " + e.to_s end