What I’m trying to do
code to export a LinkedIn post with attachment in Obsidian by just providing the URL of the post
Things I have tried
code to export a LinkedIn post with attachment in Obsidian by just providing the URL of the post:
Python
import requests
import json
def export_linkedin_post(url):
response = requests.get(url)
data = json.loads(response.content)
title = data[‘title’]
body = data[‘body’]
attachments = data[‘attachments’]
if attachments:
for attachment in attachments:
filename = attachment[‘filename’]
content = attachment[‘content’]
with open(filename, 'wb') as f:
f.write(content)
note = f"“”
Title: {title}
Body: {body}
Attachments:
{', '.join(attachments)}
“”"
with open(‘export.md’, ‘w’) as f:
f.write(note)
if name == ‘main’:
url = ‘https://www.linkedin.com/posts/johndoe_this-is-a-linkedin-post-with-an-attachment-6879876543210987654_d12345678901234567890.html’
export_linkedin_post(url)
This code first makes a request to the LinkedIn API using the URL of the post. The response is then decoded as JSON and the title, body, and attachments of the post are extracted. If there are any attachments, they are saved to files with the same names as the filenames provided by the API. Finally, a note is created with the title, body, and attachment names and saved to a file called export.md.
To use this code, you will need to install the following Python libraries:
requests
json
You can install these libraries using the following command:
pip install requests json
Once you have installed the required libraries, you can run the code by typing the following command in your terminal:
python export_linkedin_post.py
Replace the url variable in the code with the URL of the LinkedIn post that you want to export.
Kindly Reply
@kepano @Licat @Silver