Example #1
0
def QuoteHTMwriter(qList):
    # Write quotes.htm containing quote data contained in quote list (qList)
    # Supports Yahoo! finance links
    # See quotes.py for qList structure
    global userdat
    
    userdat = site_cfg.site_cfg()
    
    # CREATE FILE
    filename = xfrdir + "quotes.htm"
    fullpath = '"' + os.path.realpath(filename) + '"'   #encapsulate spaces
    
    f = open(filename,"w")
    print "Writing", filename
    
    # Write HEADER
    _QHTMheader(f)
    
    # Write BODY
    shade = False
    for quote in qList:
        _QHTMrow(f, quote, shade)
        shade = not shade
    
    # Write FOOTER
    _QHTMfooter(f)
    
    f.close()
    
    return fullpath
Example #2
0
def QuoteHTMwriter(qList):
    # Write quotes.htm containing quote data contained in quote list (qList)
    # Supports Yahoo! finance links
    # See quotes.py for qList structure
    global userdat

    userdat = site_cfg.site_cfg()

    # CREATE FILE
    filename = xfrdir + "quotes.htm"
    fullpath = '"' + os.path.realpath(filename) + '"'  #encapsulate spaces

    f = open(filename, "w")
    print("Writing", filename)

    # Write HEADER
    _QHTMheader(f)

    # Write BODY
    shade = False
    for quote in qList:
        _QHTMrow(f, quote, shade)
        shade = not shade

    # Write FOOTER
    _QHTMfooter(f)

    f.close()

    return fullpath
Example #3
0
import ofx, quotes, site_cfg
from control2 import *
from rlib1 import *

if __name__=="__main__":

    stat1 = True    #overall status flag across all operations (true == no errors getting data)
    print AboutTitle + ", Ver: " + AboutVersion + "\n"
    
    if Debug: print "***Running in DEBUG mode.  See Control2.py to disable***\n"
    doit = raw_input("Download transactions? (Y/N/I=Interactive) [Y] ").upper()
    if len(doit) > 1: doit = doit[:1]    #keep first letter
    if doit == '': doit = 'Y'
    if doit in "YI":

        userdat = site_cfg.site_cfg()
        
        #get download interval, if promptInterval=Yes in sites.dat
        interval = userdat.defaultInterval
        if userdat.promptInterval:
            try:
                p = int2(raw_input("Download interval (days) [" + str(interval) + "]: "))
                if p>0: interval = p
            except:
                print "Invalid entry. Using defaultInterval=" + str(interval)
        
        #get account info
        #AcctArray = [['SiteName', 'Account#', 'AcctType', 'UserName', 'PassWord'], ...]
        pwkey, getquotes, AcctArray = get_cfg()
        ofxList = []
        quoteFile1, quoteFile2, htmFileName = '','',''
Example #4
0
#----------------------------------------------------------------------------------------
if __name__ == "__main__":

    print(AboutTitle + ", Ver: " + AboutVersion + "\n")
    if Debug: print('\n  **DEBUG MODE**')

    #keep a backup copy of the sites.dat file
    backup = True
    if glob.glob('sites.dat') != []:
        if glob.glob('sites.bak') != []:
            if filecmp.cmp('sites.bak', 'sites.dat'): backup = False
        if backup: shutil.copy('sites.dat', 'sites.bak')

    #get the user parameters
    userdat = site_cfg.site_cfg()
    Sites = userdat.sites

    #build a Sitenames list one time
    Sitenames = []  #Sitenames array
    for site in Sites:
        Sitenames.append(site)

    Sitenames.sort()

    #do we already have a configuration file?  if so, read it in.
    pwkey, c_getquotes, AcctArray = rlib1.get_cfg()

    #is the file password protected?  If so, we need to get passkey and decrypt the account info
    if len(pwkey):
        pwkey = rlib1.decrypt_pw(pwkey)
Example #5
0
def getQuotes():

    global YahooURL, eYahoo, eYScrape, GoogleURL, eGoogle, YahooTimeZone
    status = True  #overall status flag across all operations (true == no errors getting data)

    #get site and other user-defined data
    userdat = site_cfg.site_cfg()
    stocks = userdat.stocks
    funds = userdat.funds
    eYahoo = userdat.enableYahooFinance
    YahooURL = userdat.YahooURL
    GoogleURL = userdat.GoogleURL
    eYScrape = userdat.enableYahooScrape
    eGoogle = userdat.enableGoogleFinance
    YahooTimeZone = userdat.YahooTimeZone
    currency = userdat.quotecurrency
    account = userdat.quoteAccount
    ofxFile1, ofxFile2, htmFileName = '', '', ''

    stockList = []
    print "Getting security and fund quotes..."
    for item in stocks:
        sec = Security(item)
        sec.getQuote()
        status = status and sec.status
        if sec.status: stockList.append(sec)

    mfList = []
    for item in funds:
        sec = Security(item)
        sec.getQuote()
        status = status and sec.status
        if sec.status: mfList.append(sec)

    qList = stockList + mfList

    if len(qList) > 0:  #write results only if we have some data
        #create quotes ofx file
        if not os.path.exists(xfrdir):
            os.mkdir(xfrdir)

        ofxFile1 = xfrdir + "quotes" + OfxDate() + str(
            random.randrange(1e5, 1e6)) + ".ofx"
        writer = OfxWriter(currency, account, 0, stockList, mfList)
        writer.writeFile(ofxFile1)

        if userdat.forceQuotes:
            #generate a second file with non-zero shares.  Getdata and Setup use this file
            #to force quote reconciliation in Money, by sending ofxFile2, and then ofxFile1
            ofxFile2 = xfrdir + "quotes" + OfxDate() + str(
                random.randrange(1e5, 1e6)) + ".ofx"
            writer = OfxWriter(currency, account, 0.001, stockList, mfList)
            writer.writeFile(ofxFile2)

        if glob.glob(ofxFile1) == []:
            status = False

        # write quotes.htm file
        htmFileName = QuoteHTMwriter(qList)

        #append results to QuoteHistory.csv if enabled
        if status and userdat.savequotehistory:
            csvFile = xfrdir + "QuoteHistory.csv"
            print "Appending quote results to {0}...".format(csvFile)
            newfile = (glob.glob(csvFile) == [])
            f = open(csvFile, "a")
            if newfile:
                f.write('Symbol,Name,Price,Date/Time,LastClose,%Change\n')
            for s in qList:
                #Fieldnames: symbol, name, price, quoteTime, pclose, pchange
                t = s.quoteTime
                t2 = t[4:6] + '/' + t[6:8] + '/' + t[0:4] + ' ' + t[
                    8:10] + ":" + t[10:12] + ":" + t[12:14]
                line = '"{0}","{1}",{2},{3},{4},{5}\n' \
                        .format(s.symbol, s.name, s.price, t2, s.pclose, s.pchange)
                f.write(line)
            f.close()

    return status, ofxFile1, ofxFile2, htmFileName
Example #6
0
def getQuotes():

    global YahooURL, eYahoo, eYScrape, GoogleURL, eGoogle, YahooTimeZone
    status = True    #overall status flag across all operations (true == no errors getting data)
    
    #get site and other user-defined data
    userdat = site_cfg.site_cfg()
    stocks = userdat.stocks
    funds = userdat.funds
    eYahoo = userdat.enableYahooFinance
    YahooURL = userdat.YahooURL
    GoogleURL = userdat.GoogleURL
    eYScrape = userdat.enableYahooScrape
    eGoogle = userdat.enableGoogleFinance
    YahooTimeZone = userdat.YahooTimeZone
    currency = userdat.quotecurrency
    account = userdat.quoteAccount
    ofxFile1, ofxFile2, htmFileName = '','',''
    
    stockList = []
    print "Getting security and fund quotes..."
    for item in stocks:
        sec = Security(item)
        sec.getQuote()
        status = status and sec.status
        if sec.status: stockList.append(sec)
        
    mfList = []
    for item in funds:
        sec = Security(item)
        sec.getQuote()
        status = status and sec.status
        if sec.status: mfList.append(sec)
        
    qList = stockList + mfList
    
    if len(qList) > 0:        #write results only if we have some data
        #create quotes ofx file  
        if not os.path.exists(xfrdir):
            os.mkdir(xfrdir)
        
        ofxFile1 = xfrdir + "quotes" + OfxDate() + str(random.randrange(1e5,1e6)) + ".ofx"
        writer = OfxWriter(currency, account, 0, stockList, mfList)
        writer.writeFile(ofxFile1)

        if userdat.forceQuotes:
           #generate a second file with non-zero shares.  Getdata and Setup use this file
           #to force quote reconciliation in Money, by sending ofxFile2, and then ofxFile1
           ofxFile2 = xfrdir + "quotes" + OfxDate() + str(random.randrange(1e5,1e6)) + ".ofx"
           writer = OfxWriter(currency, account, 0.001, stockList, mfList)
           writer.writeFile(ofxFile2)
        
        if glob.glob(ofxFile1) == []:
            status = False

        # write quotes.htm file
        htmFileName = QuoteHTMwriter(qList)
        
        #append results to QuoteHistory.csv if enabled
        if status and userdat.savequotehistory:
            csvFile = xfrdir+"QuoteHistory.csv"
            print "Appending quote results to {0}...".format(csvFile)
            newfile = (glob.glob(csvFile) == [])
            f = open(csvFile,"a")
            if newfile:
                f.write('Symbol,Name,Price,Date/Time,LastClose,%Change\n')
            for s in qList:
                #Fieldnames: symbol, name, price, quoteTime, pclose, pchange
                t = s.quoteTime
                t2 = t[4:6]+'/'+t[6:8]+'/'+t[0:4]+' '+ t[8:10]+":"+t[10:12]+":"+t[12:14]
                line = '"{0}","{1}",{2},{3},{4},{5}\n' \
                        .format(s.symbol, s.name, s.price, t2, s.pclose, s.pchange)
                f.write(line)
            f.close()
        
    return status, ofxFile1, ofxFile2, htmFileName