lateximgbot

Latex image Telegram bot
Log | Files | Refs | README | LICENSE

commit 1f1159664d179789c7f7187bbf4ea2926481f78a
parent b3daac4b0c5f15ac6ea14cfd6d22349ab318abe3
Author: Byron Torres <b@torresjrjr.com>
Date:   Thu,  6 May 2021 00:05:29 +0100

Add dev/

Diffstat:
Adev/examples.py | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/dev/examples.py b/dev/examples.py @@ -0,0 +1,37 @@ +#!/usr/bin/python + +from random import randint + + +def get_random_example(): + File = open("examples.tex", 'r') + File.seek(0) + + example_lines = [] + record = False + + for i, line in enumerate(File): + if i == 0: + if not line.startswith("%TOTAL"): + raise Exception("No total on first line.") + else: + total_examples = int( line.split()[1] ) + example_number = randint(1, total_examples) + continue + + if line.startswith(f"%BEGIN {example_number}"): + record = True + continue + + if line.startswith(f"%END {example_number}"): + record = False + break + + if record: + example_lines += [line] + + example = ''.join(example_lines) + return example + + +print(get_random_example())