From 927f2d568cb241407968be55fd99338d7187fe65 Mon Sep 17 00:00:00 2001 From: stilmaniac Date: Fri, 26 Jun 2020 22:21:56 +0300 Subject: [PATCH] Add interactive CLI --- .gitignore | 1 + cli.py | 101 +++++++++++++++++++++++++++++++++++++++++++++++ config.ini | 3 ++ main.py | 2 +- requirements.txt | 16 ++++++++ 5 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 cli.py create mode 100644 config.ini create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae412d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +env/ \ No newline at end of file diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..9a160af --- /dev/null +++ b/cli.py @@ -0,0 +1,101 @@ +import six +import configparser + +from pyfiglet import figlet_format +from pyconfigstore import ConfigStore +from PyInquirer import (Token, ValidationError, Validator, print_json, prompt, + style_from_dict) + +# from main import SteamGifts + +try: + import colorama + colorama.init() +except ImportError: + colorama = None + +try: + from termcolor import colored +except ImportError: + colored = None + +config = configparser.ConfigParser() + +style = style_from_dict({ + Token.QuestionMark: '#fac731 bold', + Token.Answer: '#4688f1 bold', + Token.Selected: '#0abf5b', # default + Token.Pointer: '#673ab7 bold', +}) + +def log(string, color, font="slant", figlet=False): + if colored: + if not figlet: + six.print_(colored(string, color)) + else: + six.print_(colored(figlet_format( + string, font=font), color)) + else: + six.print_(string) + + +def ask(type, name, message, validator=None, choices=[]): + questions = [ + { + 'type': type, + 'name': name, + 'message': message, + 'validator': validator, + }, + ] + if choices: + questions[0].update({ + 'choices': choices, + }) + answers = prompt(questions, style=style) + return answers + + +def main(): + + def askCookie(): + cookie = ask(type='input', + name='cookie', + message='Enter PHPSESSID cookie (Only needed to provide once):') + config['DEFAULT']['cookie'] = cookie['cookie'] + + with open('config.ini', 'w') as configfile: + config.write(configfile) + return cookie['cookie'] + + log("SteamGifts Bot", color="blue", figlet=True) + log("Welcome to SteamGifts Bot!", "green") + log("Created by: github.com/stilManiac", "white") + + config.read('config.ini') + if not config['DEFAULT'].get('cookie'): + cookie = askCookie() + + re_enter_cookie = ask(type='confirm', + name='reenter', + message='Do you want to enter new cookie?')['reenter'] + if re_enter_cookie: + cookie = askCookie() + + gift_type = ask(type='list', + name='gift_type', + message='Select type:', + choices=[ + 'All', + 'Wishlist', + 'Recommended', + 'Copies', + 'DLC', + 'New' + ])['gift_type'] + + # s = SteamGifts(cookie, gift_type) + # s.start() + +if __name__ == '__main__': + main() diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..0c039bc --- /dev/null +++ b/config.ini @@ -0,0 +1,3 @@ +[DEFAULT] +cookie = sdf + diff --git a/main.py b/main.py index 44b6a30..8e77c99 100644 --- a/main.py +++ b/main.py @@ -101,7 +101,7 @@ def get_games(): continue elif int(points) - int(game_cost) > 0: entry_gift(item.find('a', {'class': 'giveaway__heading__name'})['href'].split('/')[2]) - + n = n+1 except AttributeError: break diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..519474b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +astroid==2.4.2 +isort==4.3.21 +lazy-object-proxy==1.4.3 +mccabe==0.6.1 +prompt-toolkit==1.0.14 +pyconfigstore3==1.0.1 +pyfiglet==0.8.post1 +Pygments==2.6.1 +PyInquirer==1.0.3 +pylint==2.5.3 +regex==2020.6.8 +six==1.15.0 +termcolor==1.1.0 +toml==0.10.1 +wcwidth==0.2.5 +wrapt==1.12.1