From 4467d830a99d49588488f111ec858fc5ae5dbaba Mon Sep 17 00:00:00 2001 From: houston Date: Thu, 31 Oct 2013 15:59:32 -0600 Subject: [PATCH 1/2] MtG prices working --- AL.py | 16 ++++++++++++++++ apis/mtgCardRequest.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 apis/mtgCardRequest.py diff --git a/AL.py b/AL.py index b9812d7..2c2fd8d 100644 --- a/AL.py +++ b/AL.py @@ -36,6 +36,7 @@ from apis.lastfm import getCurrentSong from apis.rottentomatoes import rottentomatoes from apis.reddit import getSubReddit, getQuote +from apis.mtgCardRequest import mtgCardRequest from random import randint import ConfigParser import json @@ -406,6 +407,21 @@ def privmsg(self, user, channel, msg): except: self.logError(channel) + elif parts[1] == 'mtg': + try: + + cardname = ' '.join( parts[2:]) + price_response = mtgCardRequest(cardname) + if price_response: + price_response_msg = 'The Prices for {0} are {1}, {2}, {3}'.format( + cardname, + price_response['Low'], + price_response['Median'], + price_response['High']) + self.msg(channel, price_response_msg) + except Exception as e: + self.logError(channel) + #========================================================================================== # ---------- IF NOT ONE OF THE SPECIAL COMMANDS ABOVE ASK WOLFRAM diff --git a/apis/mtgCardRequest.py b/apis/mtgCardRequest.py new file mode 100644 index 0000000..8587828 --- /dev/null +++ b/apis/mtgCardRequest.py @@ -0,0 +1,28 @@ +def mtgCardRequest(cardname): + + import requests + import json + + #TCGplayer, this gives 3 outputs. Low, Median, High + tcgplayer_response = requests.get('http://magictcgprices.appspot.com/api/tcgplayer/price.json?cardname=%s' % (cardname)) + tcg_data = json.loads(tcgplayer_response.text) + + #set variable for each different api location + tcg_low = tcg_data[0] + tcg_mid = tcg_data[1] + tcg_high = tcg_data[2] + + all_prices = { + 'Low' : tcg_low, + 'Median' : tcg_mid, + 'High' : tcg_high + } + + return all_prices + +if __name__ == "__main__": + import sys + # cardname = sys.argv[1] + # cardset = sys.argv[2] + cardname = raw_input("What card do you want? ") + print mtgCardRequest(cardname) From 1dfe448ca57c28fe85d6b5d75b60fb5cbc68726d Mon Sep 17 00:00:00 2001 From: houston Date: Thu, 31 Oct 2013 16:27:20 -0600 Subject: [PATCH 2/2] Formatting and Help update --- AL.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AL.py b/AL.py index 2c2fd8d..05706b5 100644 --- a/AL.py +++ b/AL.py @@ -204,6 +204,7 @@ def privmsg(self, user, channel, msg): \nsong \ \nmovie \ \nreddit <# of links optional>\ + \nmtg \ \nor just ask me a question' self.msg(user, help_msg) except Exception as e: @@ -413,7 +414,7 @@ def privmsg(self, user, channel, msg): cardname = ' '.join( parts[2:]) price_response = mtgCardRequest(cardname) if price_response: - price_response_msg = 'The Prices for {0} are {1}, {2}, {3}'.format( + price_response_msg = 'The prices for {0} are:\nLow: {1}\nMedian: {2}\nHigh: {3}'.format( cardname, price_response['Low'], price_response['Median'],