Пример #1
0
def article_from_csv():

    with open('Scrader4.csv') as csvfile:
        reader = csv.DictReader(csvfile)
        for article in reader:
            new_article = {}
            new_article['title'] = article.get('Title')
            new_article['image_url'] = article.get('Image')
            new_article['subtitle'] = article.get('Date')
            new_article['item_url'] = article.get('Article')
            new_article['direction'] = article.get('Sentiment')
            new_article['company'] = article.get('Company')
            new_article['website'] = article.get('Website')
            new_article['website_url'] = article.get('Website url')
            new_article['false_estims'] = 0
            mongo.insert_one('articles', new_article)
Пример #2
0
def article_from_excel():

    from xlrd import open_workbook
    book = open_workbook('Scrader-Sample_1-12.xlsx')
    sheet = book.sheet_by_index(0)
    keys = dict((i, sheet.cell_value(0, i)) for i in range(sheet.ncols))
    articles = (dict((keys[j], sheet.cell_value(i, j)) for j in keys) for i in range(1, sheet.nrows))
    mongo.delete_many('articles')
    for article in articles:
        new_article = {}
        new_article['title'] = article.get('Title')
        new_article['image_url'] = article.get('image url')
        new_article['subtitle'] = '10/5/2017'
        new_article['item_url'] = article.get('URL')
        new_article['direction'] = article.get('Sentiment')
        new_article['company'] = article.get('Company')
        new_article['website'] = article.get('Website')
        new_article['website_url'] = article.get('Website url')
        new_article['false_estims'] = 0
        mongo.insert_one('articles', new_article)
Пример #3
0
def user_login(user_id, user_name, last_name):
    """ GET Server Status API endpoint
        Args:
        Returns:
            dict: A JSON object containing the nfvacc server status information
    """
    LOG.info("Hi from {}".format(socket.gethostname()))
    # name = user_name
    registered = False
    first_time = True

    user = mongo.find_one_match('users', {"user_id": user_id})
    if user is not None:
        first_time = False
        first_name = user.get('first_name')
        if user.get('subscribed'):
            registered = True
    else:
        user_dict = {
            'first_name': user_name,
            'last_name': last_name,
            'subscribed': False,
            'user_id': user_id
        }
        mongo.insert_one('users', user_dict)

    buttons = []
    init_message = ''
    if first_time:
        # init_message = 'Hi!Nice to meet you ....! ' \
        #                'Yes, I am just a machine, ' \
        #                'but I can show you news from listed companies daily...' \
        #                'I can even decide which news are bad news!'

        message = 'Let the magic begin! Pick one of the options ' \
                  'below or simply type any a listed company name.'

        button_title = 'Notifications'
        button_dict_tmpl = {
            "type": "web_url",
            "url": "{}/scrader/companies/{}".format(Server_url, user_id),
            "title": button_title
        }

        buttons.append(button_dict_tmpl)
        block = 'Initializition'
        button_title = 'I am just a guest'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)
    else:
        block = 'Companies'
        button_title = 'Good/Neutral News'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)

        block = 'Companies'
        button_title = 'Bad News'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)

        if registered:
            # message = 'Hi again {}. What would you like me to show you? ' \
            #           'Remember you can type any company you want to search for scraped news'.\
            #           format(first_name)

            message = 'Welcome back {}! ' \
                      'Hungry for more news? '\
                      'Just pick one of the options below or type ' \
                      'a listed company name for our full relevant articles archive.'.format(
                          first_name)

            notifications_button = {
                "type": "web_url",
                "url": "{}/scrader/companies/{}".format(Server_url, user_id),
                "title": "Edit Notifications"
            }
            buttons.append(notifications_button)
        else:
            # message = 'Hi again {}. What would you like me to show you? ' \
            #           'Remember you can type any company you want to search for scraped news'.\
            #           format(name)
            message = 'Welcome back {}! ' \
                      'Hungry for more news? '\
                      'Just pick one of the options below or type ' \
                      'a listed company name for our full relevant articles archive.'.format(
                          first_name)
            notifications_button = {
                "type": "web_url",
                "url": "{}/scrader/companies/{}".format(Server_url, user_id),
                "title": "Notifications"
            }
            buttons.append(notifications_button)
    if init_message != '':
        response_data = {
            "messages": [{
                'text': init_message
            }, {
                "attachment": {
                    "type": "template",
                    "payload": {
                        "template_type": "button",
                        "text": message,
                        "buttons": buttons
                    }
                }
            }]
        }
    else:
        response_data = {
            "messages": [{
                "attachment": {
                    "type": "template",
                    "payload": {
                        "template_type": "button",
                        "text": message,
                        "buttons": buttons
                    }
                }
            }]
        }

    # print(response_data)
    status = 200 if response_data is not None else 403
    js = json.dumps(response_data, indent=2)
    return flask.Response(js, status=status, mimetype='application/json')
Пример #4
0
def user_login(user_id, user_name):
    """ GET Server Status API endpoint
        Args:
        Returns:
            dict: A JSON object containing the nfvacc server status information
    """
    name = user_name
    registered = False
    first_time = True

    user = mongo.find_one_match('users', {"user_id": user_id})
    if user is not None:
        first_time = False
        first_name = user.get('first_name')
        if user.get('subscribed'):
            registered = True
    else:
        user_dict = {
            'first_name': user_name,
            'subscribed': False,
            'user_id': user_id
        }
        mongo.insert_one('users', user_dict)

    buttons = []

    if first_time:
        # print('first time loging in')
        message = 'Hi {}! Nice to see you. ' \
                  'I am the Scrader Bot. ' \
                  'My job is to utilize powerful machine ' \
                  'learning algorithms to extract the latest company ' \
                  'insights from news articles for a valuable ' \
                  'head start in your trading strategy. ' \
                  'I am still in development mode so many functions are not stable just yet. ' \
                  'Please subscribe in order to get notified when I will be fully functional'.format(name)

        block = 'Subscribe'
        button_title = 'Subscribe'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)
        block = 'Initializition'
        button_title = 'I am just a guest'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)
    else:
        block = 'Companies'
        button_title = 'Positive News'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)

        block = 'Companies'
        button_title = 'Negative News'
        button_dict_tmpl = {
            "type": "show_block",
            "block_name": block,
            "title": button_title
        }
        buttons.append(button_dict_tmpl)

        if registered:
            message = 'Hi again {}. What would you like me to show you? ' \
                      'Remember you can type any company you want to search for scraped news'.format(first_name)

            pref_button = {
                "type": "show_block",
                "block_name": "Preferences",
                "title": "Edit Preferences"
            }
            buttons.append(pref_button)
        else:
            message = 'Hi again {}. What would you like me to show you? ' \
                      'Remember you can type any company you want to search for scraped news'.format(name)

            block = 'Subscribe'
            button_title = 'Subscribe'
            button_dict_tmpl = {
                "type": "show_block",
                "block_name": block,
                "title": button_title
            }
            buttons.append(button_dict_tmpl)

    response_data = {
        "messages": [{
            "attachment": {
                "type": "template",
                "payload": {
                    "template_type": "button",
                    "text": message,
                    "buttons": buttons
                }
            }
        }]
    }

    # print(response_data)
    status = 200 if response_data is not None else 403
    js = json.dumps(response_data, indent=2)
    return flask.Response(js, status=status, mimetype='application/json')
Пример #5
0
def handle_mqtt_message(client, userdata, message):
    print("Received message " + str(message.payload.decode()) )
    insert_one(message.payload.decode())
    socketio.emit("message", {'data': str(message.payload.decode()) })
Пример #6
0
from mongo import insert_one
insert_one()