def tweetQuote(page): auth = tweepy.OAuthHandler(keys["consumer_key"], keys["consumer_secret"]) auth.set_access_token(keys["access_key"], keys["access_secret"]) api = tweepy.API(auth) quotes = QuoteModule.getQuotes(page) if not quotes: return False while (len(quotes) > 0): quotePair = quotes.pop(random.randint(0, len(quotes) - 1)) if len(quotePair) is not 2: continue try: translated = translateQuote(quotePair[0]) author = quotePair[1].split(",")[0] quote = "%s - %s" % (translated, author) api.update_status(quote) print "tweeted: %s" % quote except tweepy.TweepError as e: # dont stop if duplicate status happens print "TweepError: %s" % e continue except Exception as e: print "Error: %s" % e continue # tweet again in 20 min time.sleep(60 * 20) return True
def test_quotes(): status, ofxFile1, ofxFile2, htmFile = quotes.getQuotes() if status: print 'Download completed successfully\n\n' ask = raw_input('Open <Quotes.htm> in the default browser (y/n)?').upper() if ask=='Y': os.startfile(htmFile) #don't wait for browser close ask = raw_input('Send the results to Money (y/n)? ').upper() if ask=='Y': if ofxFile2 <> '': rlib1.runFile(ofxFile2) if Debug: raw_input('\nPress <Enter> to send ForceQuotes statement.') time.sleep(0.5) #slight delay, to force load order in Money rlib1.runFile(ofxFile1) raw_input('Press Enter to continue...') else: print 'An error occurred while testing Stock/Fund quotes.'
if QEntry == 'Accts': if len(AcctArray) == 0: print "No accounts have been configured. Run SETUP.PY to add accounts" #process accounts for acct in AcctArray: status, ofxFile = ofx.getOFX(acct, interval) #status == False if ofxFile doesn't exist stat1 = stat1 and status if status: ofxList.append([acct[0], acct[1], ofxFile]) print "" #get stock/fund quotes if QEntry == 'Quotes' and getquotes: status, quoteFile1, quoteFile2, htmFileName = quotes.getQuotes() z = ['Stock/Fund Quotes','',quoteFile1] stat1 = stat1 and status if glob.glob(quoteFile1) <> []: ofxList.append(z) print "" # display the HTML file after download if requested to always do so if status and userdat.showquotehtm: os.startfile(htmFileName) if len(ofxList) > 0: print '\nFinished downloading data\n' verify = False gogo = 'Y' if userdat.combineofx and gogo <> 'V': cfile=combineOfx(ofxList) #create combined file
with open(f) as ifile: ofx = ifile.read() p = re.compile(r'NEWFILEUID:.*') ofx2 = p.sub('NEWFILEUID:PSIMPORT', ofx) if ofx2: with open(f, 'w') as ofile: ofile.write(ofx2) #preserve origina file type but save w/ ofx extension outname = xfrdir + fname + ('' if bext == '.ofx' else '.ofx') os.rename(f, outname) ofxList.append(['import file', '', outname]) #get stock/fund quotes if QEntry == 'Quotes' and getquotes: status, quoteFile1, quoteFile2, htmFileName = quotes.getQuotes( ) z = ['Stock/Fund Quotes', '', quoteFile1] stat1 = stat1 and status if glob.glob(quoteFile1) != []: ofxList.append(z) print("") # display the HTML file after download if requested to always do so if status and userdat.showquotehtm: os.startfile(htmFileName) if len(ofxList) > 0: print('\nFinished downloading data\n') verify = False gogo = 'Y' if userdat.combineofx and gogo != 'V': cfile = combineOfx(ofxList) #create combined file