Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions AL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -203,6 +204,7 @@ def privmsg(self, user, channel, msg):
\nsong <lastfm user>\
\nmovie <movie name>\
\nreddit <subreddit> <# of links optional>\
\nmtg <card name>\
\nor just ask me a question'
self.msg(user, help_msg)
except Exception as e:
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions apis/mtgCardRequest.py
Original file line number Diff line number Diff line change
@@ -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)