summaryrefslogtreecommitdiffstats
path: root/flashcards
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2024-09-26 10:02:15 +0200
committerEddy Pedroni <epedroni@pm.me>2024-09-26 10:02:15 +0200
commite65bef9c22244fc9bcd22a37d335f5f76ba16ff5 (patch)
tree9af6fa41bfee6fc03c3ab30cf1b23a82bdf8f2e7 /flashcards
parentce76b00d7b2ccac6843732f92becfabb753864a0 (diff)
Create separate packages for library and CLI
Diffstat (limited to 'flashcards')
-rwxr-xr-xflashcards92
1 files changed, 0 insertions, 92 deletions
diff --git a/flashcards b/flashcards
deleted file mode 100755
index e0ba548..0000000
--- a/flashcards
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/python3
-
-import re
-import sys
-from pathlib import Path
-from random import shuffle
-
-class Color:
- PURPLE = '\033[95m'
- CYAN = '\033[96m'
- DARKCYAN = '\033[36m'
- BLUE = '\033[94m'
- GREEN = '\033[92m'
- YELLOW = '\033[93m'
- RED = '\033[91m'
- BOLD = '\033[1m'
- UNDERLINE = '\033[4m'
- END = '\033[0m'
-
-#print color.BOLD + 'Hello World !' + color.END
-
-cardRegex = "CARD: "
-prefixLength = len(cardRegex)
-
-# Returns a list of Path objects, containing the path to each valid file provided
-def getFileList():
- fileList = []
- if len(sys.argv) > 1:
- for f in sys.argv[1:]:
- path = Path(f)
- if path.exists() and path.is_file():
- fileList.append(f)
- return fileList
- else:
- print("Missing arguments")
- sys.exit()
-
-# Returns cards in the form [(front, back)]
-def createCardList(files):
- cards = []
- for f in files:
- cards = cards + extractCards(f)
- return cards
-
-# Extracts cards from a single file into a list of the form [(front, back)]
-def extractCards(f):
- front = ""
- back = ""
- cards = []
- with open(f) as cardFile:
- for l in cardFile:
- match = re.match(cardRegex, l)
- if match:
- if front != "":
- cards.append([front.strip(), back.strip()])
- back = ""
- front = match.string[prefixLength:]
- else:
- back += l
- # do the last front-back pair before returning
- cards.append([front.strip(), back.strip()])
- return cards
-
-# Waits for user input and reacts accordingly
-def wait():
- cmd = input().strip()
- if cmd.startswith("q") or cmd.startswith("quit") or cmd.startswith("exit"):
- sys.exit(0)
-
-# Loops serving cards to the user until the program is exited
-def serveCards(cards):
- while True:
- for i, card in enumerate(cards):
- print("----------------------------------------------------------------------------(" + str(i + 1) + "/" + str(len(cards)) + ")")
- print(Color.BLUE + Color.BOLD + card[0] + Color.END)
- wait()
- print(card[1])
- wait()
-
-def debugCards(cardList):
- for c in cardList:
- print("Front:", c[0])
- print("Back:", c[1])
-
-def main():
- files = getFileList()
- cards = createCardList(files)
- shuffle(cards)
- serveCards(cards)
-
-if __name__ == "__main__":
- main()