Welcome, Guest
Python Scripts for ComicRack

TOPIC: need some python help

need some python help 8 years 8 months ago #2846

  • imsabbel3
  • imsabbel3's Avatar
  • Offline
  • Senior Boarder
  • Posts: 78
  • Karma: 0
One thing in advance: I dont know any python, but managed to just guess the syntax by looking at other scripts posted here.
But somehow i hit a wall right now.
What i want to do is the following:

For each series in the comiclist, i want to iterate over all books in that series and do some modifications.
The latter part isnt the problem.
But how can i easily iterate over the series?

Do i have to go through each book, and build an array of lists, or is this already exposed by comicrack?
If not, how do i easily do something like this pseudocode in python:

for each book
if book.series is not serieslist
add book.series to serieslist
endif
add book to serieslist[book.series]
endfor

for each series
for each book in serieslist[series]
dostuff
endfor
endfor

I am sure its something totally trivial (seems like you can do anything in a few lines), but i spend a couple of hours already over it without any success.

The "count page numbers" script does something similar to the first part, but i dont understand the syntax:
def CalculatePages(books):
	h = Hashtable()
	for book in books:
		series = book.Series
		if series=="":
			series = book.ShadowSeries
		if h[series.ToLower()]:
			s = h[series.ToLower()]
			s.PageCount = book.PageCount + s.PageCount
		else:
			s = TheSeries(series, book.PageCount, book.Writer)
			h[series.ToLower()] = s
How does hashtable work? I googled "python hashtable()", but didnt get any meaningful hits, so is this a comicrack function? And what does "series.tolower" mean?
The administrator has disabled public write access.

Re:need some python help 8 years 8 months ago #2854

  • wadegiles
  • wadegiles's Avatar
  • Offline
  • Gold Boarder
  • Posts: 248
  • Thank you received: 3
  • Karma: 20
I don't know how to access a Series list in ComicRack, but you could indeed just build your own from the list of books.

Lists in Python are indexed on integers only so your pseudo-code can't be accomplished using them.

Hashtable is a .NET framework class. The scripting engine in ComicRack is IronPython. This engine allows accesss to much of the .NET framework within Python.

The code you posted mixes the Hashtable and Python list usage, so I'm guessing that's why you are confused.
The administrator has disabled public write access.
Time to create page: 0.156 seconds

Who's Online

We have 198 guests and 10 members online