from django.core.management.base import BaseCommand from engine.tcgplayer_api import TcgPlayerApi from engine.models import DirectData from datetime import date, timedelta api = TcgPlayerApi('first') class Command(BaseCommand): def handle(self, **options): listed_cards = api.get_category_skus('magic') success = listed_cards['success'] if success is True: direct_database = DirectData.objects cards = listed_cards['results'] non_direct = 0 for card in cards: if card['directLowPrice'] is None: non_direct += 1 sku = card['skuId'] database_entry_check = direct_database.filter(sku=sku).exists() if database_entry_check is True: entry = direct_database.get(sku=sku) entry.total_days_non_direct += 1 if date.today() - timedelta(days=1) == entry.last_add: entry.consecutive_days_non_direct += 1
from django.core.management.base import BaseCommand from orders.tasks import update_moose_tcg from my_customs.decorators import report_error import random from bs4 import BeautifulSoup as B from my_customs.functions import float_from_string, null_to_zero, check_if_foil, integers_from_string from tcg.tcg_functions import moose_price_algorithm import requests from time import time from engine.tcgplayer_api import TcgPlayerApi from django.core.mail import send_mail import csv api = TcgPlayerApi('moose') ''' Url function generates dynamic url based on differences in card attributes. Random number is generated to provide the 13-digit request number that Tcgplayer expects with each request. Different urls are required for Foil and Normal versions of cards. ''' def url(product_id, foil, condition, page=1): random_string = str(random.randint(1000000000000, 9999999999999)) condition = condition.replace(" ", "") url_path = { 'Normal': f'https://shop.tcgplayer.com/productcatalog/product/changepricetablepage?filterName=Condition&filterValue={condition}&productId={product_id}&' f'gameName=magic&page={page}&X-Requested-With=XMLHttpRequest&_={random_string}', 'Foil': f'https://shop.tcgplayer.com/productcatalog/product/changepricetablepage?filterName=Foil&filterValue=Foil&productId={product_id}&' f'gameName=magic&page={page}&X-Requested-With=XMLHttpRequest&_={random_string}',
from django.shortcuts import render, redirect, HttpResponseRedirect from django.http import JsonResponse from django.shortcuts import get_object_or_404, render_to_response from django.core.exceptions import ObjectDoesNotExist from django.core.serializers import serialize from datetime import datetime from .cart import Cart from .forms import contactForm, ProductForm from django.db.models import Q from .config import pagination from engine.tcgplayer_api import TcgPlayerApi from functools import reduce from operator import or_ from customer.models import ItemizedPreorder import re from decimal import Decimal from customer.tasks import send_order from ppal.paypal_api import PaypalApi from ppal.models import PaypalOrder import ast from django.urls import reverse from customer.models import Customer, PreordersReady, Preorder from .tasks import complete_order from django.core.mail import send_mail import random from rest_framework.views import APIView from rest_framework.response import Response from buylist.models import HotList tcg = TcgPlayerApi('first') paypal = PaypalApi()
from __future__ import absolute_import, unicode_literals from celery import shared_task from customer.secrets import Secrets from engine.tcgplayer_api import TcgPlayerApi from engine.tcg_credentials import Credentials from datetime import datetime from django.core.mail import send_mail from customer.models import OrderRequest tcg = TcgPlayerApi('first') credentials = Credentials() @shared_task(name='customer.tasks.send_order') def send_order(cart, name, notes, email, phone_number, contact_type): text = '' url = 'https://www.tcgfirst.com//order_view/' for each in cart: text = text + str(each['quantity']) + each['name'].replace( ' ', '+').replace("'", '%27').replace(",", '%2C') + "%0D%0A" versions = object.objects.only( 'set_name', 'name', 'tcg_player_id').filter(name__in=[i['name'] for i in cart]) ver = [{ 'name': v.name, 'set_name': v.set_name, 'qty': tcg.search_inventory(str(v.tcg_player_id), store='first') } for v in versions] new_list = sorted(cart, key=lambda k: k['set_name']) shopping_cart = [ "{}x {} ({}) | {} | ${} each | {}".format(
def clean(self): from engine.tcgplayer_api import TcgPlayerApi from decimal import Decimal from engine.models import Upload from ebay.tasks import manage_ebay from ebay.ebay_api import EbayApi from ebay.models import EbayListing api = TcgPlayerApi('first') if self.old_ebay_value is False and self.ebay is True: manage_ebay.apply_async(que='low_priority', args=( self.sku, 'upload', )) self.ebay = False elif self.old_ebay_value is True and self.ebay is False: # EbayApi().delete_ebay_item(self.sku) '''ebay_ref = EbayListing.objects.get(sku=self.sku) ebay_ref.delete()''' if self.update_inventory_price > Decimal(0): api.update_sku_price(self.sku, float(self.update_inventory_price), _json=True) self.price = self.update_inventory_price self.update_inventory_price = 0 elif self.update_inventory_price < Decimal(0): raise ValidationError( {'update_inventory_price': 'Price cannot be less than 0.'}) if self.update_inventory_quantity < 0: current_quantity = api.get_sku_quantity(self.sku, store='first') if current_quantity['errors']: raise ValidationError({ 'update_inventory_quantity': current_quantity['errors'][0] }) else: if current_quantity['results'][0][ 'quantity'] + self.update_inventory_quantity < 0: raise ValidationError({ 'update_inventory_quantity': f"Cannot remove more than {current_quantity['results'][0]['quantity']}." }) else: res = api.increment_sku_quantity( self.sku, self.update_inventory_quantity) if res['errors']: raise ValidationError( {'update_inventory_quantity': res['errors'][0]}) elif res['success']: self.quantity += self.update_inventory_quantity self.update_inventory_quantity = 0 else: raise ValidationError({ 'update_inventory_quantity': 'Unknown Error. Card may not be uploaded.' }) elif self.update_inventory_quantity > 0: res = api.increment_sku_quantity(self.sku, self.update_inventory_quantity) if res['errors']: raise ValidationError( {'update_inventory_quantity': res['errors'][0]}) elif res['success']: self.quantity += self.update_inventory_quantity self.last_upload_price = self.price self.last_upload_quantity = self.update_inventory_quantity self.last_upload_date = date.today() new_upload = Upload( sku=self.sku, upload_status=True, name=self.name, group_name=self.expansion, condition=self.condition, printing=self.printing, language=self.language, category=self.category, upload_quantity=self.update_inventory_quantity, upload_price=self.price, upload_date=date.today(), ) new_upload.save() self.update_inventory_quantity = 0 else: raise ValidationError({ 'update_inventory_quantity': 'Unknown error. Card may not have been uploaded.' })