예제 #1
0
def conversation(conversationid, interlocutorid):
    """ Render user messages page with a specific conversation loaded. """

    if request.method == "POST":

        # Checks for empty text field
        if not request.form.get("content"):
            flash("Message cannot be empty.", "danger")
            return redirect("/messages/" + conversationid)

        # Creates message object
        message = {}
        message["conversation_id"] = int(conversationid)
        message["sender_id"] = session["user_id"]
        message["receiver_id"] = int(interlocutorid)
        message["content"] = request.form.get("content")

        # Create message in database
        create_message(conn, message)

        # Redirect to feed
        flash("Message sent!", "success")
        return redirect("/messages/" + conversationid + "/" + interlocutorid)

    else:

        messages = get_messages(conn, int(conversationid))

        conversations = get_all_conversations(conn, session["user_id"])

        return render_template("conversation.html", messages=messages, conversation_id=int(conversationid), interlocutor_id=interlocutorid, conversations=conversations)
예제 #2
0
def match_response():
    match_info = request.get_json()
    print(
        "Hello Lucas, I have recently emailed you about your new match with " +
        match_info['name'] + ", " + match_info['age'] + ".")
    print("Please answer the following questions:\n")
    will_unmatch = raw_input("Would you like to unmatch her? ")
    while will_unmatch != 1 and will_unmatch != 0 and will_unmatch != '1' and will_unmatch != '0':
        will_unmatch = raw_input("Invalid input, please enter 1 or 0:\n")
    answer = bool(int(will_unmatch))
    if answer:
        return jsonify({"will_unmatch": 1, "message": None})
    girl_type = raw_input("Is the girl s**t or nerd? ")
    while girl_type.lower() != "s**t" and girl_type.lower() != "nerd":
        girl_type = raw_input("Enter a valid type: (s**t or nerd)\n")
    isAutomatic = raw_input("Should I sent her an automatic message? ")
    while isAutomatic != '1' and isAutomatic != '0' and isAutomatic != 0 and isAutomatic != 1:
        isAutomatic = raw_input("Invalid input, please enter 1 or 0:\n")
    answer = int(isAutomatic)
    if answer:
        return jsonify({
            "will_unmatch": 0,
            "message": create_message(match_info['name'], girl_type)
        })
    message = raw_input("Enter manually the message you would want to send:\n")
    return jsonify({"will_unmatch": 0, "message": message})
예제 #3
0
def create_websocket_connection(url, alias):
    conn = yield websocket_connect(url)
    global count

    while True:
        message = create_message(alias)
        conn.write_message(message)

        yield gen.sleep(1)

        count += 1
예제 #4
0
 def onNewMessage(self, new_messages, match_id):
     her_messages = get_her_messages(self.matches[match_id]['name'],
                                     new_messages)
     my_messages = get_my_messages(self.matches[match_id]['name'],
                                   new_messages)
     did_she_text_last = (her_messages[-1] == new_messages[-1]) if (
         len(her_messages) != 0) else False
     if 'WRONG HOLE' in her_messages or 'WIERD' in her_messages:  # unmatch person
         print('ARE YOU HERE FOR REAL?')
         self.current_matches.remove(match_id)
         self.fix_id_file()
         del self.matches[match_id]
         return tinder_api.unmatch(match_id)
     if 'MORE' == her_messages[-1]:
         tinder_api.send_msg(
             match_id, create_message(self.matches[match_id]['name'],
                                      "more"))
         print("MORE MESSAGE SENT")
     if did_she_text_last and AUTOMATIC_MESSAGES['YES DADDY'].rstrip(
             '\n\r'
     ) not in my_messages:  # This means that I am talking to her now
         if 'YES DADDY' in her_messages or 'LETS GO' in her_messages:
             tinder_api.send_msg(
                 match_id,
                 create_message(self.matches[match_id]['name'],
                                "YES DADDY"))
             print("NEW DATE FOUND -- YES DADDY MESSAGE SENT")
             self.emailer.connect()  # Tell Lucas about new date
             girl = self.matches[match_id]
             self.emailer.make_email(girl, 'date')
             self.emailer.send_email()
             self.emailer.disconnect()
         else:
             tinder_api.send_msg(
                 match_id,
                 create_message(self.matches[match_id]['name'],
                                "invalid_reply"))
             print("INVALID REPLY MESSAGE SENT")
예제 #5
0
def main_func():

    # Get configurations and load into local variable.
    config = hs.import_configurations(sys.argv)
    if not config:
        sys.exit()

    # Unpack the configuration variables
    RUN_MODE = config["RUN_MODE"]
    RUN_TYPE = config["RUN_TYPE"]
    TARGET_URL = config["URLS"]["target_url"]
    KEYWORDS = config["KEYWORDS"]["job_title"]
    HASHTAGS = config["KEYWORDS"]["hashtags"]
    FN_SAVED_GUIDS = config["FILES"]["saved_guids"]
    FN_RECORDS = config["FILES"]["records"]
    LIMITS = config["LIMITS"]
    API_URL_GET_USER = config["URLS"]["li_api_get_user_profile"]

    # Fetch JSON format job posting data. Store current data to guid file.
    data = hs.get_job_data(TARGET_URL)

    # Filter out non-IT jobs.
    it_jobs = hs.filter_data(data, KEYWORDS)

    # Create KEEP and REMOVE list.
    keep_remove = hs.compare_and_keep(it_jobs, FN_SAVED_GUIDS)
    keepers = keep_remove["keep"]

    # Create a list of GUIDS from which the user can choose from.
    suggestions = hs.make_suggestions(keepers, FN_RECORDS, LIMITS)

    # Interface with user.
    if len(suggestions) == 0:
        print(
            "Nothing to post for now. Check back again soon. Exiting program.")
        sys.exit()
    else:
        job_list_json = []
        for job in it_jobs:
            if job["guid"] in suggestions:
                job_list_json.append(job)
        if RUN_MODE == "MANUAL":
            user_selections = selector.present_menu(job_list_json)
        else:
            user_selections = hs.apply_config_selections(config, job_list_json)

    # Make connection with LinkedIn API
    if user_selections:
        linkedin_assist_obj = LinkedinAssist(
            config)  # <-- Basically a modified OAuth2 Request Object

        # Check for existing token
        try:
            token_file = open("./data/token")
            token = json.load(token_file)
            linkedin_assist_obj.get_access(token=token)
            print(STR["main_token_present"])
        except IOError:
            print(
                "[main] Warning: File access error. Reverting to manual authentication."
            )

        # Perform manual authentication if Token isn't present or expired.
        if not linkedin_assist_obj.session.authorized:
            if RUN_MODE != "AUTO":
                linkedin_assist_obj.get_access()
                if not linkedin_assist_obj.session.authorized:
                    print(
                        "[main] Error: Authentication could not be made. Exiting Program"
                    )
                    sys.exit()
            else:
                print(
                    "[main] Authentication Error: Token problem. Possibly expired."
                )
                sys.exit()
        # Token is good - save to file for future use.
        else:
            try:
                with open("./data/token", "w") as token_save:
                    token_save.seek(0)
                    json.dump(token, token_save, indent=2)
                    token_save.truncate()
            except IOError:
                print("[main] Error saving token to file.")

        # Set URN
        urn = linkedin_assist_obj.get_urn(API_URL_GET_USER)

        try:  # POST request to LinkedIn & update records

            # Load records file (date last posted, total times posted)
            with open(FN_RECORDS, "r+") as r:
                records = json.load(r)

                # For each selection:
                #  1. Create the base message (from random message bank (templates))
                #  2. Add hashtags from hashtagbank
                #  3. edit_language is a catch all method to fix small language bugs for example using UX abbrv.
                #  (might move this into the english module.)
                #  4. Create the job request post.
                #  5. Submit request to POST or print to console.
                for selection in user_selections["posts"]:
                    job = hs.search(
                        selection.split(":")[1].strip(), job_list_json)
                    msg = hs.create_message(job, messages.MESSAGES)
                    msg = hs.add_hashtags(msg, HASHTAGS)
                    msg = hs.edit_language(msg)
                    post = linkedin_assist_obj.form_post(job, urn, msg)
                    if linkedin_assist_obj.make_posts(post):
                        if ("DEVELOPMENT" or "TEST") in RUN_TYPE:
                            print("DEMO print:")
                        else:
                            print("POSTED text:")
                            hs.update_records(r, records, job, today)
                        print(msg)
                        print("\nSuccess! [{}]\n\n".format(job["title"]))
                    else:
                        print("\nFailed :( [{}]\n\n".format(job["title"]))
        except IOError:
            print("[main] Error: Records file could not be accessed.")
            print("              No posts made to LinkedIn:\n\n{}".format(
                sys.exc_info()))
            raise
    else:
        print("No shares made to LinkedIn. Exiting Program.")