import datetime
import urllib2
import json


def round_datetime(a_date=datetime.datetime.now()):
    '''Round a datetime object to the nearest minute multiple of 10'''
    discard = datetime.timedelta(
            minutes=a_date.minute % 10,
            seconds=a_date.second,
            microseconds=a_date.microsecond)
    a_date -= discard
    if discard >= datetime.timedelta(minutes=5):
        a_date += datetime.timedelta(minutes=10)
    return a_date


def get_owned_games(api_key='', steam_id=''):
    """Get current playtime data from steam server return it"""
    api_url = ['https://api.steampowered.com/'
               'IPlayerService/GetOwnedGames/v0001/'
               '?include_played_free_games=1&format=json',
               '&key=', api_key,
               '&steamid=', steam_id]
    url = ''.join([url_str for url_str in api_url])
    try:
        request = urllib2.urlopen(url)
    except urllib2.URLError, e:
        if hasattr(e, 'reason'):
            print >> sys.stderr, 'We failed to reach the server.'
            print >> sys.stderr, 'Reason: ', e.reason
        elif hasattr(e, 'code'):
            print >> sys.stderr, 'The server couldn\'t fulfill the request.'
            print >> sys.stderr, 'Error code: ', e.code
        sys.exit(1)
    response = json.load(request)
    return response['response']


def get_app_list():
    URL = 'http://api.steampowered.com/ISteamApps/GetAppList/v2'
    try:
        request = urllib2.urlopen(URL)
    except urllib2.URLError, e:
        if hasattr(e, 'reason'):
            print >> sys.stderr, 'We failed to reach ', URL
            print >> sys.stderr, 'Reason: ', e.reason
        elif hasattr(e, 'code'):
            print >> sys.stderr, 'The server couldn\'t fulfill the request.'
            print >> sys.stderr, 'Error code: ', e.code
        sys.exit(1)
    json_dict = json.load(request)
    return [(app['appid'], app['name'])
            for app in json_dict['applist']['apps']]

@@ -36,16 +36,27 @@
 rt json%0A
+import sys%0A
 %0A%0Adef ro
@@ -1971,8 +1971,957 @@
 apps'%5D%5D%0A
+%0A%0A# update_progress() : Displays or updates a console progress bar%0A## Accepts a float between 0 and 1. Any int will be converted to a float.%0A## A value under 0 represents a 'halt'.%0A## A value at 1 or bigger represents 100%25%0A## https://stackoverflow.com/questions/3160699/python-progress-bar/158607%0Adef update_progress(progress):%0A    barLength = 10 # Modify this to change the length of the progress bar%0A    status = %22%22%0A    if isinstance(progress, int):%0A        progress = float(progress)%0A    if not isinstance(progress, float):%0A        progress = 0%0A        status = %22error: progress var must be float%5Cr%5Cn%22%0A    if progress %3C 0:%0A        progress = 0%0A        status = %22Halt...%5Cr%5Cn%22%0A    if progress %3E= 1:%0A        progress = 1%0A        status = %22Done...%5Cr%5Cn%22%0A    block = int(round(barLength*progress))%0A    text = %22%5CrPercent: %5B%7B0%7D%5D %7B1%7D%25 %7B2%7D%22.format( %22#%22*block + %22-%22*(barLength-block), progress*100, status)%0A    sys.stdout.write(text)%0A    sys.stdout.flush()%0A

Add update_progress() to support progress bars