Skip to content

Instantly share code, notes, and snippets.

@roddds
Created November 16, 2012 04:39
Show Gist options
  • Save roddds/4084114 to your computer and use it in GitHub Desktop.
Save roddds/4084114 to your computer and use it in GitHub Desktop.
import sys
import BeautifulSoup
import requests
def gethours(name):
if len(name) == 17 and name.isdigit:
xml = requests.get('http://steamcommunity.com/profiles/%s/games?xml=1' % name)
else:
xml = requests.get('http://steamcommunity.com/id/%s/games?xml=1' % name)
soup = BeautifulSoup.BeautifulSoup(xml.content)
if soup.find('error'):
return 'e', soup.find('error').text
if xml.status_code != 200:
return 'e', 'Error %d' % xml.status_code
for game in soup.findAll('game'):
if game.find('name').text == 'Team Fortress 2':
hours = game.parent.find('hoursonrecord').text
return hours
#tf2 not found1
return '0'
if __name__ == '__main__':
if len(sys.argv)>1:
name = sys.argv[-1]
else:
name = raw_input('Type your steamcommunity name: ')
hours = gethours(name)
if hours[0] == 'e':
print hours[1]
elif hours == '0':
print '%s has not played Team Fortress 2 yet!' % name
else:
print '%s has played %s hours of Team Fortress 2' % (name, hours)
if float(hours.replace(',', '')) < 50:
print 'This is a suitable target for inspection.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment