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

User:Kawkeetcp/Catalog Items Generator: Difference between revisions

From the Club Penguin Wiki, the free, editable encyclopedia about Club Penguin
Jump to navigation Jump to search
imported>Kawkeetcp
Correcting link.
imported>Kawkeetcp
Updating to work with Furniture & Igloo Catalog.
 
Line 1: Line 1:
The following is a script I wrote in [https://www.python.org/downloads/ Python 3.4] that can be used for generating content for the [[Template:Penguin Style|Penguin Style]] catalog pages. However, understand that the current values for the page ranges are specific to the [http://archives.clubpenguinwiki.info/wiki/File:ENCataloguesClothingFeb2016.json February 2016 Penguin Style] and will likely need to be changed for other months.
The following is a script I wrote in [https://www.python.org/downloads/ Python 3.4] that can be used for generating content for the [[Template:Penguin Style|Penguin Style]] and [[Template:Furniture & Igloo Catalog|Furniture & Igloo Catalog]] pages. However, understand that the current values for the page ranges are specific to the February 2016 [http://archives.clubpenguinwiki.info/wiki/File:ENCataloguesClothingFeb2016.json Penguin Style] and [http://archives.clubpenguinwiki.info/wiki/File:ENCataloguesFurnitureFeb2016.json Furniture & Igloo Catalog] (since that was when I coded this) and will likely need to be changed for other months. Section names are also subject to change.
 
If you are only interested in generating items for certain sections (such as "This Month's Fashions"), you only need to worry about changing the page ranges for those sections. Make sure to then only copy those sections from the output text file. For the other item sections, you can just copy them from the previous catalog pages on the wiki, assuming that the items are the same.


If you don't feel like logging in and counting the pages to determine the page numbers, there is a script [http://clubpenguin.wikia.com/wiki/User:Hey.youcp/Resources/Catalog_Pages_Downloader 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.
If you don't feel like logging in and counting the pages to determine the page numbers, there is a script [http://clubpenguin.wikia.com/wiki/User:Hey.youcp/Resources/Catalog_Pages_Downloader 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.
Line 5: Line 7:
==Code==
==Code==
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
# Description: Generates items from Penguin Style catalog
# Description: Generates items from Penguin Style or Furniture & Igloo Catalog
# Author: Hey.youcp
# Author: Hey.youcp
# Date: February 13, 2016
# Date: February 13, 2016 / February 19, 2016


import urllib.request
import urllib.request
Line 13: Line 15:
import webbrowser
import webbrowser


# Set link to clothing catalog
# Set month and catalog ("penstyle" = Penguin Style, "iglooedit" = Furniture & Igloo Catalog)
catalogLink = "http://media8.clubpenguin.com/mobile/cp-mobile-ui/clubpenguin_v1_6/en_US/deploy/metaplace/devicepng/config/catalog/penstyle.json"
month = "February"
catalog = "penstyle"


# Set page ranges to search for items (cover page is counted as page 0)
# Set section titles and page ranges to search for items (cover page is counted as page 0)
colors = [2,2]
if catalog == "penstyle":
itemsForEveryone = [4,4]
    sectionList = [
newFashions = [6,16]
        ("Colors",[2,2]),("Items for Everyone",[4,4]),("This Month's Fashions",[6,16]),("Last Month's Fashions",[17,32]),("Get the Look!",[34,34]),
oldFashions = [17,32]
        ("Penguins at Work",[35,35]),("=Items for Everyone=",[37,38]),("=Head Items=",[39,46]),("=Face Items=",[47,50]),("=Neck Items=",[51,56]),
getTheLook = [34,34]
        ("=Body Items=",[57,64]),("=Hand Items=",[65,70]),("=Feet Items=",[71,74]),("Backgrounds",[75,76]),("Flags",[77,78])
penguinsAtWork = [35,35]
    ]
itemsForEveryone = [37,38]
elif catalog == "iglooedit":
headItems = [39,46]
    sectionList = [
faceItems = [47,50]
        (month + "'s Featured Furniture",[3,6]),("Last Month's Featured Furniture",[7,10]),(month + "'s Featured Igloos",[11,14]),
neckItems = [51,56]
        ("Last Month's Featured Igloos",[15,18]),("Igloo Flooring",[19,19]),("=Items for Everyone=",[21,22]),("=Wall Items=",[23,36]),
bodyItems = [57,64]
        ("=Floor Items=",[37,40]),("=Room Items=",[41,54]),("Essential Igloos",[55,62]),("Igloo Locations",[63,73])
handItems = [65,70]
    ]
feetItems = [71,74]
else:
backgrounds = [75,76]
    sectionList = []
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
# Initialize empty lists and item counter
itemLists = [[] for i in range(len(rangeList))]
itemLists = [[] for i in range(len(sectionList))]
itemCount = 0
itemCount = 0
# Set link to catalog JSON
catalogLink = "http://media8.clubpenguin.com/mobile/cp-mobile-ui/clubpenguin_v1_6/en_US/deploy/metaplace/devicepng/config/catalog/" + catalog + ".json"


# Download JSON file
# Download JSON file
isFound = False
isFound = False
try:
try:
     urllib.request.urlretrieve(catalogLink,"penstyle.json")
     urllib.request.urlretrieve(catalogLink,catalog + ".json")
     print("JSON file found. Now processing items...")
     print("JSON file found. Now processing items...")
     isFound = True
     isFound = True
Line 54: Line 53:
if isFound:
if isFound:
     # Read catalog JSON
     # Read catalog JSON
     with open("penstyle.json","r") as catalogJSON:
     with open(catalog + ".json","r") as catalogJSON:
         catalog = json.loads(catalogJSON.read())
         content = json.loads(catalogJSON.read())
     components = catalog["components"]
     components = content["components"]


     # Search catalog JSON
     # Search catalog JSON
Line 65: Line 64:


                 # Add items to lists
                 # Add items to lists
                 page = int(components[i]["name"].replace("penstyle_page",""))
                 page = int(components[i]["name"].replace(catalog + "_page",""))
                 for listIndex in range(0,len(rangeList)):
                 for listIndex in range(0,len(sectionList)):
                     if page >= rangeList[listIndex][0] and page <= rangeList[listIndex][1]:
                     if page >= sectionList[listIndex][1][0] and page <= sectionList[listIndex][1][1]:
                         if itemName not in itemLists[listIndex]:
                         if itemName not in itemLists[listIndex]:
                             itemLists[listIndex].append(itemName)
                             itemLists[listIndex].append(itemName)
Line 75: Line 74:
     with open("output.txt","w") as output:
     with open("output.txt","w") as output:
         for i in range(0,len(itemLists)):
         for i in range(0,len(itemLists)):
             if i == 6: output.write("===Essential Items===\n")
             if i == 6 and catalog == "penstyle":
             output.write("===" + titleList[i] + "===\n<gallery>\n")
                output.write("===Essential Items===\n")
            elif i == 5 and catalog == "iglooedit":
                output.write("===Igloo Essentials===\n")
             output.write("===" + sectionList[i][0] + "===\n<gallery>\n")
             for j in range(0,len(itemLists[i])):
             for j in range(0,len(itemLists[i])):
                 item = itemLists[i][j]
                 item = itemLists[i][j]
                 output.write("File:" + item.replace(" ","") + ".png|[[" + item + "]]\n")
                 output.write(item.replace(" ","") + ".png|[[" + item + "]]\n")
             output.write("</gallery>\n\n")
             output.write("</gallery>\n\n")



Latest revision as of 04:13, 20 February 2016

The following is a script I wrote in Python 3.4 that can be used for generating content for the Penguin Style and Furniture & Igloo Catalog pages. However, understand that the current values for the page ranges are specific to the February 2016 Penguin Style and Furniture & Igloo Catalog (since that was when I coded this) and will likely need to be changed for other months. Section names are also subject to change.

If you are only interested in generating items for certain sections (such as "This Month's Fashions"), you only need to worry about changing the page ranges for those sections. Make sure to then only copy those sections from the output text file. For the other item sections, you can just copy them from the previous catalog pages on the wiki, assuming that the items are the same.

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 or Furniture & Igloo Catalog
# Author: Hey.youcp
# Date: February 13, 2016 / February 19, 2016

import urllib.request
import json
import webbrowser

# Set month and catalog ("penstyle" = Penguin Style, "iglooedit" = Furniture & Igloo Catalog)
month = "February"
catalog = "penstyle"

# Set section titles and page ranges to search for items (cover page is counted as page 0)
if catalog == "penstyle":
    sectionList = [
        ("Colors",[2,2]),("Items for Everyone",[4,4]),("This Month's Fashions",[6,16]),("Last Month's Fashions",[17,32]),("Get the Look!",[34,34]),
        ("Penguins at Work",[35,35]),("=Items for Everyone=",[37,38]),("=Head Items=",[39,46]),("=Face Items=",[47,50]),("=Neck Items=",[51,56]),
        ("=Body Items=",[57,64]),("=Hand Items=",[65,70]),("=Feet Items=",[71,74]),("Backgrounds",[75,76]),("Flags",[77,78])
    ]
elif catalog == "iglooedit":
    sectionList = [
        (month + "'s Featured Furniture",[3,6]),("Last Month's Featured Furniture",[7,10]),(month + "'s Featured Igloos",[11,14]),
        ("Last Month's Featured Igloos",[15,18]),("Igloo Flooring",[19,19]),("=Items for Everyone=",[21,22]),("=Wall Items=",[23,36]),
        ("=Floor Items=",[37,40]),("=Room Items=",[41,54]),("Essential Igloos",[55,62]),("Igloo Locations",[63,73])
    ]
else:
    sectionList = []

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

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

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

if isFound:
    # Read catalog JSON
    with open(catalog + ".json","r") as catalogJSON:
        content = json.loads(catalogJSON.read())
    components = content["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(catalog + "_page",""))
                for listIndex in range(0,len(sectionList)):
                    if page >= sectionList[listIndex][1][0] and page <= sectionList[listIndex][1][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 and catalog == "penstyle":
                output.write("===Essential Items===\n")
            elif i == 5 and catalog == "iglooedit":
                output.write("===Igloo Essentials===\n")
            output.write("===" + sectionList[i][0] + "===\n<gallery>\n")
            for j in range(0,len(itemLists[i])):
                item = itemLists[i][j]
                output.write(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")