Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions app/realDealz/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
from environs import Env
import os
import requests

log.basicConfig(level=log.INFO)

Expand Down Expand Up @@ -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):
Expand All @@ -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()
2 changes: 1 addition & 1 deletion app/realDealz/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 12 additions & 6 deletions app/realDealz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,8 +39,6 @@ def __str__(self):
return str(self.sources)




class Game(models.Model):
'''Generic Game model'''

Expand Down Expand Up @@ -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'''
Expand Down Expand Up @@ -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
#print("Hello World")
Game().initial_load
2 changes: 1 addition & 1 deletion app/templates/realDealz/game_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<h1>Title: {{ Game.name }}</h1>
<div class="wraptext">
<img src="{{ Game.cover.url }}" alt="Game Cover" height="450" width="300" class="blackborder" style="float:left; margin-right: 10px;">
<img src="{{ Game.image_url }}" alt="Game Cover" height="450" width="300" class="blackborder" style="float:left; margin-right: 10px;">
<div class="text">
<p><strong>Price:</strong> $ {{ Game.price }}</p>
<p><strong>Developer:</strong> {{ Game.developer }}</p>
Expand Down