Add interactive CLI

This commit is contained in:
stilmaniac 2020-06-26 22:21:56 +03:00
parent 4eb01b47dd
commit 927f2d568c
5 changed files with 122 additions and 1 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
env/

101
cli.py Normal file
View file

@ -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()

3
config.ini Normal file
View file

@ -0,0 +1,3 @@
[DEFAULT]
cookie = sdf

View file

@ -101,7 +101,7 @@ def get_games():
continue continue
elif int(points) - int(game_cost) > 0: elif int(points) - int(game_cost) > 0:
entry_gift(item.find('a', {'class': 'giveaway__heading__name'})['href'].split('/')[2]) entry_gift(item.find('a', {'class': 'giveaway__heading__name'})['href'].split('/')[2])
n = n+1 n = n+1
except AttributeError: except AttributeError:
break break

16
requirements.txt Normal file
View file

@ -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