Welcome, Guest
Python Scripts for ComicRack
  • Page:
  • 1
  • 2

TOPIC: Grabbing highest Number value in Series

Grabbing highest Number value in Series 8 years 4 months ago #3645

  • oraclexview
  • oraclexview's Avatar
  • Offline
  • Moderator
  • aka SoundWave
  • Posts: 906
  • Thank you received: 182
  • Karma: 37
Hello all!

I'm new to Python, so I have a learning curve when it comes to writing scripts. Thanks to both Cyo (RenameBookFiles) & DouglasBubbletrousers (StandardizeLibrary), I've been able to auto customize the moving and renaming of my eComic files.

Now what I want to do is edit my script to grab the highest value from a collection of all books in a given 'Series' stored in the 'Number' property.

So for example:
if I have Series 'Crisis on Infinite Earths' books (Number 1, 2, 5, 9, 10, 11, 12) the script would return a value of 12.

if I have Series 'Amazing Spider-man' books (Number 59, 78, 209, 333, 400, 455) the script would return a value of 455.

Can any of you help me in writing the script that can properly pull this data based on the books I have in my ComicRack library? Let me know if my request isn't clear enough.

Thanks all!

Onyx X aka SoundWave
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3646

  • Ludwig
  • Ludwig's Avatar
  • Offline
  • Gold Boarder
  • Posts: 197
  • Thank you received: 12
  • Karma: 9
I'm no Python-Wiz so can't help you with the script.

A non-Wiz way i can give.
Select all comics in the series with Shift, then CTRL+I, then put the endnumber in 'of' then click 'refresh comics' and voila. But you already know that i suppose.

That said the 'of'-field is very important. It's a marker for the user. It marks if the series has ended or is ongoing and also gives the endnumber.

It earns a script, and off course a script is more flashy B)

So i second that motion ;)

Now it's \_/7 - time.
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3660

  • oraclexview
  • oraclexview's Avatar
  • Offline
  • Moderator
  • aka SoundWave
  • Posts: 906
  • Thank you received: 182
  • Karma: 37
I did consider the non script way by using the count field, but that's just not good enough. That way just isn't creative enough plus I want to setup scripts so that I manually imput as little as possible and learn some new coding skills at the same time.

I guess I'll have to examine my old MS Access VBA codes where I was able to accomplish this task and find a way to write the same thing in python.

If no one else has any suggestions for me, then I'll have to tackle this one on my own, and then I'll get back to you all.

Thanks though Ludwig.

Onyx X aka SoundWave
Last Edit: 8 years 4 months ago by oraclexview.
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3663

  • spyd3r0x
  • spyd3r0x's Avatar
  • Offline
  • Senior Boarder
  • Posts: 67
  • Karma: 4
Should be relatively easy, I'd think. You just need to loop through the selected group of comics twice. First loop through the selected comics, doing something like this:

if comic.number > lngNumber then lngNumber = comic.number

With the goal being, storing the greatest number you've come across so far in the lngNumber variable.

Then you loop through all comics again, doing your normal code work, this time using the lngNumber variable as your "of count" value.

Taking a look at your StandardizeLibraryTweaked script, I believe you would just add this code right above the normal "for book in books:" line:
HighestNumber = 0
for book in books:
  if book.number != "":
    if book.number.isdigit():
      if book.number > HighestNumber:
        HighestNumber = book.number
You could then use that HighestNumber variable anywhere during the regular function. For example, name = name + " #" + book.number.zfill(x) + " of " + HighestNumber, would result in Comic Name #4 of 12.zip.
Last Edit: 8 years 4 months ago by spyd3r0x.
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3669

  • oraclexview
  • oraclexview's Avatar
  • Offline
  • Moderator
  • aka SoundWave
  • Posts: 906
  • Thank you received: 182
  • Karma: 37
spyd3r0x, yeah using the sequence iteration ‘for’ with maybe even a nested ‘while’ loop sounds like a great way of achieving my goal. I just picked up a Python book yesterday, so with studying that and testing the bit of code you suggested, I’m going to see what I can come up with that works just the way I want it to. I’ll let you know how the first test goes.

Thanks!

Onyx X aka SoundWave
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3671

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
I think you could use lists:

create a list (brackete comma separated values)
issues=[]
populate it going through the issues in question:
issues.append(x)
where 'x' is the number you got...
and you end up with a list that looks like:
issues
[1,2,5,45,13,56,7,21]
then you could sort and get the higher and lower values from it with
issues.sort()
smaller = issues[0]
issues.reverse()
larger = issues[0]

Hope this helps
Last Edit: 8 years 4 months ago by perezmu.
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3683

  • oraclexview
  • oraclexview's Avatar
  • Offline
  • Moderator
  • aka SoundWave
  • Posts: 906
  • Thank you received: 182
  • Karma: 37
perezmu:
I've been reading up on Python, and it seems your idea of making a list and then appending the list with the number value for each book then taking the list and sorting it as you suggested is just about perfect for what I want to do.
I'm also thinking that I'm going to have to write the script to take into account that I only want it to do perform this portion of code on the Number value for books where the Series is equal. For example, I only want it to do this with all the books with the "Amazing Spider-Man" value in the Series field. Then it should start over and do the same thing, but on for all the books with the "Batman" value in the Series field.
It's almost there. I'll update you all when I learn more or when someone here, such as perezmu, hands me another great piece of code.

Thanks again perezmu; I'm learning a lot.
Onyx X aka SoundWave
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3687

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
:laugh:

I am glad to help! I am the one who has to thank all of you developing scripts so, givin a hand when i can is the least I could do! I have tried to work on scripts myself many times, but in the end I never have enough time due to real life intruding...

As per your last request, I think I have an idea of what you can do... later today I will give you some ideas...! Stay tuned.
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 4 months ago #3689

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
Ok, this is what I have come up with. I am not a programmer, just a physicist, this means this is probably overkill, and I am sure you can find better and more efficient ways to do it, but I think this should work.

I am not familiar with the objects and data Comicrack exposes, but I think this metacode is clear enough.

The idea is to use dictionaries. Dictionaries are a structured data type built in in Python that contains tuples, of which the first is the "name" and the second is the "content". A typical dictionary in python and use could be:
weekdays = {"su":"sunday", "mo":"monday", "tu":"tuesday"}

if you want to add a new item:
weekdays["we"]="wednesday"
and to retrieve the "content" of an item
weekdays["su"]
you can also check if a "name" (actually in python this is called "key")
weekdays.has_key("th")

Ok, how can this help you? The great thing about dictionaries is thta you can create a dictionary that has series title as keys and issues lists as content:
comics={"Amazing Spider-Man":[1,3,6,8,25,12,33,14],"Superman":[100,98,97,95]}

If you are able to create such a dictionary, my previous posts applies to these lists (you can use them as you like):
comics["Amazing Spider-Man"]
comics["Superman"]

So this is what I would do:
comics = {}   # create an empty dictionary

1 - loop through each comic in your collection
    get the comic "series" and "number", and updeate dictionary accordingly, whith something like this

if comics.has_key(series):
   comics[series].append(number) #note that I use this as a normal list
else:
   comics[series]=[number]
 #if series is not already in the dictionary, I create an entry whith a list containing just the first number encountered

Now you have a dictionary that has all the series and for each series a list of comics in that series you can now work for. For expample, to sort all the comics in every series you can use the following (note the great way you can loop through all dictionary items!):
for series in comics.keys():
    comics[series].sort()

As I said, I think this should work, but I am also sure this can be very time and memory consuming; as I said I learnt python to get things done, but never had time to learn or wrry about optimizing the code :blush:
The administrator has disabled public write access.

Re:Grabbing highest Number value in Series 8 years 3 months ago #3771

  • oraclexview
  • oraclexview's Avatar
  • Offline
  • Moderator
  • aka SoundWave
  • Posts: 906
  • Thank you received: 182
  • Karma: 37
OK, so after a month of studying, trial & error, and suggestions from spyd3r0x (who’s idea of doing a loop twice through the book selection ending up being what I chose to do – I actually looped through the books 3 times for what I wanted) and perezmu (who’s excellent ideas of using lists and dictionaries were just perfect for what I wanted) I now have completed my latest update to the Standardize Library Script Tweaked script.

There were two things that I was looking to accomplish that I wanted the script to handle without me having to manually type in the information. The 1st thing I wanted to do was format the issue number when renaming the file to take into account the amount of leading zero characters to use based on the maximum length of the highest issue number value in that book series. The 2nd thing I wanted to do was add at the end of the book series folder the year when the series began publishing based on the lowest year value in that book series. I’m not sure if I wrote the script to be the most efficient, but it does work the way I’d like it to for the most part. The only thing that has to be kept in mind is that the books this script is ran on have to 1st be sorted by Series and it should be ran on every issue within that series each time to ensure that each one is named properly. I have a couple ideas floating around in my head to get beyond these two slight limitations, but at least the script is completely functional.

perezmu:
To address your comment about this being very time and memory consuming, I did notice that it did indeed take much time and memory for this script to run its course on a test of 10 books while running ComicRack in debug mood. It roughly took about 11 to 12 minutes. However, I was happy to find out that another test on 10 books while running ComicRack in regular mood where the scripts are compiled and optimized at startup was much faster. It took only about a couple seconds to run then. So the time and memory usage I’m hoping wouldn’t really be an issue except when ran on a large number of records at one time. Only future usage will determine just how well or how bad this script was written.


So thank you both for your valued input, especially you perezmu (there’s a Karma point in it for you), and I will be posting this script with my ideas shortly.

Thank you all!
Onyx X aka SoundWave
Last Edit: 8 years 3 months ago by oraclexview.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.204 seconds

Who's Online

We have 202 guests and 9 members online