예제 #1
0
파일: tests.py 프로젝트: mvlugt/MANA
def test_get_user():
    db.create_user("test1")
    result_success = db.get_user("test1")
    assert not result_success is None
    result_failure = db.get_user("test2")
    assert result_failure is None
    db.delete_user("test1")
예제 #2
0
파일: tests.py 프로젝트: mvlugt/MANA
def test_update_user():
    _user = db.create_user("test1")
    _user.keywords["key1"] = {"term_frequency": 1, "num_docs": 2}
    db.update_user(_user)
    result = db.get_user("test1")
    assert result.keywords["key1"]["term_frequency"] == 1
    assert result.keywords["key1"]["num_docs"] == 2
    db.delete_user("test1")
예제 #3
0
def main():

    name = input("Hello there! I'm MANA. What is your name? ")

    # Check to see if user already exists in DB
    current_user = db.get_user(name)

    # If not, create user and send seed articles and ask for feedback
    if not current_user:
        current_user = db.create_user(name)
        print("Welcome to MANA " + name)
        print("Here are some initial articles, please take a look: ")
        ARTICLES = [
            "https://techcrunch.com/2016/12/08/uber-spells-out-what-causes-riders-to-lose-access-in-new-policy/",
            "http://www.cnn.com/2016/12/06/entertainment/grammy-nominations-2017/index.html",
            "http://www.dailytimesgazette.com/36308-2/36308/"
        ]
        send_articles(ARTICLES)
        get_feedback(current_user, ARTICLES)
        response = input("Would you like to continue using MANA? ")
        if response == "yes":
            go_on = True
        else:
            go_on = False

    # If they do exist, send them some articles they may like and ask for feedback
    else:
        go_on = True
        print("Welcome back " + name)
        print("Here are some articles I think you might like: ")

    while go_on:
        rel_articles = content.get_relevant_urls(current_user)
        rel_articles = [item[1] for item in rel_articles]
        qual_articles = quality.filterArticles(rel_articles)
        print(qual_articles)
        ARTICLES = [item.url for item in qual_articles]
        send_articles(ARTICLES)
        get_feedback(current_user, ARTICLES)
        response = input("Would you like to continue using MANA? ")
        if response == "yes":
            go_on = True
        else:
            go_on = False
예제 #4
0
def webhook():

    # list of Article URLS, as a default this should start with our "seed" urls
    ARTICLES = ["http://www.cnn.com/2016/12/06/politics/obama-trump-terrorism-views/index.html", "http://www.cnn.com/2016/12/06/entertainment/grammy-nominations-2017/index.html"]
    data = request.get_json()
    log(data) 

    if data["object"] == "page":

        for entry in data["entry"]:
            for messaging_event in entry["messaging"]:

                if messaging_event.get("message"):  # someone sent us a message

                    sender_id = messaging_event["sender"]["id"]        # the facebook ID of the person sending you the message
                    recipient_id = messaging_event["recipient"]["id"]  # the recipient's ID, which should be your page's facebook ID
                    message_text = messaging_event["message"]["text"]  # the message's text

                    current_user = db.get_user(sender_id)
                    # If current_user returns null, then this user does not exist in our database yet
                    if not current_user:
                        # 1). Create a user
                        current_user = db.create_user(sender_id)
                        # 2). Send a lil greeting 
                        send_message(sender_id, "Hi I'm MANA! Please tell me which of these articles interested you most")
                        article_list_message = ""
                        # 3). Send the list of our default initial articles
                        for i in range(0, len(ARTICLES)):
                            article_list_message += (str(i) + ": " + ARTICLES[i] + "\n")
                        send_message(sender_id, article_list_message)
                    else:
                        current_user.num_docs_liked = 7
                        current_user.keywords = {
                            "computer": {
                                "term_frequency": 10,
                                "num_docs": 4
                            },
                            "technology": {
                                "term_frequency": 17,
                                "num_docs": 3
                            },
                            "payment": {
                                "term_frequency": 32,
                                "num_docs": 5
                            },
                            "business": {
                                "term_frequency": 50,
                                "num_docs": 6
                            }
                        }
                        # Get the numbers of the article the user likes
                        articles_user_likes = [int(s) for s in message_text.split() if s.isdigit()]
                        send_message(sender_id, "Thanks for giving me that feedback.")
                        for index in articles_user_likes:
                            log("updating user profile")
                            # For each article the user likes, grab the keywords and update the user profile
                            url = ARTICLES[index]
                            key_words = content.get_stats(url)
                            db.update_stats(sender_id, key_words)
                        
                        # This should reflect the updated user profile
                        log("attempting to get relevant urls")
                        ARTICLES = content.get_top_urls(ARTICLES, current_user, 2)
                        log("got articles")

                        send_message(sender_id, "I found these articles I thought you might like. As always, please let me know which articles interested you most")
                        article_list_message = ""
                        # 3). Send the list of our default initial articles
                        for i in range(0, len(ARTICLES)):
                            article_list_message += (str(i) + ": " + ARTICLES[i][1] + "\n")
                        send_message(sender_id, article_list_message)
                            
                            
                if messaging_event.get("delivery"):  # delivery confirmation
                    pass

                if messaging_event.get("optin"):  # optin confirmation
                    pass

                if messaging_event.get("postback"):  # user clicked/tapped "postback" button in earlier message
                    pass

    return "ok", 200
예제 #5
0
파일: tests.py 프로젝트: mvlugt/MANA
def test_create_user():
    db.create_user("test1")
    db.delete_user("test1")