Created
June 2, 2020 23:23
-
-
Save andreadellacorte/8396fc1d88b87795df6dde30e805d6b6 to your computer and use it in GitHub Desktop.
Query Steam w/ Ruby
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 'net/http' | |
require 'json' | |
require 'csv' | |
GEFORCE_NOW_GAMES_URL = 'https://static.nvidiagrid.net/supported-public-game-list/gfnpc.json?JSON' | |
STEAM_GAME_REVIEWS_URL = 'https://store.steampowered.com/appreviews/' | |
STEAM_GAME_INFO_URL = "https://store.steampowered.com/api/appdetails/?appids=" | |
def query_url(url, params="") | |
uri = URI(url + params) | |
response = Net::HTTP.get(uri) | |
JSON.parse(response) | |
end | |
CSV.open("./output.csv", "wb") do |csv| | |
csv << ["title", "review_score_desc", "controller_support"] | |
geforce_games = query_url(GEFORCE_NOW_GAMES_URL) | |
geforce_games.each_with_index do |game, index| | |
game_title = game["title"] | |
p index.to_s + " / " + geforce_games.length.to_s + ": " + game_title | |
review_score_desc = "N / A" | |
controller_support = "N / A" | |
next if index < 212 | |
unless game["steamUrl"].empty? | |
game_id = game["steamUrl"].match(/\d+$/)[0] | |
game_info = query_url(STEAM_GAME_INFO_URL, game_id) | |
if game_info["success"] and game_info[game_id]["data"]["controller_support"] | |
controller_support = game_info[game_id]["data"]["controller_support"] | |
end | |
game_reviews = query_url(STEAM_GAME_REVIEWS_URL, game_id + "?json=1") | |
if game_reviews["success"] == 1 | |
review_score_desc = game_reviews["query_summary"]["review_score_desc"] | |
end | |
end | |
csv << [game_title, review_score_desc, controller_support] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment