+++ /dev/null
-.DEFAULT_GOAL := install
-
-prep:
- mkdir -p /usr/local/bin
- mkdir -p /usr/local/man/man1
-
-install:
- make prep
- mkdir -p /usr/local/share/lightcards/
- cp lightcards.py /usr/local/bin/lightcards
- cp man/lightcards.1 /usr/local/man/man1/
-
-uninstall:
- rm /usr/local/bin/lightcards
- rm /usr/local/man/man1/lightcards.1
-
-reinstall:
- make uninstall
- make install
# lightcards
Lightcards is a terminal program for using flashcards from a Markdown or HTML table. It is currently under heavy development, and unusable for productive studying.
+# Installation
+`pip install .`
+
## License
Copyright Armaan Bhojwani 2021, MIT license
--- /dev/null
+from . import lightcards
+
+lightcards.main()
--- /dev/null
+# Display card output and retreive input
+# Armaan Bhojwani 2021
+
+import os
+
+class Status():
+ index = 0
+ side = 0
+
+ def forward(self, stack):
+ if not self.index == len(stack) - 1:
+ self.index += 1
+
+ def back(self):
+ if not self.index < 1:
+ self.index -= 1
+
+ def flip(self):
+ if self.side == 0:
+ self.side = 1
+ else:
+ self.side = 0
+
+ def setSide(self, inp):
+ self.side = inp
+
+ def getSide(self):
+ return self.side
+
+ def getIdx(self):
+ return self.index
+
+
+def disp_card(stdscr, stack, obj):
+ stdscr.clear()
+ stdscr.addstr(str(stack[obj.getIdx()][obj.getSide()]))
+
+def get_key(stdscr, stack):
+ idx = Status()
+ disp_card(stdscr, stack, idx)
+
+ while True:
+ key = stdscr.getkey()
+ try:
+ if key == "q" or key == os.linesep:
+ exit(0)
+ if key == "j":
+ idx.forward(stack)
+ idx.setSide(0)
+ disp_card(stdscr, stack, idx)
+ if key == "k":
+ idx.back()
+ idx.setSide(0)
+ disp_card(stdscr, stack, idx)
+ if key == "l" or key == "h":
+ idx.flip()
+ disp_card(stdscr, stack, idx)
+ except Exception:
+ pass
--- /dev/null
+#!/usr/bin/env python
+# Markdown flashcard utility
+# Armaan Bhojwani 2021
+
+import argparse
+from curses import wrapper
+
+from . import display, parse
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(description="Simple terminal flashcards")
+ parser.add_argument("inp", metavar="input file", type=str, nargs=1)
+ return parser.parse_args()
+
+
+def show(stack):
+ wrapper(display.get_key, stack)
+
+
+def main():
+ args = parse_args()
+ headers = parse.parse_html(parse.md2html(args.inp[0]))[0]
+ stack = parse.parse_html(parse.md2html(args.inp[0]))[1]
+ show(stack)
+
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+#!/usr/bin/env python
+# Parse markdown table into tuple of lists
+# Armaan Bhojwani 2021
+
+import sys
+from bs4 import BeautifulSoup
+import markdown
+
+
+def md2html(file):
+ with open(file, "r", encoding="utf-8") as input_file:
+ return markdown.markdown(input_file.read(), extensions=['tables'])
+
+
+def parse_html(html):
+ def clean_text(inp):
+ return inp.get_text().rstrip()
+
+ def clean_list(inp):
+ for z in inp:
+ if not len(z) == 2:
+ inp.remove(z)
+ return inp
+
+ soup = BeautifulSoup(html, 'html.parser')
+ outp = []
+
+ for x in soup.find_all("tr"):
+ outp.append([clean_text(y) for y in x.find_all("td")])
+
+ return ([clean_text(x) for x in soup.find_all("th")],
+ clean_list(outp))
+
+def main(file):
+ return parse_html(md2html(file))
+
+if __name__ == "__main__":
+ print(main(sys.argv[1]))
+++ /dev/null
-beautifulsoup4==4.9.3
-markdown==3.3.3
--- /dev/null
+from setuptools import setup
+
+setup(
+ name="lightcards",
+ version="0.0.0",
+ description="Markdown flashcards",
+ url="https://sr.ht/~armaan/lightcards",
+ author="Armaan Bhojwani",
+ author_email="me@armaanb.net",
+ license="MIT",
+ packages=["lightcards"],
+ install_requires=["beautifulsoup4", "markdown"],
+ classifiers=[
+ "Development Status :: 2 - Pre-Alpha",
+ "Intended Audience :: Other Audience",
+ "Environment :: Console :: Curses",
+ "License :: OSI Approved :: MIT License",
+ "Topic :: Utilities"
+ ],
+)
+
+++ /dev/null
-# Display card output and retreive input
-# Armaan Bhojwani 2021
-
-import os
-
-class Status():
- index = 0
- side = 0
-
- def forward(self, stack):
- if not self.index == len(stack) - 1:
- self.index += 1
-
- def back(self):
- if not self.index < 1:
- self.index -= 1
-
- def flip(self):
- if self.side == 0:
- self.side = 1
- else:
- self.side = 0
-
- def setSide(self, inp):
- self.side = inp
-
- def getSide(self):
- return self.side
-
- def getIdx(self):
- return self.index
-
-
-def disp_card(stdscr, stack, obj):
- stdscr.clear()
- stdscr.addstr(str(stack[obj.getIdx()][obj.getSide()]))
-
-def get_key(stdscr, stack):
- idx = Status()
- disp_card(stdscr, stack, idx)
-
- while True:
- key = stdscr.getkey()
- try:
- if key == "q" or key == os.linesep:
- exit(0)
- if key == "j":
- idx.forward(stack)
- idx.setSide(0)
- disp_card(stdscr, stack, idx)
- if key == "k":
- idx.back()
- idx.setSide(0)
- disp_card(stdscr, stack, idx)
- if key == "l" or key == "h":
- idx.flip()
- disp_card(stdscr, stack, idx)
- except Exception:
- pass
+++ /dev/null
-#!/usr/bin/env python
-# Markdown flashcard utility
-# Armaan Bhojwani 2021
-
-import argparse
-from curses import wrapper
-
-import display
-import parse
-
-
-def parse_args():
- parser = argparse.ArgumentParser(description="Simple terminal flashcards")
- parser.add_argument("inp", metavar="input file", type=str, nargs=1)
- return parser.parse_args()
-
-
-def show(stack):
- wrapper(display.get_key, stack)
-
-
-def main():
- args = parse_args()
- headers = parse.parse_html(parse.md2html(args.inp[0]))[0]
- stack = parse.parse_html(parse.md2html(args.inp[0]))[1]
- show(stack)
-
-
-if __name__ == "__main__":
- main()
+++ /dev/null
-#!/usr/bin/env python
-# Parse markdown table into tuple of lists
-# Armaan Bhojwani 2021
-
-import sys
-from bs4 import BeautifulSoup
-import markdown
-
-
-def md2html(file):
- with open(file, "r", encoding="utf-8") as input_file:
- return markdown.markdown(input_file.read(), extensions=['tables'])
-
-
-def parse_html(html):
- def clean_text(inp):
- return inp.get_text().rstrip()
-
- def clean_list(inp):
- for z in inp:
- if not len(z) == 2:
- inp.remove(z)
- return inp
-
- soup = BeautifulSoup(html, 'html.parser')
- outp = []
-
- for x in soup.find_all("tr"):
- outp.append([clean_text(y) for y in x.find_all("td")])
-
- return ([clean_text(x) for x in soup.find_all("th")],
- clean_list(outp))
-
-def main(file):
- return parse_html(md2html(file))
-
-if __name__ == "__main__":
- print(main(sys.argv[1]))