Exemple #1
0
    def test_sort_results(self):
        tester_data = {
            "url": ["content", "url", "title", "article body", 5, .5, 'pos']
        }
        expected = ({
            "url": ["content", "url", "title"]
        }, {}, [], ['url'], 0, 1, 0)

        self.assertEqual(sort_results(tester_data), expected)
Exemple #2
0
def search_results():
    """Renders page with results of search and sentiment analysis."""
    # Grabs the search item with a get request.
    search = request.args.get("search")

    try:
        # Querys my database for the search company's object.
        company = NASDAQNYSE.query.filter(
            NASDAQNYSE.company_name == search).first()
        ticker = company.ticker_code
        # Grabs even more information about the company from the database.
        company_name, industry, sector, ticker = get_company_info(search)

        # Stores the ticker code in the session.
        session['symbol'] = ticker

        # Gets the current date and time
        d = datetime.now()
        now = d.strftime("%c")

        # Runs the search value through the functions (google API, web scraper, sentiment analysis API)
        news_w_sent = process_funcs(search)

        # Unpacks the results from the function that sorts the results of the functions above for passing.
        neg_results, pos_results, positive_values, negative_values, a, b, c = sort_results(
            news_w_sent)

        # Grabs today's date and the date of 10 days ago.
        today_date, last_10_date = get_date_range()

        stock_history = get_historical_prices()

        return render_template("results.html",
                               neg_results=neg_results,
                               pos_results=pos_results,
                               positive_values=positive_values,
                               negative_values=negative_values,
                               a=a,
                               b=b,
                               c=c,
                               ticker=ticker,
                               company_name=company_name,
                               industry=industry,
                               sector=sector,
                               stock_history=stock_history,
                               now=now)
    except AttributeError:
        return render_template("error.html")
def search_results():
    """Renders page with results of search and sentiment analysis."""
    # Grabs the search item with a get request.
    search = request.args.get("search")

    try:
        # Querys my database for the search company's object.
        company = NASDAQNYSE.query.filter(NASDAQNYSE.company_name == search).first()
        ticker = company.ticker_code
        # Grabs even more information about the company from the database.
        company_name, industry, sector, ticker = get_company_info(search)

        # Stores the ticker code in the session.
        session['symbol'] = ticker

        # Gets the current date and time
        d = datetime.now()
        now = d.strftime("%c")

        # Runs the search value through the functions (google API, web scraper, sentiment analysis API)
        news_w_sent = process_funcs(search)

        # Unpacks the results from the function that sorts the results of the functions above for passing.
        neg_results, pos_results, positive_values, negative_values, a, b, c = sort_results(news_w_sent)

        # Grabs today's date and the date of 10 days ago. 
        today_date, last_10_date = get_date_range()

        stock_history = get_historical_prices()


        return render_template("results.html", neg_results=neg_results,
                               pos_results=pos_results, positive_values=positive_values,
                               negative_values=negative_values, a=a, b=b, c=c,
                               ticker=ticker, company_name=company_name, industry=industry, 
                               sector=sector, stock_history=stock_history, now=now)
    except AttributeError:
        return render_template("error.html")    
Exemple #4
0
def get_comparison_results():
    """Shows results of company comparison"""
    try:
        firstsearch = request.args.get("firstcompany")
        secondsearch = request.args.get("secondcompany")

        firstcompany = NASDAQNYSE.query.filter(
            NASDAQNYSE.company_name == firstsearch).first()
        secondcompany = NASDAQNYSE.query.filter(
            NASDAQNYSE.company_name == secondsearch).first()

        first_company_name, first_industry, first_sector, tickerone = get_company_info(
            firstsearch)
        session['symbolone'] = tickerone

        second_company_name, second_industry, second_sector, tickertwo = get_company_info(
            secondsearch)
        session['symboltwo'] = tickertwo

        d = datetime.now()
        now = d.strftime("%c")

        first_news_w_sent = process_funcs(firstsearch)

        first_neg_results, first_pos_results, first_positive_values, first_negative_values, a1, b1, c1 = sort_results(
            first_news_w_sent)

        second_news_w_sent = process_funcs(secondsearch)

        second_neg_results, second_pos_results, second_positive_values, second_negative_values, a2, b2, c2 = sort_results(
            second_news_w_sent)

        return render_template("comparisonresults.html",
                               first_neg_results=first_neg_results,
                               first_pos_results=first_pos_results,
                               first_positive_values=first_positive_values,
                               first_negative_values=first_negative_values,
                               a1=a1,
                               b1=b1,
                               c1=c1,
                               tickerone=tickerone,
                               first_company_name=first_company_name,
                               first_industry=first_industry,
                               first_sector=first_sector,
                               second_neg_results=second_neg_results,
                               second_pos_results=second_pos_results,
                               second_positive_values=second_positive_values,
                               second_negative_values=second_negative_values,
                               a2=a2,
                               b2=b2,
                               c2=c2,
                               tickertwo=tickertwo,
                               second_company_name=second_company_name,
                               second_industry=second_industry,
                               second_sector=second_sector,
                               now=now)

    except AttributeError:
        return render_template("error.html")
Exemple #5
0
    def test_sort_results(self):
        tester_data = {"url" : ["content", "url", "title", "article body", 5, .5, 'pos']}
        expected = ({"url": ["content", "url", "title"]}, {}, [], ['url'], 0, 1, 0)

        self.assertEqual(sort_results(tester_data), expected)
def get_comparison_results():
    """Shows results of company comparison"""
    try:
        firstsearch = request.args.get("firstcompany")
        secondsearch = request.args.get("secondcompany")

        firstcompany = NASDAQNYSE.query.filter(NASDAQNYSE.company_name == firstsearch).first()
        secondcompany = NASDAQNYSE.query.filter(NASDAQNYSE.company_name == secondsearch).first()

        first_company_name, first_industry, first_sector, tickerone = get_company_info(firstsearch)
        session['symbolone'] = tickerone

        second_company_name, second_industry, second_sector, tickertwo = get_company_info(secondsearch)
        session['symboltwo'] = tickertwo

        d = datetime.now()
        now = d.strftime("%c")

        first_news_w_sent = process_funcs(firstsearch)

        first_neg_results, first_pos_results, first_positive_values, first_negative_values, a1, b1, c1 = sort_results(first_news_w_sent)

        second_news_w_sent = process_funcs(secondsearch)

        second_neg_results, second_pos_results, second_positive_values, second_negative_values, a2, b2, c2 = sort_results(second_news_w_sent)

        return render_template("comparisonresults.html", first_neg_results=first_neg_results,
                               first_pos_results=first_pos_results, first_positive_values=first_positive_values,
                               first_negative_values=first_negative_values, 
                               a1=a1, b1=b1, c1=c1,
                               tickerone=tickerone, first_company_name=first_company_name, first_industry=first_industry,
                               first_sector=first_sector, 
                               second_neg_results=second_neg_results,
                               second_pos_results=second_pos_results, second_positive_values=second_positive_values,
                               second_negative_values=second_negative_values, 
                               a2=a2, b2=b2, c2=c2,
                               tickertwo=tickertwo, second_company_name=second_company_name, second_industry=second_industry,
                               second_sector=second_sector, now=now)

    except AttributeError:
        return render_template("error.html")