]> git.armaanb.net Git - lightcards.git/commitdiff
Add setup.py, and make into actual Python module
authorArmaan Bhojwani <me@armaanb.net>
Sat, 30 Jan 2021 22:33:57 +0000 (17:33 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sat, 30 Jan 2021 22:34:22 +0000 (17:34 -0500)
Makefile [deleted file]
README.md
lightcards/__init__.py [new file with mode: 0644]
lightcards/display.py [new file with mode: 0755]
lightcards/lightcards.py [new file with mode: 0755]
lightcards/parse.py [new file with mode: 0755]
requirements.txt [deleted file]
setup.py [new file with mode: 0644]
src/display.py [deleted file]
src/lightcards.py [deleted file]
src/parse.py [deleted file]

diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index b6b6727..0000000
--- a/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-.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
index 3db73a21d25e7db579df7a9c0097a273125c4df8..ffc1aa1f29508245620045f72ef839bdf0fb45a5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
 # 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
diff --git a/lightcards/__init__.py b/lightcards/__init__.py
new file mode 100644 (file)
index 0000000..b460a51
--- /dev/null
@@ -0,0 +1,3 @@
+from . import lightcards
+
+lightcards.main()
diff --git a/lightcards/display.py b/lightcards/display.py
new file mode 100755 (executable)
index 0000000..988270b
--- /dev/null
@@ -0,0 +1,59 @@
+# 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
diff --git a/lightcards/lightcards.py b/lightcards/lightcards.py
new file mode 100755 (executable)
index 0000000..c744f3a
--- /dev/null
@@ -0,0 +1,29 @@
+#!/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()
diff --git a/lightcards/parse.py b/lightcards/parse.py
new file mode 100755 (executable)
index 0000000..12c1073
--- /dev/null
@@ -0,0 +1,38 @@
+#!/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]))
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644 (file)
index 2fc693c..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-beautifulsoup4==4.9.3
-markdown==3.3.3
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..6b7eb99
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,21 @@
+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"
+    ],
+)
+
diff --git a/src/display.py b/src/display.py
deleted file mode 100755 (executable)
index 988270b..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-# 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
diff --git a/src/lightcards.py b/src/lightcards.py
deleted file mode 100755 (executable)
index 88ac6e9..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/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()
diff --git a/src/parse.py b/src/parse.py
deleted file mode 100755 (executable)
index 12c1073..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/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]))