def login(): filename = os.path.expanduser('~/user.txt') fileout = [] out = [] username = '' password = '' #Check if file exists, if not, create one if not os.path.isfile(filename): print "File not found, creating file in " + filename open(filename, 'w').close() #Check if file is empty if os.stat(filename).st_size == 0: print "Empty user file, please enter your usrename and password in the file." exit() else: f = open(filename) for line in iter(f): fileout.append(line) f.close() for x in range(0, len(fileout)): out.append(fileout[x].strip()) username = out[0] password = out[1] token = moira.get_token(username, password) return token
#from googlefinance import getQuotes from bs4 import BeautifulSoup from moira import moira import re import requests import cPickle as pickle # set up moira username = '******' password = '******' game = 'moiratestone' token = moira.get_token(username, password) def makeName(inputUrl): nameRe = inputUrl.rsplit("?name=", 1)[1] nameRe = nameRe.rsplit("&p=", 1)[0] nameRe = nameRe.replace("%20", " ").replace("%3F", "?") return nameRe def makeGameName(inputUrl): nameRe = inputUrl.rsplit(".com/game/", 1)[1] nameRe = nameRe.rsplit("/portfolio/", 1)[0] # thought: I think I'm going to leave the dashes in the name, for the sake # of being able to manipulate holdings.log with better ease... return nameRe
return (strng1).replace("'", "") def buyStock(token, game, action, tickerSymbol, amt, times): print("Buying...") for x in xrange(0, times): moira.order(token, game, action, tickerSymbol, amt) print("Transaction complete.") ### MAIN FUNCTION ### # SET UP MOIRA print("Welcome to Manwholikespie's MarketWatch CLI interface.\n\n") username = raw_input("Please enter your MarketWatch email.\n > ") password = raw_input("Please enter your MarketWatch password. (Warning, not hidden)\n > ") print("Logging in...") token = moira.get_token(username, password) game = raw_input("Please enter your game id. Ex: meisenheimer\n > ") print("I'm guessing you would like to buy.") inputTicker = raw_input("Please enter the ticker symbol. Ex: AAPL\n > ") print("Searching for stock's security id.") symbol = searchStock(inputTicker) amount = raw_input("How many would you like to buy? (Beware of volume restrictions)\n > ") times = int(raw_input("How many times should this repeat?\n If only once, type 1.\n > ")) buyStock(token, game, "Buy", symbol, amount, times)