Welcome to the Club Penguin Wiki! Log in or Create an account to join the community!
User:Kawkeetcp/Catalog Items Generator: Difference between revisions
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]] | 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 | # 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 | # Set month and catalog ("penstyle" = Penguin Style, "iglooedit" = Furniture & Igloo Catalog) | ||
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) | ||
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 | # Initialize empty lists and item counter | ||
itemLists = [[] for i in range(len( | 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," | 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(" | with open(catalog + ".json","r") as catalogJSON: | ||
content = json.loads(catalogJSON.read()) | |||
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(" | page = int(components[i]["name"].replace(catalog + "_page","")) | ||
for listIndex in range(0,len( | for listIndex in range(0,len(sectionList)): | ||
if page >= | 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("===" + | 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( | 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")