Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import tkinter
- import tkinter.filedialog
- import io
- def gen_notes(book):
- start = 0
- while start < len(book):
- passage = book[start:start + 25]
- out = ""
- start += 10
- cloze_done = False
- for line,s in enumerate(passage):
- if line >= 15 and not cloze_done:
- words = s.split()
- candidates = [i for (i,w) in enumerate(words) if len(w) > 4]
- try:
- idx = random.choice(candidates)
- s = ' '.join(words[:idx]) + ' {{c1::' + words[idx] + '}} ' + ' '.join(words[idx+1:])
- cloze_done = True
- except IndexError:
- pass
- pass
- out += (s + '\n')
- yield out
- tk = tkinter.Tk()
- bookname = tkinter.filedialog.askopenfilename()
- notes = gen_notes(io.open(bookname, encoding="utf8").read().splitlines())
- def copy_note():
- global tk, notes
- tk.clipboard_clear()
- tk.clipboard_append(next(notes))
- tkinter.Button(tk, text = "copy next", command = copy_note)\
- .pack(fill=tkinter.BOTH, expand=True)
- tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment