Compare commits

..

7 commits

80 changed files with 78 additions and 58 deletions
fromtext.pygenerate.py
src
automation.1158690276.1547069965
edyn.1130981640.2125817583
was-ist-das-kronecker-delta-was-sagt-es-aus.0.htmlwas-ist-das-kronecker-delta-was-sagt-es-aus.1.htmlwas-ist-das-levicivita-symbol-was-sagt-es-aus.0.htmlwas-ist-das-levicivita-symbol-was-sagt-es-aus.1.htmlwas-ist-das-spatprodukt-was-kann-man-damit-berechnen.0.htmlwas-ist-das-spatprodukt-was-kann-man-damit-berechnen.1.htmlwas-istbrbrleftmathbfacdotnablarightmathbfrmathbfa.0.htmlwas-istbrbrleftmathbfacdotnablarightmathbfrmathbfa.1.htmlwas-istbrbrnablatimesmathbfr.0.htmlwas-istbrbrnablatimesmathbfr.1.htmlwas-istbrbrnablecdotmathbfr.0.htmlwas-istbrbrnablecdotmathbfr.1.htmlwie-hngen-die-raumladungsdichte-und-die-elektrische-flussdichte-in-der-elektrostatik-zusammen.0.htmlwie-hngen-die-raumladungsdichte-und-die-elektrische-flussdichte-in-der-elektrostatik-zusammen.1.htmlwie-ist-der-magn-fluss-definiert-was-ist-das-formelzeichen-und-welche-einheit-hat-er.0.htmlwie-ist-der-magn-fluss-definiert-was-ist-das-formelzeichen-und-welche-einheit-hat-er.1.htmlwie-kann-das-kreuzprodukt-als-determinante-geschrieben-werden.0.htmlwie-kann-das-kreuzprodukt-als-determinante-geschrieben-werden.1.htmlwie-lautet-der-nablaoperator-in-kartesischen-koordinaten.0.htmlwie-lautet-der-nablaoperator-in-kartesischen-koordinaten.1.htmlwie-lautet-die-gramanidentittbrwozu-ist-sie-hilfreich.0.htmlwie-lautet-die-gramanidentittbrwozu-ist-sie-hilfreich.1.htmlwie-lautet-die-lagrangeidentitt.0.htmlwie-lautet-die-lagrangeidentitt.1.htmlwie-lautet-die-lagrangeidentitt.1.mdwie-lautet-die-poissongleichungbrwann-gilt-siebrgibt-es-spezialflle.0.htmlwie-lautet-die-poissongleichungbrwann-gilt-siebrgibt-es-spezialflle.1.htmlwie-sieht-das-feld-einer-punktladung-aus.0.htmlwie-sieht-das-feld-einer-punktladung-aus.1.htmlwie-verhlt-sich-der-nablaoperator-in-kartesischen-koordinaten-frmathbfrmathbfrmathbfr.0.htmlwie-verhlt-sich-der-nablaoperator-in-kartesischen-koordinaten-frmathbfrmathbfrmathbfr.1.html
elektrotechnik.1520591227.1860198308
was-is-das-symbol-und-die-einheit-der-elektrischen-flussdichte.0.htmlwas-is-das-symbol-und-die-einheit-der-elektrischen-flussdichte.1.htmlwas-ist-das-symbol-und-der-wert-der-elektrischen-feldkonstante.0.htmlwas-ist-das-symbol-und-der-wert-der-elektrischen-feldkonstante.1.htmlwas-ist-das-symbol-und-der-wert-der-lichtgeschwindigkeit-im-vakuum.0.htmlwas-ist-das-symbol-und-der-wert-der-lichtgeschwindigkeit-im-vakuum.1.htmlwas-ist-das-symbol-und-der-wert-der-magnetischen-feldkonstante.0.htmlwas-ist-das-symbol-und-der-wert-der-magnetischen-feldkonstante.1.htmlwas-ist-das-symbol-und-die-einheit-der-elektrischen-spannung.0.htmlwas-ist-das-symbol-und-die-einheit-der-elektrischen-spannung.1.htmlwas-ist-das-symbol-und-die-einheit-des-elektrischen-feldes.0.htmlwas-ist-das-symbol-und-die-einheit-des-elektrischen-feldes.1.htmlwas-ist-das-symbol-und-die-einheit-des-elektrischen-flusses.0.htmlwas-ist-das-symbol-und-die-einheit-des-elektrischen-flusses.1.htmlwas-ist-die-ladung-eines-elektrons.0.htmlwas-ist-die-ladung-eines-elektrons.1.htmlwas-ist-die-lorentzkraft.0.htmlwas-ist-die-lorentzkraft.1.htmlwas-ist-die-magn-feldstrke.0.htmlwas-ist-die-magn-feldstrke.1.htmlwas-ist-die-magn-flussdichte-was-ist-ihr-formelzeiche.0.htmlwas-ist-die-magn-flussdichte-was-ist-ihr-formelzeiche.1.htmlwas-verbindet-die-elektrische-flussdichte-und-die-feldstrke.0.htmlwas-verbindet-die-elektrische-flussdichte-und-die-feldstrke.1.htmlwie-berechnet-man-die-kraft-die-auf-einen-linienleiter-in-einem-magn-feld-wirkt.0.htmlwie-berechnet-man-die-kraft-die-auf-einen-linienleiter-in-einem-magn-feld-wirkt.1.htmlwie-berechnet-man-die-kraft-die-auf-einen-linienleiter-in-einem-magn-feld-wirkt.1.mdwie-hngen-die-magnetische-feldkonstante-die-elektrische-feldkonstante-und-die-lichtgeschwindigkeit-zusammen.0.htmlwie-hngen-die-magnetische-feldkonstante-die-elektrische-feldkonstante-und-die-lichtgeschwindigkeit-zusammen.1.htmlwie-ist-die-induktivitt-definiert-welche-einheit-hat-sie.0.htmlwie-ist-die-induktivitt-definiert-welche-einheit-hat-sie.1.htmlwie-sieht-das-magn-feld-hervorgerufen-durch-einen-linienleiter-aus.0.htmlwie-sieht-das-magn-feld-hervorgerufen-durch-einen-linienleiter-aus.1.html
maths.1916628129.1488301872
physik.1868799683.1655999710

View file

@ -36,7 +36,7 @@ def process_line(
slug = slug.replace(' ', '-')
base_filename = deckpath / slug
for i, c in enumerate(columns):
with (base_filename.parent / (base_filename.name + f'.{i}.md')).open('w') as fp:
with (base_filename.parent / (base_filename.name + f'.{i}.html')).open('w') as fp:
fp.write(c)
if not c.endswith('\n'):
fp.write('\n')

View file

@ -9,7 +9,7 @@ import random
import re
RE_DIRNAME = re.compile(r'^(.*)\.([0-9]+)\.([0-9]+)$')
RE_FILENAME = re.compile(r'^(.*)\.([0-9]+)\.md$')
RE_FILENAME = re.compile(r'^(.*)\.([0-9]+)\.(md|html)$')
class MyNote(genanki.Note):
pass
@ -20,20 +20,25 @@ def load_notes(
model: genanki.Model,
) -> list[genanki.Note]:
files_loaded = []
final_files: dict[str, list[tuple[pathlib.Path, int]]] = {}
final_files: dict[str, list[tuple[pathlib.Path, int, bool]]] = {}
for dirpath, _, filenames in path.walk():
files_loaded += [dirpath / x for x in filenames]
for f in files_loaded:
match = RE_FILENAME.match(f.name)
if match:
final_files.setdefault(match.group(1), []).append((f, int(match.group(2))))
final_files.setdefault(match.group(1), []).append(
(f, int(match.group(2)), match.group(3) == 'html'),
)
notes: list[genanki.Note] = []
for v in final_files.values():
note_files: list[pathlib.Path] = [v_[0] for v_ in sorted(v, key=lambda x: x[1])]
note_files: list[tuple[pathlib.Path, bool]] = [(v_[0], v_[2]) for v_ in sorted(v, key=lambda x: x[1])]
note_str: list[str] = []
for f in note_files:
for f, is_html in note_files:
with f.open() as fp:
html_str = markdown.markdown(fp.read())
if is_html:
html_str = fp.read()
else:
html_str = markdown.markdown(fp.read())
note_str += [html_str]
notes += [MyNote(model=model, fields=note_str, guid=genanki.guid_for(note_str[0]))]
return notes
@ -50,7 +55,8 @@ def load_notes(
@click.option('--destructive/--no-destructive', 'destructive', type=bool, default=False, help='Perform write operations, which may end in data loss')
@click.option('--autogenerate/--no-autogenerate', 'autogenerate', type=bool, default=False, help='Generate missing ids, should probably be used with --destructive, to always use the same ones.')
@click.option('--debug/--no-debug', 'debug', type=bool, default=False, help="Debug mode, don't write files")
@click.argument('path', type=click.Path(path_type=pathlib.Path, dir_okay=True))
@click.option('--multi', 'multi', type=click.Path(path_type=pathlib.Path))
@click.argument('paths', type=click.Path(path_type=pathlib.Path, dir_okay=True), nargs=-1)
def main(
*,
name: str | None,
@ -64,54 +70,62 @@ def main(
destructive: bool,
autogenerate: bool,
debug: bool,
path: pathlib.Path,
multi: pathlib.Path | None,
paths: list[pathlib.Path],
):
match = RE_DIRNAME.match(path.name)
if match:
model_name = model_name or match.group(1)
name = name or match.group(1)
model_id = model_id or int(match.group(2))
deck_id = deck_id or int(match.group(3))
else:
model_name = model_name or path.name
name = name or path.name
if model_id is None:
if autogenerate:
model_id = random.randrange(1 << 30, 1 << 31)
else:
raise click.ClickException('model_id could not be derived from directory name and is not explicitly set, or autogenerate enabled')
if deck_id is None:
if autogenerate:
deck_id = random.randrange(1 << 30, 1 << 31)
else:
raise click.ClickException('deck_id could not be derived from directory name and is not explicitly set, or autogenerate enabled')
if destructive:
new_path = path.parent / f'{path.name}.{model_id}.{deck_id}'
if not debug:
path.rename(new_path)
path = new_path
model = genanki.Model(
model_id,
model_name,
fields=[dict(name=x) for x in fields],
templates=[
{
'name': template_name,
'qfmt': question_format,
'afmt': answer_format,
},
],
)
notes: list[genanki.Note] = load_notes(path=path, model=model)
deck = genanki.Deck(
deck_id,
name,
)
for n in notes:
deck.add_note(n)
click.echo(f'added {len(notes)} notes')
if not debug:
genanki.Package(deck).write_to_file(path.parent / (path.name + '.apkg'))
decks = []
for path in paths:
match = RE_DIRNAME.match(path.name)
if match:
model_name = model_name or match.group(1)
name = name or match.group(1)
model_id = model_id or int(match.group(2))
deck_id = deck_id or int(match.group(3))
else:
model_name = model_name or path.name
name = name or path.name
if model_id is None:
if autogenerate:
model_id = random.randrange(1 << 30, 1 << 31)
else:
raise click.ClickException('model_id could not be derived from directory name and is not explicitly set, or autogenerate enabled')
if deck_id is None:
if autogenerate:
deck_id = random.randrange(1 << 30, 1 << 31)
else:
raise click.ClickException('deck_id could not be derived from directory name and is not explicitly set, or autogenerate enabled')
if destructive:
new_path = path.parent / f'{path.name}.{model_id}.{deck_id}'
if not debug:
path.rename(new_path)
path = new_path
model = genanki.Model(
model_id,
model_name,
fields=[dict(name=x) for x in fields],
templates=[
{
'name': template_name,
'qfmt': question_format,
'afmt': answer_format,
},
],
)
notes: list[genanki.Note] = load_notes(path=path, model=model)
deck = genanki.Deck(
deck_id,
name,
)
for n in notes:
deck.add_note(n)
click.echo(f'added {len(notes)} notes')
decks += [deck]
if not debug:
genanki.Package(deck).write_to_file(path.parent / (path.name + '.apkg'))
if not debug and multi:
if multi.suffix != '.apkg':
click.echo('WARNING: destination file does not have extension ".apkg"')
genanki.Package(decks).write_to_file(multi)

View file

@ -0,0 +1 @@
Was ist<br><br>[$]\left(\mathbf{a}\cdot\nabla\right)\mathbf{r}[/$]

View file

@ -0,0 +1 @@
Was ist<br><br>[$]\nabla\times\mathbf{r}[/$]

View file

@ -0,0 +1 @@
[$]\vec{0}[/$]

View file

@ -0,0 +1 @@
Was ist<br><br>[$]\nabla\cdot\mathbf{r}[/$]

View file

@ -0,0 +1 @@
[$]3[/$]

View file

@ -0,0 +1 @@
[$$](\mathbf{a} \times \mathbf{b}) \cdot (\mathbf{c} \times \mathbf{d}) = (\mathbf{a} \cdot \mathbf{c})(\mathbf{b} \cdot \mathbf{d}) - (\mathbf{b} \cdot \mathbf{c})(\mathbf{a} \cdot \mathbf{d})[/$$]<br><br>mit Spezialfall<br><br>[$$]|\mathbf{a} \times \mathbf{b}|^2 = |\mathbf{a}|^2 |\mathbf{b}|^2 - (\mathbf{a} \cdot \mathbf{b})^2[/$$]

View file

@ -1 +0,0 @@
"[$$](\mathbf{a} \times \mathbf{b}) \cdot (\mathbf{c} \times \mathbf{d}) = (\mathbf{a} \cdot \mathbf{c})(\mathbf{b} \cdot \mathbf{d}) - (\mathbf{b} \cdot \mathbf{c})(\mathbf{a} \cdot \mathbf{d})[/$$]<br><br>mit Spezialfall<br><br>[$$]<span style=""white-space-collapse: preserve;"">|\mathbf{a} \times \mathbf{b}|^2 = |\mathbf{a}|^2 |\mathbf{b}|^2 - (\mathbf{a} \cdot \mathbf{b})^2</span>[/$$]"

View file

@ -1 +1 @@
[$$]\mathbf{F}=Q\left(\mathbf{E}+\mathbf{v}\times\mathbf{B}\right)[$$/]
[$$]\mathbf{F}=Q\left(\mathbf{E}+\mathbf{v}\times\mathbf{B}\right)[/$$]

View file

@ -0,0 +1 @@
[$$]\mathbf{F}=I\cdot \mathbf{l} \times \mathbf{B}[/$$]