leoncvlt / loconotion

📄 Python tool to turn Notion.so pages into lightweight, customizable static websites
833 stars 131 forks source link

Twitter Embeds #56

Open jaymu53 opened 3 years ago

jaymu53 commented 3 years ago

So I had some tweet embeds in some of my Notion pages that aren't being rendered properly.

You can use the Twitter embed API to get the HTML for the tweet and replace the tag that's currently on the page.

Currently, I'm using Location to download all the pages and then doing some clean-up.

This is how I'm adding in the tweet embeds:

`tweets = soup.findAll("twitter-widget")

for tweet in tweets:
    tweet_url = "https://twitter.com/name/status/" + tweet.attrs['data-tweet-id']
    twitter_api = "https://publish.twitter.com/oembed?url=" + tweet_url
    tweet_embed_html = requests.get(twitter_api).json()['html'].replace("\n", "")
    tweet_embed_html = "<div style='width: 300'>" + tweet_embed_html + "</div>"
    tweet.append(BeautifulSoup(tweet_embed_html, 'html.parser'))`

Can I add this to the repo?

leoncvlt commented 3 years ago

Could you link an example of a page with broken tweets when parsing? Maybe we can figure out a way to get them to behave. If not, more than happy to adopt your implementation :)