Skip to content

Instantly share code, notes, and snippets.

@entchen66
Created February 28, 2019 22:28
Show Gist options
  • Save entchen66/99963b112c82a39402d7157ed058327f to your computer and use it in GitHub Desktop.
Save entchen66/99963b112c82a39402d7157ed058327f to your computer and use it in GitHub Desktop.
get broken images
import aiohttp
import asyncio
import json
import string
import sys
from PIL import Image
import os
import datetime as datetime
import random
import locale
from io import BytesIO, FileIO
import math
locale.setlocale(locale.LC_ALL, "")
async def fetch_json(session, url):
async with session.get(url) as response:
# print(response.status)
assert response.status == 200
return await response.json()
async def fetch_image(session, url):
async with session.get(url) as response:
assert response.status == 200
return await response.read()
async def getImage(url):
async with aiohttp.ClientSession() as session:
response = await fetch_image(session, url)
return response
async def getPlayerID(playerName):
async with aiohttp.ClientSession() as session:
response = await fetch_json(session, f'https://fortnite-public-api.theapinetwork.com/prod09/users/id?username={playerName}')
return response
async def getPlayerStats(playerID):
async with aiohttp.ClientSession() as session:
response = await fetch_json(session, f'https://fortnite-public-api.theapinetwork.com/prod09/users/public/br_stats_v2?user_id={playerID}')
return response
async def getLTMs():
async with aiohttp.ClientSession() as session:
response = await fetch_json(session, f'https://fortnite-public-api.theapinetwork.com/prod09/playlists')
return response
async def getTest():
async with aiohttp.ClientSession() as session:
response = await fetch_json(session, 'https://fortnite-public-api.theapinetwork.com/prod09/items/list')
return response
async def getAllItems():
counter = 0
dict = {}
error = {}
jsonResponse = await getTest()
print(f'{counter} - {jsonResponse}')
for i in jsonResponse:
if i['type'] == 'outfit':
dict[counter] = i['images']['transparent']
print(i)
try:
icon = Image.open(BytesIO(await getImage(i['images']['transparent']))).convert('RGBA')
icon = icon.resize((512, 512), Image.ANTIALIAS)
icon.save(f'test-{counter}.png', 'PNG')
except:
error[i['identifier']] = i['name']
counter += 1
print(counter)
print(dict)
print(error)
loop = asyncio.get_event_loop()
loop.run_until_complete(getAllItems())
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment