Skip to content

Instantly share code, notes, and snippets.

@akosnikhazy
Last active July 4, 2016 21:12
Show Gist options
  • Save akosnikhazy/3febc444d7f638f3e7534b4d5e99450b to your computer and use it in GitHub Desktop.
Save akosnikhazy/3febc444d7f638f3e7534b4d5e99450b to your computer and use it in GitHub Desktop.
This primitive little program downloads Spore creatures from spore.com
import urllib
import requests
import os
"I found that all the public creatures are in this folder's subfolder"
baseURL = 'http://static.spore.com/static/thumb/501/'
"""
Starting numbers. Download start at these numbers.
Folders look like in the 501 folder: /012/034/501012024001.png
Where the filename is the folder names and the file number: 501|012|034|001.png
countOut is the first number
countIn is the second number
image is the third number
"""
countOut = 0
countIn = 0
image = 0
"sits next to this py file. Created if not exists"
downloadDir = 'test'
def threeDigits(input):
"Because all directories are three digit strings"
if input < 10:
return str('00' + str(input))
elif input >= 10 and input < 100:
return str('0' + str(input))
else:
return str(input)
def makeDir(name):
"very basic"
if not os.path.exists(name):
os.makedirs(name)
while (countOut < 36):
a = threeDigits(countOut)
while (countIn < 1000):
b = threeDigits(countIn)
while(image < 1000):
c = threeDigits(image)
imageURL = baseURL+a+'/'+b+'/501'+str(a)+str(b)+str(c)+'.png'
print(imageURL)
makeDir(downloadDir+'/'+str(a)+'/'+str(b))
"we really have to check for the file if it exists. Otherwise you end up with fake png files"
"there are more invalid file numbers than valid ones"
request = requests.get(imageURL)
if request.status_code != 200:
print('no such file')
else:
urllib.urlretrieve(imageURL, downloadDir + '/' + str(a) + '/' + str(b) + '/501' + str(a) + str(b) + str(c) + '.png')
print("success")
print('--------')
image+=1
countIn += 1
image = 0
countOut += 1
countIn = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment