Skip to content

Commit

Permalink
Revert "Revert "Better UX/UI""
Browse files Browse the repository at this point in the history
  • Loading branch information
samthegitguy authored Oct 28, 2020
1 parent f751281 commit 9e5ba6a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 31 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ build/
*.egg-info

# Keys
lichs/key
lichs/key.txt
lichs/token.key

# Others
__pycache__

76 changes: 47 additions & 29 deletions lichs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,83 @@
import berserk
import chess
from pathlib import Path
from getpass import getpass

from lichs.Game import Game
from lichs.api_key import set_api

token_file = Path(__file__).parent.absolute() / "key"
token_file = Path(__file__).parent.absolute() / "token.key"

def set_token(key):
token_file.write_text(key)
print("The API-token " + key + " was entered and saved.")
print("The API-token was entered and saved.")

def get_token():
return getpass("Please enter your token: ")
# def get_opt(opt):
# TODO Get option function


def main():
if len(sys.argv) == 2:
set_token(sys.argv[1])

if not token_file.exists():
print("Please provid a token key")
print("Please provide a token key")
print("See the instructions in the Github README:")
print("https://github.com/Cqsi/lichs#how-to-generate-a-personal-api-token")
key = input("token: ")
set_token(key)
set_token(get_token())

token = token_file.read_text()
session = berserk.TokenSession(token)
client = berserk.clients.Client(session)
board = berserk.clients.Board(session)

# Gets your account data, e.g ["id"], ["username"]
try:
account_data = client.account.get()
player_id = account_data["id"]
except berserk.exceptions.ResponseError as e:
print("Error ", e, "occurred.")
print("Unable to connect Lichess")
print("Check if your token key is right")
print("Or try again later")
os._exit(0)
errOccurring = True
while errOccurring:
try:
account_data = client.account.get()
player_id = account_data["id"]
errOccurring = False
except berserk.exceptions.ResponseError as e:
print("Error ", e, "occurred.")
print("Unable to connect to Lichess")
print("Check if your token key is right")
print("Or try again later")
set_token(get_token())

# Welcome text
print("Welcome to Lichess!\n")
print("What kind of chess do you want to play?")
print("1. Rapid (10+0)\n2. Classical (30+0)\n")
num = input("Enter 1 or 2: ")
time = 0

if num=="1":
time=10
elif num=="2":
time=30
else:
# This needs improvement, something like a while/for loop
print("Something went wrong, please enter the lichess command again.")
sys.exit()
print("Welcome to Lichess in the Terminal (lichs)\n")
print("Type either\nP to play\nH for help\nQ to quit ")
choice = input("Choose your option: ")
optFlag = True # Flag for options menu
num = " "
while optFlag == True:
if choice.lower() == "h":
print("Welcome to Lichess in the Terminal (lichs)\n")
print("Thanks for playing. ")
# TODO add help menu
elif choice.lower() == "q": sys.exit(0)
elif choice.lower() == "p": optFlag = False
else: print("Please choose from either P to play, H for help, or Q to quit")
print("What kind of chess would you like to play? \n 1. Rapid (10+0)\n2. Classical (30+0)\n")
typeFlag = True # Flag for gametype validation
while typeFlag == True:
if num=="1":
time=10
typeFlag = False
elif num=="2":
time=30
typeFlag = False
else:
num = input("Please choose from either 1 (Rapid, 10+0) or 2 (Classical, 30+0): ")

print("Searching after opponent...")
board.seek(time, 0)

for event in board.stream_incoming_events():
if event['type'] == 'gameStart':

print("An opponent was found!")

isWhite = True
Expand Down
13 changes: 11 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
berserk==0.10.0
python-chess==0.25.1
berserk==0.10.0
certifi==2020.6.20
chardet==3.0.4
Deprecated==1.2.10
idna==2.10
lichs==1.2.0
ndjson==0.3.1
python-chess==1.1.0
requests==2.24.0
urllib3==1.25.10
wrapt==1.12.1

0 comments on commit 9e5ba6a

Please sign in to comment.