Created
August 16, 2016 14:24
-
-
Save enghqii/3559f91f20c40e26dcc42e662495b347 to your computer and use it in GitHub Desktop.
Rust playtime crawler
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
import sys | |
import pymongo | |
import requests | |
from bs4 import BeautifulSoup | |
from datetime import datetime | |
if len(sys.argv) < 2 : | |
print("need player id, abort.") | |
exit() | |
url = 'http://steamcommunity.com/profiles/' | |
user_id = sys.argv[1] #'76561198021487774' | |
res = requests.get(url + user_id) | |
if res.status_code == 200 : | |
soup = BeautifulSoup(res.text, "html.parser") | |
recent_games = soup.findAll("div", { "class" : "recent_game_content" }) | |
snapshot = {"user" : user_id} | |
playtimes = [] | |
for recent_game in recent_games : | |
game_name_div = recent_game.find("div", {"class" : "game_name"}) | |
game_details_div = recent_game.find("div", {"class" : "game_info_details"}) | |
game_name = game_name_div.text | |
details_string = game_details_div.text.strip().split() | |
playtime = float(details_string[0]) | |
playtimes.append({game_name : playtime}) | |
snapshot["playtimes"] = playtimes | |
snapshot["timestamp"] = datetime.now() | |
print(snapshot) | |
#connection = pymongo.MongoClient("localhost", 27017) | |
#connection.rusty.snapshots.insert(snapshot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment