Price: $ {{ Game.price }}
Developer: {{ Game.developer }}
diff --git a/app/realDealz/library.py b/app/realDealz/library.py index ebc62f2..d9d491c 100644 --- a/app/realDealz/library.py +++ b/app/realDealz/library.py @@ -6,6 +6,7 @@ import requests from environs import Env import os +import requests log.basicConfig(level=log.INFO) @@ -142,6 +143,27 @@ def m_post(self, url : str, p_fields : dict , p_headers : dict = None): ).data) return result + def get_game_image(self, app_id): + '''Get the header image of the specified game using the Steam API''' + url = f"{self.base['steam']}appdetails?appids={app_id}" + response = requests.get(url) + data = response.json() + if data[str(app_id)]['success']: + return data[str(app_id)]['data']['header_image'] + else: + return None + +# This is for testing +# It will only run if this file is run directly +if __name__ == "__main__": + library = Library() + # print(library.search_all()) + #print(library.get_top_100()) + + #testing game images + app_id = 130 #Testing Counter-Strike + image_url = library.get_game_image(app_id) + print(f"Header image for app ID {app_id}: {image_url}") @val_auth def get_images(self): @@ -156,26 +178,4 @@ def get_images(self): with open("amazing_image.jpg", "wb") as f: f.write(b) - return r.json() - -#!Fixme this doesn't work yet but it will soon - def get_wishlist(self, steam_id): - '''Get the wishlist of a steam user''' - _url = self.base['steam'] + f"wishlist/{steam_id}/wishlistdata/" - _headers = {"Accept": "application/json"} - req = requests.get(_url, headers=_headers) - - return dir(req) - -def test_img(): - l = Library(True, True) - # print(l.search_all()) - print(l.get_wishlist("76561198180301021")) - # print(l.get_images()) - -# This is for testing -# It will only run if this file is run directly -if __name__ == "__main__": - test_img() - - + return r.json() \ No newline at end of file diff --git a/app/realDealz/migrations/0001_initial.py b/app/realDealz/migrations/0001_initial.py index cfc28bb..59286bf 100644 --- a/app/realDealz/migrations/0001_initial.py +++ b/app/realDealz/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.1.7 on 2023-04-25 02:30 +# Generated by Django 4.1.7 on 2023-05-01 19:37 from django.db import migrations, models diff --git a/app/realDealz/models.py b/app/realDealz/models.py index 7ccfd16..e3730dd 100644 --- a/app/realDealz/models.py +++ b/app/realDealz/models.py @@ -2,6 +2,10 @@ from django.urls import reverse import logging as log import realDealz.library as lib + +# create an instance of the Library class +my_library = lib() + # Model attributes are declared here #Allow multiple platforms @@ -35,8 +39,6 @@ def __str__(self): return str(self.sources) - - class Game(models.Model): '''Generic Game model''' @@ -64,7 +66,7 @@ def __str__(self): genre = models.CharField(max_length=100, default="IDK", help_text='genre') - + @classmethod def initial_load(self): '''Load the initial library from steamspy''' @@ -103,7 +105,11 @@ def clear_all(self): def get_absolute_url(self): '''Returns the URL to access a detail record for this Game.''' return reverse('game-detail', args=[str(self.appid)]) - + + @property + def image_url(self): + return my_library.get_game_image(self.appid) + if __name__ == "__main__": - print("Hello World") - # Game().initial_load \ No newline at end of file + #print("Hello World") + Game().initial_load diff --git a/app/templates/realDealz/game_detail.html b/app/templates/realDealz/game_detail.html index db10d0b..79d33a5 100644 --- a/app/templates/realDealz/game_detail.html +++ b/app/templates/realDealz/game_detail.html @@ -6,7 +6,7 @@
Price: $ {{ Game.price }}
Developer: {{ Game.developer }}