diff --git a/AL.py b/AL.py index b9812d7..05706b5 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 @@ -203,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: @@ -406,6 +408,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:\nLow: {1}\nMedian: {2}\nHigh: {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)