Welcome to the Club Penguin Wiki! Log in or Create an account to join the community!

User:Kawkeetcp/Catalog Items Generator

From the Club Penguin Wiki, the free, editable encyclopedia about Club Penguin
Revision as of 09:09, 14 February 2016 by imported>Kawkeetcp (Creating a page for a script I wrote for the wiki.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The following is a script I wrote in Python 3.4 that can be used for generating content for the Penguin Style catalog pages. However, understand that the current values for the page ranges are specific to the February 2016 Penguin Style and will likely need to be changed for other months.

If you don't feel like logging in and counting the pages to determine the page numbers, there is a script here that downloads all of the pages and numbers them. You may also have to change some item names that the script generates, as they aren't always consistent with the names of item articles and images on the wiki. Regardless, it's much faster than going through the catalog and manually typing each item name.

Code

# Description: Generates items from Penguin Style catalog
# Author: Hey.youcp
# Date: February 13, 2016

import urllib.request
import json
import webbrowser

# Set link to clothing catalog
catalogLink = "http://media8.clubpenguin.com/mobile/cp-mobile-ui/clubpenguin_v1_6/en_US/deploy/metaplace/devicepng/config/catalog/penstyle.json"

# Set page ranges to search for items (cover page is counted as page 0)
colors = [2,2]
itemsForEveryone = [4,4]
newFashions = [6,16]
oldFashions = [17,32]
getTheLook = [34,34]
penguinsAtWork = [35,35]
itemsForEveryone = [37,38]
headItems = [39,46]
faceItems = [47,50]
neckItems = [51,56]
bodyItems = [57,64]
handItems = [65,70]
feetItems = [71,74]
backgrounds = [75,76]
flags = [77,78]

# Place page ranges into a list and set list titles
rangeList = [colors,itemsForEveryone,newFashions,oldFashions,getTheLook,penguinsAtWork,itemsForEveryone,
             headItems,faceItems,neckItems,bodyItems,handItems,feetItems,backgrounds,flags]
titleList = ["Colors","Items for Everyone","This Month's Fashion","Last Month's Fashion","Get the Look!","Penguins at Work","=Items for Everyone=",
             "=Head Items=","=Face Items=","=Neck Items=","=Body Items=","=Hand Items=","=Feet Items=","Backgrounds","Flags"]

# Initialize empty lists and item counter
itemLists = [[] for i in range(len(rangeList))]
itemCount = 0

# Download JSON file
isFound = False
try:
    urllib.request.urlretrieve(catalogLink,"penstyle.json")
    print("JSON file found. Now processing items...")
    isFound = True
except:
    print("JSON file not found.")

if isFound:
    # Read catalog JSON
    with open("penstyle.json","r") as catalogJSON:
        catalog = json.loads(catalogJSON.read())
    components = catalog["components"]

    # Search catalog JSON
    for i in range(1,len(components)-1):
        if "frames" in components[i]["layout"]:
            for j in range(0,len(components[i]["layout"]["frames"])):
                itemName = components[i]["layout"]["frames"][j]["name"]

                # Add items to lists
                page = int(components[i]["name"].replace("penstyle_page",""))
                for listIndex in range(0,len(rangeList)):
                    if page >= rangeList[listIndex][0] and page <= rangeList[listIndex][1]:
                        if itemName not in itemLists[listIndex]:
                            itemLists[listIndex].append(itemName)
                            itemCount += 1

    # Output items
    with open("output.txt","w") as output:
        for i in range(0,len(itemLists)):
            if i == 6: output.write("===Essential Items===\n")
            output.write("===" + titleList[i] + "===\n<gallery>\n")
            for j in range(0,len(itemLists[i])):
                item = itemLists[i][j]
                output.write("File:" + item.replace(" ","") + ".png|[[" + item + "]]\n")
            output.write("</gallery>\n\n")

    # Print item count and open output text file
    print("Done. " + str(itemCount) + " items were processed.")
    webbrowser.open("output.txt")