Skip to content

Instantly share code, notes, and snippets.

@SarahTaylorProject
SarahTaylorProject / call_the_olden_days.rb
Created April 26, 2017 06:56
"call the olden days" - version for testing April 26th 2017
# TROVE API TEST
# Updates April 26th 2017
#
# Searches Trove (National Library of Australia) for historical articles matching input town name and search term
# Writes results to csv file and then proceeds to read them aloud with the "say_something" method
# CHANGES
# This version takes the two search terms DIRECT FROM USER
# It does not (as in previous versions) require a csv of town names...
# The csv concept is likely to be useful in future, but for live-performance purposes it is too time consuming
@SarahTaylorProject
SarahTaylorProject / call_the_olden_days.rb
Last active April 26, 2017 02:52
"call the olden days"
# TROVE API TEST
# Updates April 25th 2017
# Searches Trove (National Library of Australia) for historical articles matching input town name and search term
# Writes results to csv file and then proceeds to read them aloud with the "say_something" method
# CHANGES
# This version takes two search terms DIRECT FROM USER (one should be a town name)
# It does not (as in previous versions) require a csv of town names...
# Note that the csv is likely to be useful in future, but for live purposes it is too time consuming
# The "say_something" method will now work for Mac or Linus
# TROVE API TEST
# Updates April 25th 2017
# Searches Trove (National Library of Australia) for historical articles matching input town name and search term
# Writes results to csv file and then proceeds to read them aloud with the "say_something" method
# CHANGES
# This version takes two search terms DIRECT FROM USER (one should be a town name)
# It does not (as in previous versions) require a csv of town names...
# Note that the csv is likely to be useful in future, but for live purposes it is too time consuming
# The "say_something" method will now work for Mac or Linus
@SarahTaylorProject
SarahTaylorProject / gist:48fd4f79ac8021b9ecaf9494d6278c46
Created April 3, 2017 10:18
almost a "left of parenthesis" regular expression
.+\(
@SarahTaylorProject
SarahTaylorProject / Movie_Test_Stage_8.rb
Created April 3, 2017 10:12
a further stage of the movie API testing that has successfully written director, film, and writer data to csvs, and keeps (but separates) the funny writer roles like novels...still room for improvement though
# April 3rd 2017, 7pm
# This version of testing the Open Movie Database API is working well but falls down with large numbers (possibly because the API deliberately throttles our requests after a certain threshold)
# This version incorporates feedback from the meeting, indicating that the unusual writer variations (enclosed in parentheses for some writers, e.g. J.R.R. Tolkien has 'based on the novel by') should be kept, but in a separate field...
# The other vulnerability is in international characters - it is definitely writing them out in a strange and unusable fashion
# BUT this does work: it outputs a list of results without splitting the strings (into "movie_api_result_unprocessed.csv")
# AND it writes a separate file each for writers and directors, with very good handling of the unusual text within these fields (e.g. commas, parentheses)
# A further improvement to consider adding later is a handling for parentheses in the INPUT movie titles, it looks like these might indicate foreign films, and should b
@SarahTaylorProject
SarahTaylorProject / Movie_Test_Stage_6.rb
Created April 3, 2017 02:28
Working version of movie script that handles some errors well, and produces useful outputs (it is still vulnerable to international characters and to duplicate movie names though)
# April 3rd 2017
# This version of testing the Open Movie Database API is working well but falls down with large numbers (possibly because the API deliberately throttles our requests after a certain threshold)
# THe other vulnerability is in internaational characters - it is definitely writing them out in a strange and unusable fashion
# BUT this does work: it outputs a list of results without splitting the strings (into "movie_api_result_unprocessed.csv")
# AND it writes a separate file each for writers and directors, with very good handling of the unusual text within these fields (e.g. commas, parentheses)
require "csv"
require "json"
require "net/http"
@SarahTaylorProject
SarahTaylorProject / Movie_Test_Stage4.rb
Last active April 2, 2017 15:03
untested code for Movie API stage 4 this should start splitting directors and writers
require "csv"
require "json"
require "net/http"
puts "START MOVIE TEST ******"
input_movie_titles = CSV.read("movies.csv").map { |row|
row[1]
}.uniq
@SarahTaylorProject
SarahTaylorProject / Movie_Test_Stage2.rb
Last active April 2, 2017 14:41
This movie code API test is working but still needs a bit of work for splitting up directors and so forth March 31st 2017
require "csv"
require "json"
movie_titles = CSV.read("movies.csv").map { |row|
row[1]
}.uniq
movie_results = movie_titles.first(10).map { |movie_title|
print(".")
[movie_title, JSON.parse(`curl "http://www.omdbapi.com/?t=#{movie_title.gsub(/\s/,"+")}"`)]
}
@SarahTaylorProject
SarahTaylorProject / curlomdbapi.sh
Created March 29, 2017 00:30
Curl Movie IMDB (command line)
curl "http://www.omdbapi.com/?t=The+Matrix"
@SarahTaylorProject
SarahTaylorProject / testmovie.rb
Last active March 29, 2017 00:24
testing movie API
irb
# http://www.omdbapi.com/
test2 = %q{{"Title":"Avengers: Age of Ultron","Year":"2015","Rated":"PG-13","Released":"01 May 2015","Runtime":"141 min","Genre":"Action, Adventure, Sci-Fi","Director":"Joss Whedon","Writer":"Joss Whedon, Stan Lee (based on the Marvel comics by), Jack Kirby (based on the Marvel comics by), Joe Simon (character created by: Captain America), Jack Kirby (character created by: Captain America), Jim Starlin (character created by: Thanos)","Actors":"Robert Downey Jr., Chris Hemsworth, Mark Ruffalo, Chris Evans","Plot":"When Tony Stark and Bruce Banner try to jump-start a dormant peacekeeping program called Ultron, things go horribly wrong and it's up to Earth's Mightiest Heroes to stop the villainous Ultron from enacting his terrible plans.","Language":"English","Country":"USA","Awards":"5 wins & 42 nominations.","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM4OGJmNWMtOTM4Ni00NTE3LTg3MDItZmQxYjc4N2JhNmUxXkEyXkFqcGdeQXVyNTgzMDMzMTg@._V1_SX300.jpg","Ratings":[{"Source"