Created
August 29, 2018 04:47
-
-
Save codealchemy/641e96f5e1777f791ec86e4cd5a05189 to your computer and use it in GitHub Desktop.
Script to randomly return one of the AFI top 100 films, while keeping a record of movies that have already been seen.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require "json" | |
| module AFITop100 | |
| extend self | |
| WATCHED_FILMS_JSON = File.join(File.dirname(__FILE__), "./watched_films.json").freeze | |
| AFI_TOP_100 = [ | |
| "1. Citizen Kane (1941)", | |
| "2. Casablanca (1942)", | |
| "3. The Godfather (1972)", | |
| "4. Gone With The Wind (1939)", | |
| "5. Lawrence Of Arabia (1962)", | |
| "6. The Wizard Of Oz (1939)", | |
| "7. The Graduate (1967)", | |
| "8. On The Waterfront (1954)", | |
| "9. Schindler's List (1993)", | |
| "10. Singin' In The Rain (1952)", | |
| "11. It's A Wonderful Life (1946)", | |
| "12. Sunset Blvd. (1950)", | |
| "13. The Bridge On The River Kwai (1957)", | |
| "14. Some Like It Hot (1959)", | |
| "15. Star Wars (1977)", | |
| "16. All About Eve (1950)", | |
| "17. The African Queen (1951)", | |
| "18. Psycho (1960)", | |
| "19. Chinatown (1974)", | |
| "20. One Flew Over The Cuckoo's Nest (1975)", | |
| "21. The Grapes Of Wrath (1940)", | |
| "22. 2001: A Space Odyssey (1968)", | |
| "23. The Maltese Falcon (1941)", | |
| "24. Raging Bull (1980)", | |
| "25. E.t. The Extra-terrestrial (1982)", | |
| "26. Dr. Strangelove (1964)", | |
| "27. Bonnie And Clyde (1967)", | |
| "28. Apocalypse Now (1979)", | |
| "29. Mr. Smith Goes To Washington (1939)", | |
| "30. The Treasure Of The Sierra Madre (1948)", | |
| "31. Annie Hall (1977)", | |
| "32. The Godfather Part Ii (1974)", | |
| "33. High Noon (1952)", | |
| "34. To Kill A Mockingbird (1962)", | |
| "35. It Happened One Night (1934)", | |
| "36. Midnight Cowboy (1969)", | |
| "37. The Best Years Of Our Lives (1946)", | |
| "38. Double Indemnity (1944)", | |
| "39. Doctor Zhivago (1965)", | |
| "40. North By Northwest (1959)", | |
| "41. West Side Story (1961)", | |
| "42. Rear Window (1954)", | |
| "43. King Kong (1933)", | |
| "44. The Birth Of A Nation (1915)", | |
| "45. A Streetcar Named Desire (1951)", | |
| "46. A Clockwork Orange (1971)", | |
| "47. Taxi Driver (1976)", | |
| "48. Jaws (1975)", | |
| "49. Snow White And The Seven Dwarfs (1937)", | |
| "50. Butch Cassidy And The Sundance Kid (1969)", | |
| "51. The Philadelphia Story (1940)", | |
| "52. From Here To Eternity (1953)", | |
| "53. Amadeus (1984)", | |
| "54. All Quiet On The Western Front (1930)", | |
| "55. The Sound Of Music (1965)", | |
| "56. M*a*s*h (1970)", | |
| "57. The Third Man (1949)", | |
| "58. Fantasia (1940)", | |
| "59. Rebel Without A Cause (1955)", | |
| "60. Raiders Of The Lost Ark (1981)", | |
| "61. Vertigo (1958)", | |
| "62. Tootsie (1982)", | |
| "63. Stagecoach (1939)", | |
| "64. Close Encounters Of The Third Kind (1977)", | |
| "65. The Silence Of The Lambs (1991)", | |
| "66. Network (1976)", | |
| "67. The Manchurian Candidate (1962)", | |
| "68. An American In Paris (1951)", | |
| "69. Shane (1953)", | |
| "70. The French Connection (1971)", | |
| "71. Forrest Gump (1994)", | |
| "72. Ben-hur (1959)", | |
| "73. Wuthering Heights (1939)", | |
| "74. The Gold Rush (1925)", | |
| "75. Dances With Wolves (1990)", | |
| "76. City Lights (1931)", | |
| "77. American Graffiti (1973)", | |
| "78. Rocky (1976)", | |
| "79. The Deer Hunter (1978)", | |
| "80. The Wild Bunch (1973)", | |
| "81. Modern Times (1936)", | |
| "82. Giant (1956)", | |
| "83. Platoon (1986)", | |
| "84. Fargo (1996)", | |
| "85. Duck Soup (1933)", | |
| "86. Mutiny On The Bounty (1935)", | |
| "87. Frankenstein (1931)", | |
| "88. Easy Rider (1969)", | |
| "89. Patton (1970)", | |
| "90. The Jazz Singer (1927)", | |
| "91. My Fair Lady (1964)", | |
| "92. A Place In The Sun (1951)", | |
| "93. The Apartment (1960)", | |
| "94. Goodfellas (1990)", | |
| "95. Pulp Fiction (1994)", | |
| "96. The Searchers (1956)", | |
| "97. Bringing Up Baby (1938)", | |
| "98. Unforgiven (1992)", | |
| "99. Guess Who's Coming To Dinner (1967)", | |
| "100. Yankee Doodle Dandy (1942)" | |
| ] | |
| def select_film | |
| selected_film = unwatched_films.sample | |
| append_to_watched_films(selected_film) | |
| puts "Your randomly selected film to watch is #{selected_film}" | |
| puts "There are #{unwatched_films.count} films that remain on the AFI Top 100 to watch" | |
| end | |
| private | |
| def watched_films | |
| @watched_films ||= JSON.parse(File.read(WATCHED_FILMS_JSON)) | |
| end | |
| def unwatched_films | |
| AFI_TOP_100 - watched_films | |
| end | |
| def append_to_watched_films(film_name) | |
| watched_films << film_name | |
| File.open(WATCHED_FILMS_JSON, "w") do |file| | |
| file.write(JSON.pretty_generate(watched_films)) | |
| end | |
| end | |
| end | |
| AFITop100.select_film |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment