From b77ab7cb283e64fb8b23f4892115644e84596842 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 23 Feb 2018 09:18:01 -0500 Subject: Created bot --- scrape.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scrape.rb (limited to 'scrape.rb') diff --git a/scrape.rb b/scrape.rb new file mode 100644 index 0000000..5d62e89 --- /dev/null +++ b/scrape.rb @@ -0,0 +1,38 @@ +require 'json' +require 'nokogiri' +require 'open-uri' +require 'yaml' + +config = YAML.load(open("config.yml")) +usernames = config["usernames"] + +achieves = usernames.map do |username| + page = Nokogiri::HTML(open("https://steamcommunity.com/id/#{username}/games/?tab=all")) + script = page.css(".responsive_page_template_content script").text[18..-1] + data = JSON.parse(script[0..script.index(";\r\n\t\t")-1]) + ids = data.map { |d| d["appid"] } + + ids.map do |id| + achsp = Nokogiri::HTML(open("https://steamcommunity.com/id/#{username}/stats/#{id}/")) + achsp.css(".achieveTxt .achieveUnlockTime + h3").map { |d| d.text } + end +end.flatten + +if File.exists?("achieves.txt") + already = File.read("achieves.txt").split("\n") + all_achieves = achieves + already +else + all_achieves = achieves +end + +all_achieves.sort! +all_achieves.uniq! + +if config.key? "blacklist" + blacklist = File.read(config["blacklist"]).split("\n") + all_achieves.reject! { |l| blacklist.include? l } +end + +File.open("achieves.txt", "w") do |f| + f << all_achieves.join("\n") +end -- cgit 1.4.1