Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json, requests, math, sys
- from PIL import Image
- def generate_wallpaper(argv):
- #determine the number of columns and rows based off of user input
- cols = int(argv[1])
- rows = math.ceil(36/cols)
- #get json data about the deck from the api
- response = requests.get('https://www.keyforgegame.com/api/decks/' + argv[0] + '/?links=cards')
- data = json.loads(response.content)
- #get a list of card ids from the json
- cardlist = data['data']['_links']['cards']
- #get the data for each card in the deck
- carddata = data['_linked']['cards']
- #create a blank image that matches the size of the rows and columns
- wallpaper = Image.new('RGB', (300*cols,420*rows))
- #the offsets will be used to make sure each image is pasted in the correct
- #place in the blank image
- x_offset = 0
- y_offset = 0
- max_offset = 300*cols
- for card in cardlist:
- #using the link to the card image, download the image
- image_link = [x['front_image'] for x in carddata if x['id'] == card][0]
- card_image = Image.open(requests.get(image_link, stream=True).raw)
- #paste the downloaded image into the blank image
- wallpaper.paste(card_image, (x_offset, y_offset))
- #update the offsets for the next card
- x_offset += 300
- if x_offset >= max_offset:
- x_offset = 0
- y_offset += 420
- #save the file
- wallpaper.save('keyforge_wallpaper.jpg')
- if __name__ == "__main__":
- #this is where the program starts
- #it passes the arguements you specified to the generate_wallpaper function
- generate_wallpaper(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment