Пример #1
0
def main():
    """
    The main method of the nuncium application will initialize the execution of
    the program. Threads will be used to query for user input. Each window has
    its own thread to manage the update of its own interface.
    """

    # UI object: The user interface of the nuncium application.
    ui = UI()

    # Integer: The height will consist of the entire screen and the width will
    #          consist of approximately 1/5 of the screen's width.
    height = curses.LINES
    width = int(curses.COLS / 5)

    # String: The default news category that is displayed on startup.
    category = "Top Stories"

    # Window object: The window that will render the menu interface.
    menu_window = ui.window(height, width)
    ui.display_menu(menu_window, category, color=curses.COLOR_BLUE)

    # Integer: The starting position in the x-coordinate of the news window will
    #          be rendered where the last window left off. The width of the news
    #          window will consist of the remaining free space.
    x = width
    width = curses.COLS - width

    # Window object: The window that will render the news content.
    news_window = ui.window(height, width, x, y=0)

    # News object: The news aggregator of the nunicum application.
    news = News()
    news.fetch_news(ui, news_window)

    ui.cursor(menu_window, x=1, y=1, y2=1, current="Top Stories")

    # Thread object: A thread used for updating the menu and news content.
    menu_thread = Thread(target=update, args=(menu_window,), daemon=True)
    news_thread = Thread(target=update, args=(news_window,), daemon=True)

    menu_thread.start()
    news_thread.start()

    # Wait for the threads to finish working.
    while running:
        pass

    ui.cleanup()
Пример #2
0
def word_frequency(query_name):
    data_container = []
    query_name = query_name
    spans = [{
        'from_parameter': '2018-01-01',
        'to': '2018-01-15'
    }, {
        'from_parameter': '2018-01-16',
        'to': '2018-01-31'
    }, {
        'from_parameter': '2018-02-01',
        'to': '2018-02-15'
    }, {
        'from_parameter': '2018-02-15',
        'to': '2018-02-28'
    }, {
        'from_parameter': '2018-03-01',
        'to': '2018-03-15'
    }, {
        'from_parameter': '2018-03-16',
        'to': '2018-03-31'
    }]
    for span in spans:
        news = News()
        data = news.fetch_news(q=query_name,
                               language='en',
                               from_parameter=span['from_parameter'],
                               to=span['to'])
        # print(data)
        analysis = news.analyze_count(data)
        data_container.append(analysis)

    wordset = set()
    combined_data_container = {}
    for analysis in data_container:
        for key in analysis.keys():
            if key in wordset:
                combined_data_container[key] = {
                    **combined_data_container[key],
                    **analysis[key]
                }
            else:
                wordset.add(key)
                combined_data_container[key] = analysis[key]

    # var trace1 = {
    #   x: [1, 2, 3, 4],
    #   y: [10, 15, 13, 17],
    #   mode: 'markers',
    #   name: 'Scatter'
    # };

    js_data_container = []
    for word in combined_data_container:
        x = list(combined_data_container[word].keys())
        x.sort()
        y = []
        for date in x:
            y.append(int(combined_data_container[word][date]))
        trace = {'x': x, 'y': y, 'name': word}
        if sum(trace['y']) > 100 and trace['name'] != query_name.lower():
            js_data_container.append(trace)

    layout = {
        'title':
        'Other Words Found in Headlines that include "{}" (2018-YTD)'.format(
            query_name),
        'xaxis': {
            'title': 'Week Number'
        },
        'yaxis': {
            'title': 'Count of Appearances in Headlines'
        }
    }

    # save raw js to the database with id=query_name above

    return [js_data_container, layout]