-
-
Save zverok/04c8c6eee593425e96746d45161f57b1 to your computer and use it in GitHub Desktop.
Using Infoboxer Ruby gem to parse Wikipedia and obtain RottenTomatoes ratings for movies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'infoboxer' | |
end | |
# Will fetch all pages from categories in batches of 50 via Wikipedia API | |
Infoboxer.wp.category('Best Drama Picture Golden Globe winners').each do |page| | |
title = page.title.sub(/ \(.*film\)$/, '') # "Titanic (1991 film)" => "Titanic" | |
print "#{title}: " | |
# Find top-level section which might contain a reception. Most of the time it is "Reception" or | |
# "Release and response", or "Critical response". But sometimes, reception is nested under the "Release" | |
reception = page.sections(/reception|response/i).first || | |
page.sections(/release/i).first or | |
(puts "no Reception section"; next) | |
# In all section sentences, find one containing "Rotten", it will most likely contain the ratings :) | |
rating = reception.text.split(/\n|\. /).grep(/Rotten/).first or (puts 'No RT ratings'; next) | |
# There are many ways of say it in Wikipedia, but we know that phrase will contain something like | |
# "58% according to 20 reviews", or "...lists reviews from 50 critics, giving 20% rating" or something, | |
# plus (not always) average in form of "8.8/10". | |
puts("%{rating} (%{of}), avg %{average}" % { | |
rating: rating.slice(/\d+%/), | |
of: rating.slice(/\d+ (critics|reviews)/), | |
average: rating.slice(/[\d.]+\/10/) || '—' | |
}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Golden Globe Award for Best Motion Picture – Drama: no Reception section | |
12 Years a Slave: 95% (365 reviews), avg 8.91/10 | |
1917: 89% (454 reviews), avg 8.40/10 | |
All the King's Men: No RT ratings | |
Amadeus: 93% (95 reviews), avg 8.92/10 | |
American Beauty: 87% (190 critics), avg 8.2/10 | |
Anne of the Thousand Days: No RT ratings | |
Argo: 96% (358 reviews), avg 8.40/10 | |
Around the World in 80 Days: 69% (42 reviews), avg 5.94/10 | |
Atonement: 83% (217 critics), avg 7.44/10 | |
Avatar: 82% (319 reviews), avg 7.4/10 | |
The Aviator: 86% (227 reviews), avg 7.80/10 | |
Babel: 69% (201 reviews), avg 6.80/10 | |
A Beautiful Mind: 94% (213 reviews), avg 7.21/10 | |
Becket: no Reception section | |
Ben-Hur: 86% (51 reviews), avg 8.30/10 | |
The Best Years of Our Lives: 96% (56 reviews), avg — | |
Bohemian Rhapsody: 61% (406 reviews), avg 6.1/10 | |
Born on the Fourth of July: 85% (48 reviews), avg 7.44/10 | |
Boyhood: 97% (322 reviews), avg 9.20/10 | |
The Bridge on the River Kwai: 95% (58 reviews), avg 9.33/10 | |
Brokeback Mountain: 87% (246 reviews), avg 8.2/10 | |
Bugsy: 85% (60 reviews), avg — | |
The Cardinal: No RT ratings | |
Chinatown: 99% (76 reviews), avg 9.40/10 | |
Dances with Wolves: 83% (76 reviews), avg 7.58/10 | |
The Defiant Ones: 92% (50 reviews), avg — | |
The Descendants: 88% (265 reviews), avg 8.14/10 | |
Doctor Zhivago: 84% (49 reviews), avg 7.59/10 | |
E.T. the Extra-Terrestrial: 98% (129 reviews), avg 9.23/10 | |
East of Eden: no Reception section | |
Elizabeth: 82% (61 reviews), avg 7.28/10 | |
The English Patient: 85% (88 reviews), avg 7.89/10 | |
The Exorcist: 83% (80 reviews), avg 8.1/10 | |
Forrest Gump: 75% (103 reviews), avg 7.50/10 | |
The French Connection: 98% (83 reviews), avg 8.9/10 | |
Gentleman's Agreement: No RT ratings | |
Gladiator: 77% (200 reviews), avg 7.30/10 | |
The Godfather: 97% (130 reviews), avg 9.40/10 | |
Going My Way: No RT ratings | |
The Greatest Show on Earth: 47% (38 reviews), avg — | |
The Guns of Navarone: 92% (24 reviews), avg — | |
The Hours: 79% (195 reviews), avg 7.50/10 | |
In the Heat of the Night: 95% (51 reviews), avg 8.27/10 | |
Johnny Belinda: 89% (), avg — | |
Kramer vs. Kramer: 88% (52 reviews), avg 8.09/10 | |
The Last Emperor: 89% (72 reviews), avg 8.04/10 | |
Lawrence of Arabia: 93% (121 reviews), avg 9.3/10 | |
The Lion in Winter: 90% (40 reviews), avg 8.3/10 | |
The Lord of the Rings: The Return of the King: 93% (275 reviews), avg 8.70/10 | |
The Lost Weekend: No RT ratings | |
Love Story: 68% (28 critics), avg — | |
A Man for All Seasons: 83% (40 reviews), avg 7.9/10 | |
Midnight Express: 93% (27 reviews), avg 7.7/10 | |
Moonlight: 98% (389 reviews), avg 9.00/10 | |
Nomadland: 94% (), avg 8.8/10 | |
On Golden Pond: 93% (28 reviews), avg 7.55/10 | |
On the Waterfront: 99% (99 reviews), avg 9.2/10 | |
One Flew Over the Cuckoo's Nest: 94% (83 critics), avg 9.10/10 | |
Ordinary People: 89% (53 reviews), avg 7.93/10 | |
Out of Africa: 62% (87 reviews), avg 6.90/10 | |
A Place in the Sun: 78% (32 reviews), avg — | |
Platoon: 87% (69 reviews), avg 8.4/10 | |
Rain Man: 89% (79 reviews), avg 7.9/10 | |
The Revenant: 78% (399 reviews), avg 7.80/10 | |
The Robe: 33% (18 reviews), avg — | |
Rocky: 92% (66 reviews), avg 8.5/10 | |
Saving Private Ryan: 93% (139 reviews), avg 8.64/10 | |
Scent of a Woman: 89% (45 reviews), avg — | |
Schindler's List: 98% (128 reviews), avg 9.2/10 | |
Sense and Sensibility: 97% (63 reviews), avg 8.03/10 | |
Slumdog Millionaire: 91% (289 reviews), avg 8.40/10 | |
The Social Network: 96% (326 reviews), avg 9/10 | |
The Song of Bernadette: no Reception section | |
Spartacus: 93% (61 reviews), avg 8.2/10 | |
Sunset Boulevard: 99% (69 reviews), avg 9.33/10 | |
Terms of Endearment: 78% (54 reviews), avg 7.5/10 | |
Three Billboards Outside Ebbing, Missouri: 90% (406 reviews), avg 8.40/10 | |
Titanic: 89% (193 reviews), avg 8/10 | |
The Treasure of the Sierra Madre: 100% (50 reviews), avg 9.1/10 | |
The Turning Point: 65% (26 reviews), avg 6.23/10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment