def amigo_init(tick, category, freq):
    # Get column name
    cname = getconf(category)
    if not cname:
        p = []
        p.append(tick)
        p.append(category)
        p.append(freq)
        writelog('[CRITICAL] No Configuration File Found', 'amigo_init', p)
        sys.exit('[CRITICAL] No Configuration File Found')
        return 1
    tname = 'amigo_' + tick + '_' + category.replace('-', '_') + '_' + freq

    # Erase WipeOut Old table
    tdrop = 'DROP TABLE IF EXISTS ' + tname
    dberase(tdrop)

    # Create table
    tcreate1 = 'CREATE TABLE ' + tname + ' ( id INT(3) UNSIGNED AUTO_INCREMENT PRIMARY KEY, '
    tcreate2 = ''
    for li in cname:
        tcreate2 = tcreate2 + str(li) + ' VARCHAR(10), '
    tcreate2 = tcreate2[:-2] + ')'
    dbquery(tcreate1 + tcreate2)
    return 0
def yql_analyst_trends_init(tick):
    d = 'DROP TABLE IF EXISTS ' + tick + '_yql_analyst_trends'
    dberase(d)

    s = 'CREATE TABLE ' + tick + '_yql_analyst_trends (id INT NOT NULL AUTO_INCREMENT, Strong_Buy VARCHAR(10), Buy VARCHAR(10), Hold VARCHAR(10), Underperform VARCHAR(10), Sell VARCHAR(10), PRIMARY KEY(id))'
    dbquery(s)
    return 0
def yql_real_init():
	# Drop Table if exists
	d = 'DROP TABLE IF EXISTS yql_real'
	dberase(d)
	# Creating new table
	s = 'CREATE TABLE yql_real (id INT NOT NULL AUTO_INCREMENT, tick VARCHAR(10), ask VARCHAR(10), bid VARCHAR(10), rchange VARCHAR(10), es VARCHAR(10), marketcap VARCHAR(20), dayr VARCHAR(10), pe VARCHAR(10), smc VARCHAR(20), PRIMARY KEY (id))'
	dbquery(s)
	return 0
Beispiel #4
0
def yql_hist_init(tick):
	dquery = 'DROP TABLE IF EXISTS ' + tick + '_hist'
	dberase(dquery)

	#create table
	cquery = 'CREATE TABLE ' + tick + '_hist (id INT NOT NULL AUTO_INCREMENT, volume VARCHAR(20), adjclose VARCHAR(10), PRIMARY  KEY (id))'
	dbquery(cquery)
	return 0
Beispiel #5
0
def yql_dividends_init():
	cn = getconf('dividends')
	if not cn:
		p = []
		writelog('[CRITICAL] No Configuration File Found', 'yql_dividends_init', p)
		sys.exit('[CRITICAL] No Configuration File Found')
		return 1
	d = 'DROP TABLE IF EXISTS yql_dividends'
	dberase(d)

	s = 'CREATE TABLE yql_dividends (id INT NOT NULL AUTO_INCREMENT, tick VARCHAR(10), '
	for ele in cn:
		s = s + ele + ' VARCHAR(25), '
	s = s[:-2] + ', PRIMARY KEY(id))'
	dbquery(s)
	return 0
def yql_estimates_init(tick):
	cn = getconf('estimates')
	if not cn:
		p = []
		p.append(tick)
		writelog('[CRITICAL] No Configuration File Found', 'yql_estimates_init', p)
		sys.exit('[CRITICAL] No Configuration File Found')
		return 1
	d = 'DROP TABLE IF EXISTS ' + tick + '_yql_estimates'
	dberase(d)

	s = 'CREATE TABLE ' + tick + '_yql_estimates (id INT NOT NULL AUTO_INCREMENT, '
	for ele in cn:
		s = s + ele + ' VARCHAR(15), '
	s = s[:-2] + ', PRIMARY KEY(id))'
	dbquery(s)
	return 0
def yql_growth_init(tick):
    cn = getconf('growth')
    if not cn:
        p = []
        p.append(tick)
        writelog('[CRITICAL] No Configuration File Found', 'yql_growth_init',
                 p)
        sys.exit('[CRITICAL] No Configuration File Found')
        return 1
    d = 'DROP TABLE IF EXISTS ' + tick + '_yql_growth'
    dberase(d)

    s = 'CREATE TABLE ' + tick + '_yql_growth (id INT NOT NULL AUTO_INCREMENT, '
    for ele in cn:
        s = s + ele + ' VARCHAR(15), '
    s = s[:-2] + ', PRIMARY KEY(id))'
    dbquery(s)
    return 0
Beispiel #8
0
def populate(list, deletet, start):
    p = []
    p.append(list)
    p.append(deletet)
    writelog('[INFO] Populating Ticklist Number :', 'populate', p)
    cname = getconf("ticklist_p" + str(list))
    if not cname:
        writelog('[CRITICAL] No Configuration File Found', 'populate', p)
        sys.exit('[CRITICAL] No Configuration File Found')

    term = "quarterly"
    ctick = ''
    rcl = []
    total = len(cname)
    counter = 0

    if (deletet == 1):
        writelog('[INFO] Dropping and Creating New Table', 'populate', p)
        s = "DROP TABLE IF EXISTS ticklist"
        dberase(s)
        s = "CREATE TABLE ticklist (id INT NOT NULL AUTO_INCREMENT, tick VARCHAR(10) NOT NULL, enabled VARCHAR(5) NOT NULL, status VARCHAR(5) NOT NULL, manual VARCHAR(5) NOT NULL, marketcap VARCHAR(20), sector VARCHAR(100), industry VARCHAR(100), errorfnc VARCHAR(200), enabledp VARCHAR(100), PRIMARY KEY(id))"
        dbquery(s)
    for tick in cname:
        counter = counter + 1
        if (counter >= start):
            outputstr = (str(counter)) + ":" + tick
            print(outputstr)
            writelog('[INFO] Progress: ' + str(counter) + ' / ' + str(total),
                     'populate', p)
            success = 0
            failure = 0
            failed_functions = []

            writelog('[INFO] Re-Initializing Tables Now......(' + tick + ')',
                     'populate', p)
            if (amigo_init(tick, "balance-sheet", term) == 0):
                tname = 'amigo_' + tick + '_' + "balance_sheet" + '_' + term
                writelog('[SUCCESS] Initialized ' + tname + ' table',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tname + ' table',
                    'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tname +
                         ' table')
            time.sleep(1)
            if (amigo_init(tick, "cash-flow", term) == 0):
                tname = 'amigo_' + tick + '_' + "cash_flow" + '_' + term
                writelog('[SUCCESS] Initialized ' + tname + ' table',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tname + ' table',
                    'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tname +
                         ' table')
            time.sleep(1)
            if (amigo_init(tick, "income-statement", term) == 0):
                tname = 'amigo_' + tick + '_' + "income_statement" + '_' + term
                writelog('[SUCCESS] Initialized ' + tname + ' table',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tname + ' table',
                    'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tname +
                         ' table')

            if (yql_analyst_trends_init(tick) == 0):
                writelog(
                    '[SUCCESS] Initialized ' + tick + '_yql_analyst_trends',
                    'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tick +
                    '_yql_analyst_trends table', 'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tick +
                         '_yql_analyst_trends table')

            if (yql_competitor_init(tick) == 0):
                writelog('[SUCCESS] Initialized ' + tick + '_yql_competitor',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tick +
                    '_yql_competitor table', 'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tick +
                         '_yql_competitor table')

            if (yql_estimates_init(tick) == 0):
                writelog('[SUCCESS] Initialized ' + tick + '_yql_estimates',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tick +
                    '_yql_estimates table', 'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tick +
                         '_yql_estimates table')

            if (yql_growth_init(tick) == 0):
                writelog('[SUCCESS] Initialized ' + tick + '_yql_growth',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tick +
                    '_yql_growth table', 'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tick +
                         '_yql_growth table')

            if (yql_hist_init(tick) == 0):
                writelog('[SUCCESS] Initialized ' + tick + '_yql_hist',
                         'populate', p)
            else:
                writelog(
                    '[CRITICAL] Unable to create database ' + tick +
                    '_yql_hist table', 'populate', p)
                sys.exit('[CRITICAL] Unable to create database ' + tick +
                         '_yql_hist table')

            writelog('[INFO] Populating Tables Now......(' + tick + ')',
                     'populate', p)

            if (amigo(tick, "balance-sheet", term, 0) == 0):
                success = success + 1
            else:
                failure = failure + 1
                ff = "amigo-balance-sheet"
                failed_functions.append(ff)

            if (amigo(tick, "cash-flow", term, 0) == 0):
                success = success + 1
            else:
                failure = failure + 1
                ff = "amigo-cash-flow"
                failed_functions.append(ff)

            if (amigo(tick, "income-statement", term, 0) == 0):
                success = success + 1
            else:
                failure = failure + 1
                ff = "amigo-income-statement"
                failed_functions.append(ff)

            if (yql_analyst_summary(tick, 0) == 0):
                success = success + 1
            else:
                failure = failure + 1
                ff = "yql_analyst_summary"
                failed_functions.append(ff)

            if (yql_analyst_trends(tick, 0) == 0):
                success = success + 1
            else:
                failure = failure + 1
                ff = "yql_analyst_trends"
                failed_functions.append(ff)

            if (yql_competitor(tick, 0) == 0):
                success = success + 1
            else:
                failure = failure + 1
                ff = "yql_competitor"
                failed_functions.append(ff)

            if (yql_day(tick, 0) == 0):
                success = success + 1
            else:
                ff = "yql_day"
                failed_functions.append(ff)

            if (yql_dividends(tick, 0) == 0):
                success = success + 1
            else:
                ff = "yql_dividends"
                failed_functions.append(ff)

            if (yql_estimates(tick, 0) == 0):
                success = success + 1
            else:
                ff = "yql_estimates"
                failed_functions.append(ff)

            if (yql_growth(tick, 0) == 0):
                success = success + 1
            else:
                ff = "yql_growth"
                failed_functions.append(ff)

            if (yql_highlight(tick, 0) == 0):
                success = success + 1
            else:
                ff = "yql_highlight"
                failed_functions.append(ff)

            writelog(
                '[INFO] Populating Database Tables Complete! ' + '(' + tick +
                ')', 'populate', p)

            # Delete Row
            dquery = 'DELETE FROM ticklist WHERE tick = \'' + tick + '\''
            dbquery(dquery)

            if (failure > 0):
                flist = functostr(failed_functions)
                wmsg = '[WARNING] Encountered Some Failures While Populating Database for ' + tick + '. \nSuccess: ' + str(
                    success) + '  Failure: ' + str(
                        failure) + '\nList of Failed Functions: ' + flist
                writelog(wmsg, 'populate', p)
                s = "INSERT INTO ticklist (tick, enabled, status, manual, errorfnc) VALUES (\'" + tick + "\', \'1\', \'1\', \'1\', \'" + flist + "\')"
            else:
                writelog(
                    '[SUCCESS] Populated Database Tables For ' + tick +
                    ' Without Error', 'populate', p)
                s = "INSERT INTO ticklist (tick, enabled, status, manual) VALUES (\'" + tick + "\', \'1\', \'0\', \'1\')"
            dbquery(s)
            time.sleep(7)
    writelog('[INFO] Finished Populating Database', 'populate', p)
    writelog('[INFO] Finished Populating Ticklist Number: ' + str(list),
             'populate', p)