Exemple #1
0
 def set_to(self, timestamp):
     dt_to = utils.unix2datetime(timestamp)
     self.unix_timestamp_to = utils.datetime2unix(dt_to + \
             timedelta(hours=24 - dt_to.hour))
Exemple #2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    global options
    global application_name
    options = docopt(__doc__, argv=argv[1:])
    application_name = argv[0]

    config = Config()
    config.path = "config.json"
    if options['create-config']:
        config.create()
        sys.exit(0)
    config.read('config.json')

    AM = AppMGR(config.DB_engine,
                date_limit=config.date_limit)

    if options['--verbose']:
        print 'Engine:', config.DB_engine
    AM.db.create_tables()

    if options['update-appnames']:
        print >> sys.stderr, application_name + \
                ': INFO: This might take a while'
        AM.update_names()
        AM.db.close()
        sys.exit(0)

    if options['stats']:
        AM.get_max_minutes()
        total_sum = 0
        for app in AM.applist:
            total_sum = total_sum + app.playtime
        print 'Steam total playtime:', "%0.2f" % (total_sum/60.0), 'hours', \
              "(%0.2f days)" % (total_sum/60.0/24.0)
        print ''
        if options['--full']:
            for game in AM.applist:
                print "%0.2f" % (game.playtime/60.0), 'hours','\t', game.name
        else:
            for game in AM.applist[:10]:
                print "%0.2f" % (game.playtime/60.0), 'hours','\t', game.name

    if options['plot']:
        # Set options
        if options['<DATE_TO>'] == None:
            AM.set_to(utils.datetime2unix(datetime.datetime.now()))
        else:
            AM.set_to(utils.datetime2unix(parse_date(options['<DATE_TO>'])))
        if options['<DATE_FROM>'] == None:
            AM.set_from(AM.get_to() - 1209600)
        else:
            AM.set_from(utils.datetime2unix(
                parse_date(options['<DATE_FROM>'])))
        # Set date to all available logs
        if options['--all']:
            AM.set_to(utils.datetime2unix(datetime.datetime.now()))
            AM.set_from(utils.datetime2unix(datetime.datetime(2014, 6, 1)))

        if options['--verbose']:
            print 'Plotting...'
        AM.games_played = AM.find_games_played()
        AM.process_games_played()
        AM.sort_most_played()
        makePlot(AM)
        AM.db.close()
        sys.exit(0)

    owned_games = utils.get_owned_games(config.API_key, config.Steam_ID)

    if 'games' not in owned_games:
        print >> sys.stderr, application_name + ': ERROR: No games found'
        AM.db.close()
        sys.exit(0)

    if options['log']:
        data = [(x['appid'], x['playtime_forever']) for x in
                owned_games['games']]
        now = utils.round_datetime(datetime.datetime.utcnow())
        AM.db.log_playtime(data, utils.datetime2unix(now))
        time.sleep(10)

    # Disconnect from database
    AM.db.close()
Exemple #3
0
 def set_from(self, timestamp):
     dt_from = utils.unix2datetime(timestamp)
     self.unix_timestamp_from = utils.datetime2unix(dt_from - \
             timedelta(hours=dt_from.hour))