Skip to content

Commit

Permalink
Retrieve cards via marvelsnapzone API
Browse files Browse the repository at this point in the history
  • Loading branch information
vlmaier committed Aug 9, 2023
1 parent ab63e11 commit 810e175
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions scrapr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@

CARDS_API_URL = "http://localhost:8080/v1/cards"
MARVELSNAPZONE_URL = 'https://marvelsnapzone.com/cards'
MARVELSNAPZONE_API_URL = 'https://marvelsnapzone.com/getinfo/?searchtype=cards&searchcardstype=true'


def get_cards():
print("[%s] %s" % (datetime.now(), "Starting retrieving cards ..."))
response = requests.get(MARVELSNAPZONE_API_URL)

if response.status_code == 200:
json_data = response.json()
success = json_data.get("success", {})
return success.get("cards", [])
else:
print(f"Error: Request failed with status code {response.status_code}")


def scrap():
Expand Down Expand Up @@ -44,7 +57,6 @@ def scrap():
characters.append(character)
print("[%s] %s" % (datetime.now(), f"Found {character['name']}"))

# TODO: uncomment to download card images.
image_urls = [character['url'] for character in characters]
download_images(image_urls)

Expand Down Expand Up @@ -83,7 +95,7 @@ def download_image(url, dir_name):
try:
response = requests.get(url)
response.raise_for_status()
file_name = url.rsplit('/', 1)[-1]
file_name = url.rsplit('/', 1)[-1].rsplit('?', 1)[0]
file_path = os.path.join(dir_name, file_name)
with open(file_path, 'wb') as file:
file.write(response.content)
Expand Down Expand Up @@ -194,5 +206,8 @@ def parse_source(source):


if __name__ == '__main__':
characters = scrap()
cards = get_cards()
image_urls = [card['art'] for card in cards]
download_images(image_urls)
# characters = scrap()
# create_cards(characters)

1 comment on commit 810e175

@vlmaier
Copy link
Owner Author

@vlmaier vlmaier commented on 810e175 Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the approach from the issue #20

Please sign in to comment.