In [ ]:
import requests
from bs4 import BeautifulSoup

In [ ]:
response = requests.get("https://www.facebook.com/actonmagic")
doc = BeautifulSoup(response.text, 'html.parser')

In [ ]:
stories = doc.find_all("div", { 'class': '_5pbx userContent' })
len(stories)

In [ ]:
import re
all_stories = []

for story in stories:
    
    status = story.find("p")
    if status:
        status_text = status.text.strip()
        #print(status_text)
        new_status = re.sub(r"[^A-Za-z0-9\-\?\:\.\/]", " ", status_text)
        clean_status = re.sub(r"\s\s+"," ", new_status)
        #print(new_status)
        #print(clean_status)
        all_stories.append(clean_status)
print(all_stories)

In [ ]:
all_stories[0]

In [ ]:
api_key = "my key"
api_secret = "my secret"

In [ ]:
!pip install twython

In [ ]:
import twython
twitter = twython.Twython(api_key, api_secret)

In [ ]:
auth = twitter.get_authentication_tokens()
print("Log into Twitter as the user you want to authorize and visit this URL:")
print("\t" + auth['auth_url'])

In [ ]:
pin = "8207618"

twitter = twython.Twython(api_key, api_secret, auth['oauth_token'], auth['oauth_token_secret'])
tokens = twitter.get_authorized_tokens(pin)

new_access_token = tokens['oauth_token']
new_token_secret = tokens['oauth_token_secret']
print("your access token:", new_access_token)
print("your token secret:", new_token_secret)

In [ ]:
twitter = twython.Twython(api_key, api_secret, new_access_token, new_token_secret)

In [ ]:
story_1 = all_stories[0]
story_2 = all_stories[1]
if story_1 != story_2:
    twitter.update_status(status=story_1)

In [ ]:


In [ ]: