mirror of
https://github.com/creyD/asiimov.git
synced 2026-06-12 00:52:23 +02:00
Added Functionality To Get Player Inventory
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="right_nav" class="nav_box">
|
<div id="right_nav" class="nav_box">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<a href="{% url 'offer_create' %}">Add Offer</a> | <a href="{% url 'me_settings' %}">Settings</a> | Welcome, <a href="{% url 'me' %}">{{ user.gamer.personaname }} <a href="{% url 'logout' %}">(Logout)</a></a>
|
<a href="{% url 'offer_create' %}">Add Offer</a> | <a href="{% url 'me_inventory' %}">Inventory</a> | <a href="{% url 'me_settings' %}">Settings</a> | Welcome, <a href="{% url 'me' %}">{{ user.gamer.personaname }} <a href="{% url 'logout' %}">(Logout)</a></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url 'signup' %}"><img src="{% static 'pic/steam_sign_in.png' %}" /></a>
|
<a href="{% url 'signup' %}"><img src="{% static 'pic/steam_sign_in.png' %}" /></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
23
src/core/migrations/0004_auto_20200119_1201.py
Normal file
23
src/core/migrations/0004_auto_20200119_1201.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.0.2 on 2020-01-19 11:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0003_gamer_offer_count'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='itemtype',
|
||||||
|
name='max_float',
|
||||||
|
field=models.FloatField(null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='itemtype',
|
||||||
|
name='min_float',
|
||||||
|
field=models.FloatField(null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
23
src/core/migrations/0005_auto_20200119_1205.py
Normal file
23
src/core/migrations/0005_auto_20200119_1205.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.0.2 on 2020-01-19 11:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0004_auto_20200119_1201'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='iteminstance',
|
||||||
|
name='float',
|
||||||
|
field=models.FloatField(null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='iteminstance',
|
||||||
|
name='paintseed',
|
||||||
|
field=models.IntegerField(null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
36
src/core/migrations/0006_auto_20200119_1240.py
Normal file
36
src/core/migrations/0006_auto_20200119_1240.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Generated by Django 3.0.2 on 2020-01-19 11:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0005_auto_20200119_1205'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='iteminstance',
|
||||||
|
name='float',
|
||||||
|
field=models.FloatField(default=0),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='iteminstance',
|
||||||
|
name='inspect_link',
|
||||||
|
field=models.URLField(default='http://test.org', max_length=512),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='iteminstance',
|
||||||
|
name='market_tradable_restriction',
|
||||||
|
field=models.CharField(max_length=1, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='iteminstance',
|
||||||
|
name='paintseed',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -29,8 +29,8 @@ class ItemType(models.Model):
|
|||||||
name_color = models.CharField(max_length=7) # Hexadecimal color of the name
|
name_color = models.CharField(max_length=7) # Hexadecimal color of the name
|
||||||
type = models.CharField(max_length=1000) # i.e. ★ Covert Knife
|
type = models.CharField(max_length=1000) # i.e. ★ Covert Knife
|
||||||
rarity = models.CharField(max_length=1000) # tags > category = rarity > localized_tag_name
|
rarity = models.CharField(max_length=1000) # tags > category = rarity > localized_tag_name
|
||||||
min_float = models.FloatField()
|
min_float = models.FloatField(null=True) # At creation time there is no data, so we need null=True
|
||||||
max_float = models.FloatField()
|
max_float = models.FloatField(null=True) # At creation time there is no data, so we need null=True
|
||||||
|
|
||||||
|
|
||||||
# Class for storing stickers applied to weapons
|
# Class for storing stickers applied to weapons
|
||||||
@@ -43,13 +43,13 @@ class Stickers(models.Model):
|
|||||||
class ItemInstance(models.Model):
|
class ItemInstance(models.Model):
|
||||||
item_class = models.ForeignKey(ItemType, on_delete=models.PROTECT)
|
item_class = models.ForeignKey(ItemType, on_delete=models.PROTECT)
|
||||||
instanceid = models.IntegerField(primary_key=True, unique=True) # 0 for something like cases, which will be excluded here
|
instanceid = models.IntegerField(primary_key=True, unique=True) # 0 for something like cases, which will be excluded here
|
||||||
market_tradable_restriction = models.IntegerField() # How long the item will be trade locked
|
market_tradable_restriction = models.CharField(max_length=1, null=True) # How long the item will be trade locked | null is not tradelocked
|
||||||
inspect_link = models.URLField(max_length=512, null=True)
|
inspect_link = models.URLField(max_length=512)
|
||||||
wear = models.CharField(max_length=100) # tags > category = exterior > localized_tag_name
|
wear = models.CharField(max_length=100) # tags > category = exterior > localized_tag_name
|
||||||
float = models.FloatField() # Float of the object
|
float = models.FloatField() # Float of the object
|
||||||
paintseed = models.IntegerField() # Pattern ID
|
paintseed = models.IntegerField() # Pattern ID
|
||||||
killeatervalue = models.IntegerField(null=True) # StatTrack
|
killeatervalue = models.IntegerField(null=True) # StatTrack | null is no StatTrack
|
||||||
customname = models.CharField(max_length=128, null=True) # Nametag
|
customname = models.CharField(max_length=128, null=True) # Nametag | null is no Nametag
|
||||||
stickers = models.ManyToManyField(Stickers)
|
stickers = models.ManyToManyField(Stickers)
|
||||||
|
|
||||||
def getInspectLink(self):
|
def getInspectLink(self):
|
||||||
@@ -87,7 +87,7 @@ class Gamer(models.Model):
|
|||||||
avatar = models.URLField(max_length=256)
|
avatar = models.URLField(max_length=256)
|
||||||
commentpermission = models.BooleanField() # If set, profile allows public comments
|
commentpermission = models.BooleanField() # If set, profile allows public comments
|
||||||
|
|
||||||
# Optional Fields (only available if public profile)
|
# Optional Fields (only available if public profile else null)
|
||||||
timecreated = models.IntegerField(null=True) # Only visible if user has profile visibility
|
timecreated = models.IntegerField(null=True) # Only visible if user has profile visibility
|
||||||
loccountrycode = models.CharField(max_length=2, null=True) # 2 char ISO country code
|
loccountrycode = models.CharField(max_length=2, null=True) # 2 char ISO country code
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import urllib.request
|
|||||||
import json
|
import json
|
||||||
# For getting the STEAM_API_KEY
|
# For getting the STEAM_API_KEY
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from .models import Gamer, ItemType, ItemInstance
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
STEAM_SERVER = 'https://api.steampowered.com/'
|
STEAM_SERVER = 'https://api.steampowered.com/'
|
||||||
USER_METHOD = 'ISteamUser/GetPlayerSummaries/v2'
|
USER_METHOD = 'ISteamUser/GetPlayerSummaries/v2'
|
||||||
@@ -18,13 +20,68 @@ def getUserInfo(steamID, API_KEY=settings.STEAM_API_KEY):
|
|||||||
return player_object['response']['players'][0]
|
return player_object['response']['players'][0]
|
||||||
|
|
||||||
|
|
||||||
|
def getInstanceData(inventory_object, instance_id):
|
||||||
|
for key in inventory_object['descriptions']:
|
||||||
|
if key['instanceid'] == instance_id:
|
||||||
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
def getFloat(inspect_link):
|
||||||
|
QUERY = FLOAT_SERVER + inspect_link
|
||||||
|
float_object = json.load(urllib.request.urlopen(QUERY))
|
||||||
|
if 'error' in float_object:
|
||||||
|
return False
|
||||||
|
return float_object
|
||||||
|
|
||||||
|
|
||||||
|
def getSubTag(scope, search_key, search_value):
|
||||||
|
for tag in scope:
|
||||||
|
if tag.search_key == search_value:
|
||||||
|
return tag
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Get the CS:GO inventory of a gamer
|
# Get the CS:GO inventory of a gamer
|
||||||
def getUserInventory(steamID, API_KEY=settings.STEAM_API_KEY, GAME_ID=730):
|
def updateInventory(steamID, GAME_ID=730):
|
||||||
QUERY = INVENTORY_SERVER + '/' + steamID + '/' + GAME_ID + '/2?l=english&count=5000'
|
gamer = get_object_or_404(Gamer, steamid=steamID)
|
||||||
|
QUERY = INVENTORY_SERVER + str(steamID) + '/' + str(GAME_ID) + '/2?l=english&count=5000'
|
||||||
inventory_object = json.load(urllib.request.urlopen(QUERY))
|
inventory_object = json.load(urllib.request.urlopen(QUERY))
|
||||||
return inventory_object
|
if 'success' in inventory_object:
|
||||||
|
for item in inventory_object['assets']:
|
||||||
|
if item['instanceid'] == 0:
|
||||||
def getFloat(asset, steamID):
|
pass
|
||||||
QUERY = FLOAT_SERVER + asset.getInspectLink()
|
else:
|
||||||
return json.load(urllib.request.urlopen(QUERY))
|
instance_data = getInstanceData(inventory_object, item['instanceid'])
|
||||||
|
link = instance_data['actions'][0]['link'].replace("%owner_steamid%", str(steamID)).replace("%assetid%", str(item['instanceid']))
|
||||||
|
while (True):
|
||||||
|
item_infos = getFloat(link)
|
||||||
|
if item_infos:
|
||||||
|
break
|
||||||
|
item_class = ItemType.objects.get_or_create(
|
||||||
|
paint_index=item_infos['iteminfo']['paintindex'],
|
||||||
|
classid=item['classid'],
|
||||||
|
appid=item['appid'],
|
||||||
|
tradable=(True if item['marketable'] == 1 else False),
|
||||||
|
icon_url=item_infos['iteminfo']['imageurl'],
|
||||||
|
name=item['name'],
|
||||||
|
name_color=item['name_color'],
|
||||||
|
type=item['type'],
|
||||||
|
rarity=getSubTag(item['tags'], 'category', 'Rarity').localized_tag_name,
|
||||||
|
min_float=item_infos['iteminfo']['min'],
|
||||||
|
max_float=item_infos['iteminfo']['max']
|
||||||
|
)
|
||||||
|
new_item = ItemInstance.objects.get_or_create(
|
||||||
|
item_class=item_class[0],
|
||||||
|
instanceid=item['instanceid'],
|
||||||
|
market_tradable_restriction=(item['owner_descriptions'][1]['value']
|
||||||
|
if 'owner_descriptions' in item else None),
|
||||||
|
inspect_link=instance_data['actions'][0]['link'],
|
||||||
|
wear=item_infos['iteminfo']['wear_name'],
|
||||||
|
float=item_infos['iteminfo']['floatvalue'],
|
||||||
|
paintseed=item_infos['iteminfo']['paintseed'],
|
||||||
|
killeatervalue=(item_infos['iteminfo']['killeatervalue'] if 'killeatervalue' in item_infos['iteminfo'] else None),
|
||||||
|
customname=(item_infos['iteminfo']['customname'] if 'customname' in item_infos['iteminfo'] else None)
|
||||||
|
)
|
||||||
|
gamer.inventory.add(new_item)
|
||||||
|
return inventory_object
|
||||||
|
return False
|
||||||
|
|||||||
24
src/core/templates/profile/inventory.html
Normal file
24
src/core/templates/profile/inventory.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{% extends 'master.html' %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<!-- Adding custom style sheet for profile-->
|
||||||
|
<link rel="stylesheet" href="{% static 'css/profile.css' %}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="content_block">
|
||||||
|
<h3>{{ gamer.personaname }} - Inventory</h3>
|
||||||
|
|
||||||
|
{% if request.user.gamer == gamer %}<p><a href="{% url 'profile_inventory_update' gamer.steamid %}">Refresh Inventory Data</a></p>{% endif %}
|
||||||
|
|
||||||
|
{% for item in gamer.inventory.all %}
|
||||||
|
<div>
|
||||||
|
<h4 style="color: #{{ item.item_class.name_color }}">item.item_class.name</h4>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
{% empty %}
|
||||||
|
No Invetory Data!
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<h3>Links</h3>
|
<h3>Links</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<a href="{{ gamer.profileurl }}" target="_blank"><li>Steam</li></a>
|
<a href="{{ gamer.profileurl }}" target="_blank"><li>Steam</li></a>
|
||||||
|
<a href="{% url 'profile_inventory' gamer.steamid%}"><li>Inventory</li></a>
|
||||||
<a href="http://csgo.exchange/id/{{ gamer.steamid }}"><li>csgo.exchange</li></a>
|
<a href="http://csgo.exchange/id/{{ gamer.steamid }}"><li>csgo.exchange</li></a>
|
||||||
{% if gamer.tradeurl %}<a href="{{ gamer.tradeurl }}" target="_blank"><li>Trade</li></a>{% endif %}
|
{% if gamer.tradeurl %}<a href="{{ gamer.tradeurl }}" target="_blank"><li>Trade</li></a>{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -35,9 +36,9 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3>Statistics</h3>
|
<h3>Statistics</h3>
|
||||||
|
<p>Live Offers: <b>{{ live_offers }}</b></p>
|
||||||
<p>Offers created: {{ gamer.offer_count }}</p>
|
<p>Offers created: {{ gamer.offer_count }}</p>
|
||||||
<p>Live Offers: {{ live_offers }}</p>
|
<p>Asiimov Member since: {{ gamer.system_user.date_joined }}</p>
|
||||||
<p>Member since: {{ gamer.system_user.date_joined }}</p>
|
<p>Last Asiimov Login: {{ gamer.system_user.last_login }}</p>
|
||||||
<p>Last Login: {{ gamer.system_user.last_login }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ urlpatterns = [
|
|||||||
path('search/<str:filter>', views.search, name='search'),
|
path('search/<str:filter>', views.search, name='search'),
|
||||||
path('profile/<int:steamID>', views.profile, name='profile'),
|
path('profile/<int:steamID>', views.profile, name='profile'),
|
||||||
path('profile/<int:steamID>/update', views.profile_update, name='profile_update'),
|
path('profile/<int:steamID>/update', views.profile_update, name='profile_update'),
|
||||||
path('profile/me', views.me, name='me'),
|
path('profile/<int:steamID>/inventory', views.profile_inventory, name='profile_inventory'),
|
||||||
path('profile/settings', views.me_settings, name='me_settings'),
|
path('profile/<int:steamID>/inventory/update', views.profile_inventory_update, name='profile_inventory_update'),
|
||||||
|
path('me', views.me, name='me'),
|
||||||
|
path('me/settings', views.me_settings, name='me_settings'),
|
||||||
|
path('me/inventory', views.me_inventory, name='me_inventory'),
|
||||||
|
|
||||||
path('help', views.help, name='help'),
|
path('help', views.help, name='help'),
|
||||||
path('imprint', views.imprint, name='imprint'),
|
path('imprint', views.imprint, name='imprint'),
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import requests
|
|||||||
# For manually creating system users
|
# For manually creating system users
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
# For getting the API interaction methods
|
# For getting the API interaction methods
|
||||||
from .steam_api import getUserInfo
|
from .steam_api import getUserInfo, updateInventory
|
||||||
# Import for manually logging in user after creation
|
# Import for manually logging in user after creation
|
||||||
from django.contrib.auth import login
|
from django.contrib.auth import login
|
||||||
|
|
||||||
@@ -137,6 +137,12 @@ def profile(request, steamID):
|
|||||||
return render(request, 'profile/profile.html', {'gamer': dude, 'live_offers': Offer.objects.filter(offeror=dude).count()})
|
return render(request, 'profile/profile.html', {'gamer': dude, 'live_offers': Offer.objects.filter(offeror=dude).count()})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def profile_inventory(request, steamID):
|
||||||
|
dude = get_object_or_404(Gamer, steamid=steamID)
|
||||||
|
return render(request, 'profile/inventory.html', {'gamer': dude})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profile_update(request, steamID):
|
def profile_update(request, steamID):
|
||||||
if (request.user.steamid == steamID and request.user.gamer.API_KEY) or request.user.is_staff:
|
if (request.user.steamid == steamID and request.user.gamer.API_KEY) or request.user.is_staff:
|
||||||
@@ -160,8 +166,18 @@ def profile_update(request, steamID):
|
|||||||
# PRIVATE AREA
|
# PRIVATE AREA
|
||||||
@login_required
|
@login_required
|
||||||
def me(request):
|
def me(request):
|
||||||
dude = get_object_or_404(Gamer, steamid=request.user.gamer.steamid)
|
return redirect(profile, steamID=request.user.gamer.steamid)
|
||||||
return render(request, 'profile/profile.html', {'gamer': dude, 'live_offers': Offer.objects.filter(offeror=dude).count()})
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def me_inventory(request):
|
||||||
|
return redirect(profile_inventory, steamID=request.user.gamer.steamid)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def profile_inventory_update(request, steamID):
|
||||||
|
updateInventory(steamID)
|
||||||
|
return redirect(profile_inventory, steamID=steamID)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
Reference in New Issue
Block a user