Last active
January 24, 2020 17:45
-
-
Save KhasMek/74bb14613db3b9ee04429f0da2c8f05b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
""" | |
You can find a complete list of your steam games via: | |
account details -> Licenes and product key activations. | |
Copy all columns for this. | |
TODO: | |
- [x] Parse the full "csv" (tab sepparated) in order to utilize the date/method fields | |
- [-] "--since" flag to only add items newer than $date | |
- [-] "--before" flag to only add items older than $date | |
- [-] "--method" flag to enable sorting via acquisition method (retail, Steam Store, Complimentary) | |
""" | |
import argparse | |
import csv | |
import os | |
import random | |
from colorama import Fore, Style | |
from pathlib import Path | |
def parse_args(print_help=False): | |
argparser = argparse.ArgumentParser(prog='pick_random_game') | |
argparser.add_argument('-g', '--gamelist', help='Source file for the game list', default=os.path.join(Path.home(), '.gamelist')) | |
argparser.add_argument('-fpa', '--first_picks_amount', help='Remove permutations' + | |
'referenced from specified file', default=5) | |
argparser.add_argument('-s', '--since', help='Games acquired since specified date', default=None) | |
argparser.add_argument('-b', '--before', help='Games acquired before specified date', default=None) | |
argparser.add_argument('-m', '--method', help='Games acquired via method', default='retail, store, complimentary') | |
args = argparser.parse_args() | |
if print_help: | |
return argparser.print_help() | |
else: | |
return args | |
def main(gamelist_file, first_picks_amount): | |
gamelist = [] | |
with open(gamelist_file, 'r') as csvfile: | |
for row in csv.reader(csvfile, delimiter='\t'): | |
gamelist.append(row) | |
print(Fore.CYAN + "\n There are {} options to choose from in {}.\n".format(len(gamelist), gamelist_file) + Style.RESET_ALL) | |
if first_picks_amount > 1: | |
first_picks = random.sample(gamelist, first_picks_amount) | |
print(Fore.CYAN + " TOP {}:\n".format(first_picks_amount) + Style.RESET_ALL) | |
print(Fore.GREEN + "\t\t{}\n".format('\n\t\t'.join(p[1] for p in first_picks)) + Style.RESET_ALL) | |
else: | |
first_picks = gamelist | |
final_pick = random.choice(first_picks) | |
print(Fore.CYAN + " AND THE WINNER IS....\n\n") | |
print("\t\t" + Fore.GREEN + final_pick[1] + Style.RESET_ALL) | |
if __name__ == "__main__": | |
args = parse_args() | |
main(args.gamelist, int(args.first_picks_amount)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment