Compare commits

..

No commits in common. "17287cfcb3afa1eedcc98d342794b77854b4ebc9" and "0d3afee6624b064f2f7744a45e5c9d7c1923333e" have entirely different histories.

7 changed files with 14 additions and 208 deletions

View File

@ -1,22 +0,0 @@
#!/usr/bin/env bash
set +e
printf "%s" "Enter URL: "
read URL
articles=$(curl -s "$URL/articles.txt")
# list=''
# while IFS= read article; do
# list+="$article "
# done < <(printf '%s' "$articles")
while :
do
article=$(./tools/widgets/list_selector.py --desc="Select an article:" --result="line" -- $articles)
if [ -z "$article" ]; then
break
fi
curl -s "$URL/markdown/$article.md" | pager
done

View File

@ -37,11 +37,9 @@ done
./tools/feed_generator.py ./articles/ $URL > ./html/feed.xml ./tools/feed_generator.py ./articles/ $URL > ./html/feed.xml
./tools/plaintext_article_listing_generator.py ./articles/ > ./html/articles.txt
mkdir -p "./html/markdown/" mkdir -p "./html/markdown/"
for d in ./articles/*/; do for d in ./articles/*/; do
if [ -d "$d" ]; then if [ -d "$d" ]; then
cp "$d/page.mmd" "./html/markdown/$(basename $d).md" cp "$d/page.mmd" "./html/markdown/$(basename $d).mdd"
fi fi
done done

View File

@ -1,6 +1,4 @@
import time, subprocess import time, subprocess
from os import walk, path
import urllib.parse
def the_line_after_metadata(lines: []) -> int: def the_line_after_metadata(lines: []) -> int:
i = 0 i = 0
@ -26,18 +24,3 @@ def parse_metadata(filepath: str) -> {}:
result["Last Edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath))) result["Last Edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath)))
return result return result
def parse_article_directory(directory: str) -> {}:
articles = {}
for root, dirs, _ in walk(directory):
for d in dirs:
metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd"))
article = urllib.parse.quote(d)
articles[article] = {
"metadata": metadata
}
break
return articles
def sort_titles_by_date(articles: {}) -> []:
return sorted(articles.keys(), key=lambda a: articles[a]["metadata"].get("Date", time.gmtime(0)), reverse=True)

View File

@ -1,10 +1,11 @@
#!/usr/bin/python3 #!/usr/bin/python3
from sys import argv, exit from sys import argv, exit
from os import walk, path
from random import choice, seed from random import choice, seed
import time import time, urllib.parse
from article_utils import parse_article_directory, sort_titles_by_date from article_utils import parse_metadata
from page_shares import wrap_page, ADJECTIVES, MONTHS from page_shares import wrap_page, ADJECTIVES, MONTHS
if len(argv) <= 1: if len(argv) <= 1:
@ -27,9 +28,17 @@ Personal blog of one {choice(ADJECTIVES)} Veclav Talica.
""" """
artciles = parse_article_directory(argv[1]) artciles = {}
for root, dirs, _ in walk(argv[1]):
for d in dirs:
metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd"))
article = urllib.parse.quote(d)
artciles[article] = {
"metadata": metadata
}
break
for title in sort_titles_by_date(artciles): for title in sorted(artciles.keys(), key=lambda a: artciles[a]["metadata"].get("Date", time.gmtime(0)), reverse=True):
article = artciles[title] article = artciles[title]
metadata = article["metadata"] metadata = article["metadata"]
page += ( page += (

View File

@ -1,15 +0,0 @@
#!/usr/bin/env python3
from sys import argv, exit
from article_utils import parse_article_directory, sort_titles_by_date
if len(argv) <= 1:
print("No directory was supplied")
exit(-1)
articles = parse_article_directory(argv[1])
result = '\n'.join(sort_titles_by_date(articles))
print(result)

View File

@ -1,95 +0,0 @@
#!/usr/bin/env python3
from sys import argv
import curses
from wrapper import widget_wrapper
list_starting_arg = 1
for i, arg in enumerate(argv[1:]):
if arg == '--':
if i + 2 == len(argv):
print("Empty list given")
exit(-1)
list_starting_arg = i + 2
break
else:
print("List starting -- wasn't given")
exit(-1)
desc_arg = ''
result_arg = 'index'
# todo: Generalize and simplify over descriptor object.
for arg in argv[1:]:
if arg.startswith('--'):
if arg == '--':
break
elif arg.startswith('--result='):
result_arg = arg[arg.find('=') + 1:]
if result_arg not in ['index', 'line']:
print("Invalid --result=")
exit(-1)
elif arg.startswith('--desc='):
desc_arg = arg[arg.find('=') + 1:]
else:
print("Unknown parameter ", arg)
exit(-1)
else:
print("Unknown parameter ", arg)
exit(-1)
current = 0
lines = argv[list_starting_arg:]
list_box = None
def init(screen):
global list_box
curses.start_color()
curses.curs_set(0)
y = 0
if desc_arg != '':
list_box = screen.subwin(y + 1, 0)
y += 1
def draw_list_box():
y = 0
list_box.border()
y += 1
for i, line in enumerate(lines):
list_box.addstr(y, 1, line, curses.A_REVERSE if i == current else curses.A_NORMAL)
y += 1
list_box.refresh()
def driver(screen):
global current
y = 0
if desc_arg != '':
screen.addstr(y, 0, desc_arg)
y += 1
draw_list_box()
key = screen.getch()
if key == curses.KEY_DOWN:
current = (current + 1) % len(lines)
elif key == curses.KEY_UP:
current = len(lines) - 1 if current == 0 else current - 1
elif key == curses.KEY_ENTER or key == 10 or key == 13:
if result_arg == 'index':
return str(current)
elif result_arg == 'line':
return lines[current]
screen.refresh()
if __name__ == "__main__":
print(widget_wrapper(init, driver))

View File

@ -1,52 +0,0 @@
import curses
import signal
import atexit
import os, sys
from sys import argv, exit
def handler(signum, frame):
curses.endwin()
exit(1)
# def exit_handler():
# curses.endwin()
init = None
driver = None
def curses_wrapper(screen):
curses.noecho()
curses.cbreak()
screen.keypad(True)
init(screen)
while True:
result = driver(screen)
if result != None:
return result
def widget_wrapper(p_init, p_driver):
signal.signal(signal.SIGINT, handler)
# atexit.register(exit_handler)
global init, driver
init = p_init
driver = p_driver
with open('/dev/tty', 'rb') as inf, open('/dev/tty', 'wb') as outf:
saved_stdin = os.dup(0)
saved_stdout = os.dup(1)
saved_stderr = os.dup(2)
os.dup2(inf.fileno(), 0)
os.dup2(outf.fileno(), 1)
os.dup2(outf.fileno(), 2)
result = curses.wrapper(curses_wrapper)
os.dup2(saved_stdin, 0)
os.dup2(saved_stdout, 1)
os.dup2(saved_stderr, 2)
return result