Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 06-10-2022, 01:58 AM   #1
wishingstar
Enthusiast
wishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheese
 
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
Question Randomizing text files in a book

As I'm organizing my library, I'm combining a bunch of articles by topic into collections. I have these articles downloaded as html files, and placed in folders by topic. So basically what I do is:
  1. Create an empty epub
  2. Import all html files from a given folder into it
  3. Perform any necessary html cleaning
  4. Create a ToC from files (in the cleaning step, each file starts with the title of the article in <h> tags)
  5. Save the book, fill in metadata, and add a cover

Now my question is about ordering the articles.

The way outlined here means the articles will be added in alphabetical order, which is okay in principle, but I'm wondering if I can add some 'variety' into the collection by somehow randomizing the order of the html files in the book.

I know I can drag the individual html files around, but that's impractical with 100+ articles. Is there a way to randomize the files automatically, or to write a script to randomize the files on import somehow?

Last edited by wishingstar; 06-10-2022 at 02:01 AM.
wishingstar is offline   Reply With Quote
Old 06-10-2022, 02:49 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,363
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
If you can script you can simply use conversion to do this in an automated fashion. https://manual.calibre-ebook.com/faq...specific-order
kovidgoyal is offline   Reply With Quote
Advert
Old 06-11-2022, 12:40 AM   #3
wishingstar
Enthusiast
wishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheesewishingstar can extract oil from cheese
 
Posts: 33
Karma: 1032
Join Date: Nov 2016
Device: Kobo Aura Edition 2, Lenovo Android 10
Thank you, I followed something similar to your suggestion, only I did the randomization in a python script outside of calibre before importing. Here's the script I used in case anyone is interested. Basically, the script adds a random prefix to each file name, and then I import them into the book editor, which will now be in the new order determined by the random prefix.

Code:
import os
import random

path = r"path\\to\\folder\\"  # note: using double slashes because windows
string_to_draw_from = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
for file in os.listdir(path):
    letters = ''.join(random.choices(string_to_draw_from, k=2)) + '_'  # 2 random letters as prefix
    os.rename(path+file, f"{path}{letters}{file}")
wishingstar is offline   Reply With Quote
Reply

Tags
edit book

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aura Grey text in book, Black text in menu aluisscp Kobo Reader 4 09-03-2014 07:10 PM
Troubleshooting K4NT (2012) randomizing screensavers SN3AKYf0x Amazon Kindle 2 12-11-2012 04:18 AM
Text files with # and ## p3aul Calibre 6 10-13-2009 03:10 PM
Text files blanked Halk Calibre 21 05-18-2009 01:31 PM
Text tool for formatting Gutenberg text files bob_ninja Workshop 5 11-13-2007 12:28 PM


All times are GMT -4. The time now is 04:42 AM.


MobileRead.com is a privately owned, operated and funded community.