Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 06-24-2021, 05:46 PM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,618
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: Extracting a number from a string

I have two columns, text #kobobookmark and integer #chaptercount.

I'd like to create a new column to keep track of read chapters in a fanfic, e.g. 5/25.

I thought the best way to do that is a GPM template that
a) checks a book is a fanfic, is currently being read, and has something in #kobobookmark to count,
b) extract the number of read chapters from #kobobookmark,
c) display that number next to #chaptercount.

I managed to get the first part working already:

Code:
program:
	if 
			$#fanficcat 
		&& 
			$#currentlyreading 
		&& 
			$#kobobookmark
	then
		$#chaptercount
	fi
Unfortunately the implementation of b and c I'm a bit stuck on. The bookmarks are always in a string similar to this:

OEBPS/file0003.xhtml#kobo.1.1

The "0003.xhtml" means that it's currently on chapter 3. What would be the best way to get the number and display it as '3/{#chaptercount} chapters read'?


Last edited by ownedbycats; 06-24-2021 at 07:11 PM.
ownedbycats is offline   Reply With Quote
Old 06-24-2021, 09:13 PM   #2
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
You can get that number with regex. The following should return it.

Code:
program:
re_group($#kobobookmark, '.*\/file(\d+).*')
I'll let you include it in your template and sort out the formatting
davidfor is offline   Reply With Quote
Old 06-24-2021, 09:29 PM   #3
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,618
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That covers part b). While I tinker to see if I can figure out c), is there a way to strip excess leading 0s?
ownedbycats is offline   Reply With Quote
Old 06-24-2021, 09:42 PM   #4
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
The function "format_number" should do it:

Code:
program:
format_number(re_group($#kobobookmark, '.*\/file(\d+).*'),'{0:,d}')
davidfor is offline   Reply With Quote
Old 06-24-2021, 10:14 PM   #5
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,618
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I think I'm supposed to use a template() here. Though I syntaxed something wrong because it's dividing the numbers (e.g. in the screenshot, it should be '21/22'). Oops.

Code:
program:
	if 
			$#fanficcat 
		&& 
			$#currentlyreading 
		&& 
			$#kobobookmark
	then
		
		template(format_number(re_group($#kobobookmark, '.*\/file(\d+).*'),'{0:,d}')/$$#chaptercount)

	fi
Also, I noticed the current template gave an error if the #kobobookmark value is OEBPS/Cover.xhtml#kobo.1.1. Is there a way to change the $#kobobookmark test to account for that?
Attached Thumbnails
Click image for larger version

Name:	2021-06-25 00_59_04-calibre — __ My Books __ Fanfiction __.png
Views:	73
Size:	1.4 KB
ID:	187862  

Last edited by ownedbycats; 06-25-2021 at 12:34 AM.
ownedbycats is offline   Reply With Quote
Old 06-25-2021, 12:47 AM   #6
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
I am fairly sure you don't want "template" there. What you probably want to do is a "strcat". So:

Code:
strcat(format_number(re_group($#kobobookmark, '.*\/file(\d+).*'),'{0:,d}'),'/',$$#chaptercount)
For the other part, you could do something like:

Code:
current_chapter = 0;
if contains($#kobo_reading_location, 'File','1','0') then
    current_chapter = re_group($#kobobookmark, '.*\/file(\d+).*')
fi;
strcat(format_number(current_chapter,'{0:,d}'),'/',$$#chaptercount);
That should replace the line with the template in it.
davidfor is offline   Reply With Quote
Old 06-25-2021, 01:05 AM   #7
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,618
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That worked, though testing it showed a slight oversight since I tend to pause at the beginning of chapters. I fixed by subtracting by one.

Code:
program:
input = $#kobobookmark;
a = re(input, '.*\/file(\d+).*', '\1');


	if 
			$#fanficcat 
		&& 
			$#currentlyreading 
		&& 
			$#kobobookmark
	then
		
		strcat(format_number(subtract(a, 1), '{0:,d}'), '/',$$#chaptercount)

	fi
Though while this tested ok putting it in the column itself made an error about 'a' being an unknown identifier.

Last edited by ownedbycats; 06-25-2021 at 01:09 AM.
ownedbycats is offline   Reply With Quote
Old 06-25-2021, 01:21 AM   #8
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,618
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I was able to fix it by doing this (for some reason it recognized neither input nor a)

Code:
  strcat(format_number(subtract((re($#kobobookmark, '.*\/file(\d+).*', '\1')), 1), '{0:,d}'), '/',$$#chaptercount)
ownedbycats is offline   Reply With Quote
Old 06-25-2021, 03:07 PM   #9
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,618
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
The error I got turned out to be a bug in the column evaluator. chaley is working on it now.
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template: Incrementing a padded number by one ownedbycats Library Management 2 03-09-2021 07:54 PM
Replace reoccurring string with increasing number 1v4n0 ePub 4 12-17-2017 05:35 AM
Djvu: Extracting ISBN numbers from a large number of books? MelBr Other formats 7 04-13-2014 03:35 AM
Error message: "TEMPLATE ERROR Single '}' encountered in format string" frank14612 Calibre 22 07-02-2013 11:05 AM
Mathch a string while ignoring some character in that string? ElMiko Sigil 12 12-01-2011 10:05 PM


All times are GMT -4. The time now is 07:32 AM.


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