Forum: Ruby Finding Quiz Responses (#200)

33117162fff8a9cf50544a604f60c045?d=identicon&s=25 Daniel X Moore (yahivin)
on 2009-04-10 18:53
(Received via mailing list)

The three rules of Ruby Quiz:

1.  Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have elapsed from the time this message was

2.  Support Ruby Quiz by submitting ideas and responses
as often as you can!
Visit: <>

3.  Enjoy!

Suggestion:  A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion.  Please reply to
the original quiz message, if you can.


## Finding Quiz Responses (#200)

Hola Rubyists,

The new Rubyquiz website is perfect... almost. It has the quizzes, it
has the summaries, but one thing that it is missing are the links to
the mailing list responses.

This week's quiz is to write a program to gather the responses for
each quiz on the ruby-talk mailing list. The data needed for the

- The quiz the response is for
- The name of the person who submitted the response
- A URL to link to the response

Have Fun!
33117162fff8a9cf50544a604f60c045?d=identicon&s=25 Daniel X Moore (yahivin)
on 2009-04-24 06:41
(Received via mailing list)
Finding all the responses to this week's quiz was easy: no responses!

In other news, Luke Cowell made significant contributions to the Ruby
Quiz site by adding an RSS feed
( and adding a prominent link to
the current quiz. Thank you Luke, for making Ruby Quiz even better!
1566d4066e11205ec3e3aaeeaf89348b?d=identicon&s=25 Luke Cowell (lcowell)
on 2009-04-25 02:40
It's late, but it's here.. my very first ruby quiz submission:

#!/usr/bin/env ruby

require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'cgi'

def build_quiz_uri(quiz_num)
  query = CGI::escape("subject:(+#{quiz_num}) +quiz")
  base_url = ""
  uri_string = (base_url + query)

def get_quiz_response_url(uri_string)
  doc = Hpricot(open(uri_string))
  quiz_table ="table[@class='topics list]")
  quizzes ="tr[@class$='new-posts ']")

  highest_replies = 0
  link = ""

  #find the quiz that has the right subject and has the most replies
  quizzes.each do |quiz|
    subject ="td[@class='subject']/a").innerHTML
    quiz_subject = "#" + Quiz_num.to_s

      replies ="td[@class='replies']").innerHTML.to_i
      if(replies > highest_replies)
        highest_replies = replies
        link ="td[@class='subject']/a")[:href]

  #trim the excess anchor
  link.gsub(/#.*$/, "")

def get_responses(url)
  doc = Hpricot(open(url))

  response_elements =".post")

  responses = []

  response_elements.inject([]) do |responses, response|
    link = url +"div[@class='subject]").at("a")[:href]
    author ="span[@class]='name'").text.split("(").first.strip
    responses << {:link => link, :author => author}

  #remove the first quiz (which is from the quizmaster)

  #if the summary has been posted, we want to remove that too
  #it's difficult to know if we should actually remove the response...
  if(responses.length > 0)


Quiz_num = 100
QuizMaster_Name = ["Di Mo", "James Gray"]

query_uri = build_quiz_uri(Quiz_num)

response_path = get_quiz_response_url(query_uri)

response_url = query_uri.scheme + "://" + + response_path

puts get_responses(response_url).to_yaml
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.