示例#1
0
    def facebook_schedule_publish(self, email, password, media_username, post_datetime, media_type="facebook"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and find posts with the email = email provided in params
        current_time_scheduled_posts = retrieve_current_time_scheduled_posts(email)

        # loop through current_time_scheduled_posts to publish content to appropriate media platform
        for post in current_time_scheduled_posts:
            # post right content to Twitter
            if post[3] == media_type:
                # connect facebook app to the access token for the user
                graph = facebook.GraphAPI(post[5])
                # retrieve all the pages associate to the user - "me"
                accounts = graph.get_connections(id="me", connection_name="accounts")
                # iterates through all the pages to get the very page id number user want to post to
                for page in accounts["data"]:
                    if page["name"] == post[2]:
                        identity_number = page["id"]
                        token_key = page["access_token"]
                # connect facebook app to the access token for that very page
                graph_page = facebook.GraphAPI(token_key)
                # post scheduled text to facebook
                graph_page.put_object(parent_object=identity_number, connection_name="feed", message=post[1])

        return "Post successfully published to LinkedIn", 200
示例#2
0
    def schedule_post(self, email, password, post_datetime, media_type, media_username, message_text):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and also retrieve the token key and secret
        account_details = retrieve_token(email)

        # save message_text into publishing collection
        post_details = {"body": message_text,
        "email": email,
        "media_username": media_username,
        "media_type": media_type,
        "sm_profile_id": account_details[0][4],
        "token_key": account_details[0][2],
        "token_secret": account_details[0][3],
        "post_datetime": post_datetime,
        "post_type": "scheduled"
        }
        publishing_collection.insert_one(post_details)

        return "Your post has been scheduled for {}".format(post_datetime), 200
示例#3
0
    def twitter_schedule_publish(self, email, password, media_username, post_datetime, media_type="twitter"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and find posts with the email = email provided in params
        current_time_scheduled_posts = retrieve_current_time_scheduled_posts(email)
        
        # loop through current_time_scheduled_posts to publish content to appropriate media platform
        for post in current_time_scheduled_posts:
            # post right content to Twitter
            if post[3] == media_type:
                try:
                    # authenticate twitter app with user account
                    auth.set_access_token(token_key, token_secret)
                    api = tweepy.API(auth, wait_on_rate_limit=True)
                    api.verify_credentials()
                    print("Authentication OK")
                except:
                    print("Error during authentication")

                finally:
                    # Post Tweet on Twitter
                    api.update_status(post[1])
        return "Post successfully published to Twitter", 200
示例#4
0
    def get_posts_twitter(self, email, password, media_username, media_type="twitter"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405
        # confirm user has access to account, and also retrieve the right token key and secret
        account_details = retrieve_token(email)

        # fetch requested data
        if media_type == media_type:
            try:
                # authenticate twitter app with user account
                auth.set_access_token(account_details[0][2], account_details[0][3])
                api = tweepy.API(auth, wait_on_rate_limit=True)
                api.verify_credentials()
                print("Authentication OK")
            except:
                return "Error during authentication"

            finally:
                # Retrieve users recent tweets on Twitter
                user_all_tweets_details = api.user_timeline(screen_name = account_details[0][1], count = 15, include_rts = False)
                # Collect required details only
                user_tweets_details = [(status.text, status.user.screen_name, status.favorite_count, status.retweet_count) for status in my_tweets]
                return user_tweets_details, 200
示例#5
0
    def change_schedule(self, email, password, post_id, new_message_text, post_datetime):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # verify if user has access to the post
        correct_email = entry.verify_email_to_post(post_id, email)
        if not correct_email:
            return "Unauthorized request", 403

        # find the post to be deleted
        post_to_change = publishing_collection.find_one({"_id": post_id})

        # delete the scheduled post
        publishing_collection.update_one({
        "_id": post_id
        }, {
        "$set": {
        "body": new_message_text,
        "post_datetime": post_datetime
        }
        })

        return "Post updated", 200
示例#6
0
    def add_keyword_linkedin(self,
                             email,
                             password,
                             keyword,
                             media_username,
                             media_type="linkedin"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and also retrieve the token key and secret
        account_details = retrieve_token(email)

        # save contents to listening colletion
        keyword_details = {
            "email": email,
            "media_username": media_username,
            "media_type": media_type,
            "sm_profile_id": account_details[0][4],
            "token_key": account_details[0][2],
            "keyword": keyword
        }
        listening_collection.insert_one(keyword_details)

        return "{} has been added successfully".format(keyword), 200
示例#7
0
    def twitter_listening(self,
                          email,
                          password,
                          keyword,
                          media_username,
                          date_since,
                          media_type="twitter"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        try:
            # authenticate twitter app with user account
            auth.set_access_token(token_key, token_secret)
            api = tweepy.API(auth, wait_on_rate_limit=True)
            api.verify_credentials()
            print("Authentication OK")
        except:
            print("Error during authentication")
        finally:
            # Post Tweet on Twitter
            tweets = tweepy.Cursor(api.search,
                                   q=search_words,
                                   lang="en",
                                   since=date_since).items(10000)
示例#8
0
    def linkedin_quick_post(self, email, password, media_username, message_text, media_type="linkedin"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and also retrieve the token key and secret
        account_details = retrieve_token(email)

        # save message_text into publishing collection
        post_details = {"body": message_text,
        "email": email,
        "media_username": media_username,
        "media_type": media_type,
        "sm_profile_id": account_details[0][4],
        "token_key": account_details[0][2],
        "post_datetime": post_datetime,
        "post_type": "quick"
        }
        publishing_collection.insert_one(post_details)

        # linkedin api url for posting
        url = "https://api.linkedin.com/v2/ugcPosts"
        # header parameter
        headers = {'Content-Type': 'application/json',
        'X-Restli-Protocol-Version': '2.0.0',
        'Authorization': 'Bearer ' + token_key}
        # post json
        post_data = {
            "author": "urn:li:organization:"+sm_profile_id,
            "lifecycleState": "PUBLISHED",
            "specificContent": {
                "com.linkedin.ugc.ShareContent": {
                    "shareCommentary": {
                        "text": message_text
                        },
                        "shareMediaCategory": "NONE"
                        }
                        },
                        "visibility": {
                            "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
                            }
                            }
        # try posting content
        try:
            requests.post(url, headers=headers, json=post_data)
        except:
            print("Error trying to post content")
        return "Post successfully published to LinkedIn", 200
示例#9
0
    def linkedin_schedule_publish(self, email, password, media_username, post_datetime, media_type="linkedin"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and find posts with the email = email provided in params
        current_time_scheduled_posts = retrieve_current_time_scheduled_posts(email)

        # loop through current_time_scheduled_posts to publish content to appropriate media platform
        for post in current_time_scheduled_posts:
            # post right content to Twitter
            if post[3] == media_type:
                # linkedin api url for posting
                url = "https://api.linkedin.com/v2/ugcPosts"
                # header parameter
                headers = {'Content-Type': 'application/json',
                'X-Restli-Protocol-Version': '2.0.0',
                'Authorization': 'Bearer ' + post[5]}
                # post json
                post_data = {
                    "author": "urn:li:organization:"+post[4],
                    "lifecycleState": "PUBLISHED",
                    "specificContent": {
                        "com.linkedin.ugc.ShareContent": {
                            "shareCommentary": {
                                "text": post[1]
                                },
                                "shareMediaCategory": "NONE"
                                }
                                },
                                "visibility": {
                                    "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
                                    }
                                    }
                # try posting content
                try:
                    requests.post(url, headers=headers, json=post_data)
                except:
                    print("Error trying to post content")
        return "Post successfully published to LinkedIn", 200
示例#10
0
    def see_schedule(self, email, password):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and find posts with the email = email provided in params
        all_posts = publishing_collection.find({"email": email})
        scheduled_posts = [(i["_id"], i["body"], i["media_username"], i["post_datetime"])
        for i in all_posts if i["post_type"]=="scheduled"]

        return scheduled_posts, 200
示例#11
0
    def twitter_quick_post(self, email, password, media_username, message_text, media_type="twitter"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # confirm user has access to account, and also retrieve the token key and secret
        account_details = retrieve_token(email)

        # save message_text into publishing collection
        post_details = {"body": message_text,
        "email": email,
        "media_username": media_username,
        "media_type": media_type,
        "token_key": account_details[0][2],
        "token_secret": account_details[0][3],
        "post_datetime": post_datetime,
        "post_type": "quick"
        }
        publishing_collection.insert_one(post_details)

        try:
            # authenticate twitter app with user account
            auth.set_access_token(token_key, token_secret)
            api = tweepy.API(auth, wait_on_rate_limit=True)
            api.verify_credentials()
            print("Authentication OK")
        except:
            print("Error during authentication")

        finally:
            # Post Tweet on Twitter
            api.update_status(message_text)
        return "Post successfully published to Twitter", 200
示例#12
0
    def get_posts_linkedin(self, email, password, media_username, media_type="linkedin"):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405
        # confirm user has access to account, and also retrieve the right token key and secret
        account_details = retrieve_token(email)

        if media_type == media_type:
            # linkedin url for retrieving posts
            url = "https://api.linkedin.com/v2/ugcPosts?q=authors&authors=List(urn%3Ali%3Aorganization%3A{})&sortBy=LAST_MODIFIED".format(sm_profile_id)
            # required parameter
            params = {'oauth2_access_token': token_key}
            # retrieve posts
            response = requests.get(url, params=params)
            # loop through posts
        return response # to change it when Linkedin solve issue
示例#13
0
    def kill_scheduled_post(self, email, password, post_id):
        # confirm if email is in database
        try:
            customers_collection.find_one({"email": email})
        except:
            return "Email does not exist", 402
        # confirm email-password match
        entry = Entry()
        correct_password = entry.verify_password(email, password)
        if not correct_password:
            return "Incorrect password", 405

        # verify if user has access to the post
        correct_email = entry.verify_email_to_post(post_id, email)
        if not correct_email:
            return "Unauthorized request", 403

        # find the post to be deleted
        post_to_delete = publishing_collection.find_one({"_id": post_id})

        # delete the scheduled post
        publishing_collection.delete_one(post_to_delete)

        return "Post deleted", 200
示例#14
0
async def access(email: str, password: str):
    entry = Entry()
    login_result = entry.login(email, password)
    return login_result
示例#15
0
async def access(fullname: str, email: str, password: str):
    entry = Entry()
    signup_result = entry.signup(fullname, email, password)
    return signup_result