Example #1
0
def updateTrend(cardId):
    print('running updateTrend for', cardId)
    try:
        con = sql.connect(dbLoc)
        con.row_factory = sql.Row
        cur = con.cursor()
        print('connected to db')
    except:
        print('couldnt connect to db')

    try:
        valueIndicator = ""
        valueIndicator = cardAverage.weekMonth(cardId)[2]
        print('collected cardAverage')
    except:
        print('could not perform cardAverage')
    # insert to watchlist
    try:
        cur.execute(
            "INSERT or replace into watchlist (ID, PRICEDIRECTION) values (?, ?)",
            (
                cardId,
                valueIndicator,
            ))
        con.commit()
        con.close()
    except:
        print('could not update card with updateTrend')
        con.close()
Example #2
0
def searchID(cardId, chartID='chart_ID2', chart_type='line', chart_height=500):
    # the search bar results for the layout html
    if request.method == "GET":
        print('search cardID get request')
        con = sql.connect(dbLoc)
        con.row_factory = sql.Row
        cur = con.cursor()

        # initializing my variables
        priceList = []
        dateList = []
        imageUrl = ""
        sameCards = []
        setCodes = []
        duplicate_names = []
        cardInfo = {}
        cardName = ""

        # selects name and set of the card
        try:
            for x in cur.execute(
                    "select NAME, CARDSET from CARDS where ID=(?)",
                (cardId, )):
                print('the name is:', x[0])
                print('the set is:', x[1])
                cardName = x[0]
                setCodes.append(x[1])
        except:
            print('I couldnt get the card name')
        try:
            price_now = recent_price(cardId)
        except:
            print('could not get price today')

        # select ids of all reprints
        print('card im looking up:', cardId)
        try:
            for x in cur.execute(
                    """select id, 
            cardset, 
            picurl
            from cards 
            where name = (?) 
            and cards.ONLINEONLY != 'True'""", (cardName, )):
                try:
                    sameCards.append(x[0])
                except:
                    print('could not append samecards in sameName')
                try:
                    price = recent_price(x[0])
                    duplicate_names.append([x[0], x[1], x[2], price])
                except:
                    print('could not append duplicate_names in sameName')

                print("i found an ID")
                print("x 0:", x[0])
                print("x 1:", x[1])
            print('duplicate_names:', duplicate_names)
        except:
            print('I couldn\'t select the ids for samecards')

        try:
            print('running searchCard')
            imageUrl = searchCard(cardId, cur, priceList, dateList, imageUrl)
            print('prices:', priceList)
            print('dates:', dateList)
            data = [list(x) for x in zip(dateList, priceList)]
        except:
            print('cant perform searchcard')
        try:
            cur.execute(
                "select cards.cmc, type, power, toughness, rarity, cardset from cards where cards.id == ((?))",
                (cardId, ))
            fetchInfo = cur.fetchone()
        except:
            print('could not perform id sql search')

        for value in fetchInfo:
            print('value: ', value)
        try:
            cardInfo['cmc'] = fetchInfo['cmc']
            cardInfo['type'] = fetchInfo['type']
            cardInfo['power'] = fetchInfo['power']
            cardInfo['toughness'] = fetchInfo['toughness']
            cardInfo['rarity'] = fetchInfo['rarity']
            cardInfo['buylist'] = 'N/A'
            cardInfo['cardset'] = fetchInfo['cardset']
            cardInfo['cardname'] = cardName
        except:
            print('could not add values to cardInfo dictionary')

        try:
            cur.execute('select name from cardset where code = (?)',
                        (cardInfo['cardset'], ))
            cardInfo['setname'] = cur.fetchone()[0]
            print(cardInfo['setname'])
        except:
            print('could not grab set name')

        print('the card cmc value:', cardInfo['cmc'])
        print('search value:', cardInfo['type'])
        print('power:', cardInfo['power'])

        con.close()
        # supposed to change data input

        # chart data routed to javascript
        chart = {
            "renderTo": chartID,
            "type": chart_type,
            "height": chart_height,
            "zoomType": 'x',
            "backgroundColor": "#f5f5f5"
        }
        series = [{"name": 'series label', "data": data}]
        title = {"text": ' '}
        xAxis = {"type": "datetime"}
        yAxis = {"title": {"text": 'yax'}}
        pageType = 'graph'

        # I need to insert credits and any other variables into the html of the charts
        return render_template("resultsLayout.html",
                               pageType=pageType,
                               chartID=chartID,
                               chart=chart,
                               series=series,
                               title=title,
                               xAxis=xAxis,
                               yAxis=yAxis,
                               imageUrl=imageUrl,
                               sameCards=sameCards,
                               setCodes=setCodes,
                               cardId=cardId,
                               sameCardsCombo=duplicate_names,
                               cardInfo=cardInfo,
                               card_names=card_names,
                               price_now=price_now)

    elif request.method == "POST":
        # post means i'm adding a card to the watchlist
        print('the request was post')

        con = sql.connect(dbLoc)
        cur = con.cursor()

        valueIndicator = cardAverage.weekMonth(cardId)[2]
        try:
            cur.execute(
                "INSERT or replace into watchlist (ID, PRICEDIRECTION) values (?, ?)",
                (
                    cardId,
                    valueIndicator,
                ))
            con.commit()
        except:
            print('could not insert card')
        con.close()
        rows = getWatchList()

        return render_template("watchlistLayout.html",
                               rows=rows,
                               card_names=card_names)
Example #3
0
def watchlist():

    if request.method == 'GET':
        print('watchlist get request')
        rows = getWatchList()

        return render_template("watchlistLayout.html",
                               rows=rows,
                               card_names=card_names)

    # post to insert
    elif request.form.get('removeCard') == None:
        print('/watchlist post request insert')
        con = sql.connect(dbLoc)
        con.row_factory = sql.Row
        cur = con.cursor()
        # this is the name from html
        r = (request.form['watchlist'])

        cardId = ""
        valueIndicator = ""

        # card ID fetching
        # selects first available ID where id's len is 3
        try:
            for cardIdNum in cur.execute(
                    """select ID 
            from CARDS 
            where UPPER(NAME)=UPPER((?)) 
            and cards.ONLINEONLY != 'True' 
            and length(cardset)=3 
            and nonfoil = 'True'""", (r, )):
                cardId = cardIdNum[0]
        except:
            print('could not find card')

        # the cardAverage week/month for the searched card
        valueIndicator = cardAverage.weekMonth(cardId)[2]

        # insert to watchlist
        try:
            cur.execute(
                "INSERT or replace into watchlist (ID, PRICEDIRECTION) values (?, ?)",
                (
                    cardId,
                    valueIndicator,
                ))
            con.commit()
        except:
            print('could not insert card')
        con.close()

        rows = getWatchList()

        return render_template("watchlistLayout.html",
                               rows=rows,
                               card_names=card_names)

    # post request to remove card from list
    else:
        print("remove card post request")
        con = sql.connect(dbLoc)
        cur = con.cursor()
        cardID = request.form.get('removeCard')

        try:
            cur.execute("delete from watchlist where ID=(?)", (cardID, ))
            print('removed ', cardID, ' from watchlist')
        except:
            print('could not remove card from watchlist')
        con.commit()
        con.close()

        rows = getWatchList()

        return render_template("watchlistLayout.html",
                               rows=rows,
                               card_names=card_names)