### Get Blog Information (Python) Source: https://context7.com/tumblr/pytumblr/llms.txt This snippet demonstrates retrieving information about a blog, including name, title, description, post count, URL, and other settings. It includes examples of checking multiple blogs. ```python # Get blog information blog_info = client.blog_info('staff.tumblr.com') # Access blog properties if blog_info.get('meta', {}).get('status') == 200: blog = blog_info['blog'] print(f"Blog Name: {blog['name']}") print(f"Title: {blog['title']}") print(f"Description: {blog.get('description', '')}") print(f"Total Posts: {blog['posts']}") print(f"URL: {blog['url']}") print(f"Updated: {blog.get('updated', 0)}") print(f"Ask Enabled: {blog.get('ask', False)}") print(f"Ask Anonymous: {blog.get('ask_anon', False)}") # Check multiple blogs blogs = ['staff', 'engineering', 'art'] for blog_name in blogs: info = client.blog_info(blog_name) if info.get('blog'): print(f"{blog_name}: {info['blog']['posts']} posts") ``` -------------------------------- ### Setup Interactive Console - Bash Source: https://github.com/tumblr/pytumblr/blob/master/README.rst Runs the PyTumblr interactive console for OAuth authentication. Requires pyyaml package installed. Stores authentication tokens in ~/.tumblr for use across different Tumblr API clients. ```bash $ python interactive_console.py ``` -------------------------------- ### Install PyTumblr using pip Source: https://github.com/tumblr/pytumblr/blob/master/README.rst This command installs the PyTumblr library using pip. Ensure pip is up to date before running. ```bash pip install pytumblr ``` -------------------------------- ### Get Blog Posts (Python) Source: https://context7.com/tumblr/pytumblr/llms.txt Demonstrates fetching posts from a blog with filtering and pagination. Shows examples including post type filtering (photo, video), tag filtering, retrieving a specific post by ID and pagination and using NPF. ```python # Get recent posts from a blog posts = client.posts('staff.tumblr.com', limit=20) # Process posts for post in posts.get('posts', []): print(f"Post ID: {post['id']}") print(f"Type: {post['type']}") print(f"URL: {post['post_url']}") print(f"Tags: {', '.join(post.get('tags', []))}") print("---") # Filter by post type photo_posts = client.posts('photography-blog.tumblr.com', type='photo', limit=10) video_posts = client.posts('video-blog.tumblr.com', type='video', limit=10) # Filter by tag cat_posts = client.posts('cutecats.tumblr.com', tag='kittens', limit=20) # Get specific post by ID specific_post = client.posts('staff.tumblr.com', id=123456789) # Pagination with offset offset = 0 all_posts = [] while offset < 100: batch = client.posts('blog.tumblr.com', limit=20, offset=offset, reblog_info=True, notes_info=True) posts_list = batch.get('posts', []) if not posts_list: break all_posts.extend(posts_list) offset += 20 # Use NPF (Neue Post Format) for modern content pf_posts = client.posts('blog.tumblr.com', npf=True, limit=10) ``` -------------------------------- ### Get Blog's Queued Posts using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Explains how to retrieve posts that are currently in a blog's queue, which requires authentication as the blog owner. It covers fetching queued posts, processing their details, and implementing pagination. An example also shows how to fetch queued posts using the NPF (New Post Format) option. ```python import pytumblr # Assuming 'client' is an authenticated pytumblr client instance # Get queued posts blog_identifier = 'myblog.tumblr.com' print(f"--- Fetching queued posts for {blog_identifier} ---") queue_response = client.queue(blog_identifier, limit=20) # Process queued posts if queue_response and queue_response.get('posts'): print(f"Number of posts currently in queue: {len(queue_response['posts'])}") for post in queue_response['posts']: print(f" Post ID: {post.get('id', 'N/A')}") print(f" Post Type: {post.get('type', 'N/A')}") print(f" Post State: {post.get('state', 'N/A')}") print(f" Scheduled for: {post.get('scheduled_publish_time', 'Not scheduled')}") print(" ---") else: print("No posts found in the queue or could not retrieve.") # Get queue with NPF format for modern content print(f"\n--- Fetching queued posts with NPF format ---") npf_queue = client.queue(blog_identifier, npf=True, limit=10) if npf_queue and npf_queue.get('posts'): print(f"Retrieved {len(npf_queue['posts'])} posts in NPF format.") # Process NPF posts similar to other post types else: print("Could not retrieve NPF queued posts.") # Pagination using offset print(f"\n--- Fetching ALL queued posts using pagination ---") offset = 0 all_queued = [] while True: batch = client.queue(blog_identifier, limit=20, offset=offset) posts = batch.get('posts', []) if not posts: print("No more queued posts to retrieve.") break all_queued.extend(posts) print(f"Retrieved batch of {len(posts)} posts. Total collected so far: {len(all_queued)}.") offset += 20 # Increment offset for the next request print(f"\nSuccessfully retrieved a total of {len(all_queued)} queued posts.") ``` -------------------------------- ### Get Publicly Followed Blogs using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Demonstrates how to retrieve a list of blogs that a specific blog publicly follows. This functionality is available only if the blog owner has enabled the feature to show who they follow. The examples cover basic retrieval, processing blog data, and implementing pagination using an offset. ```python import pytumblr # Assuming 'client' is an authenticated pytumblr client instance # Get blogs that a blog follows blog_identifier = 'staff.tumblr.com' print(f"--- Fetching blogs followed by {blog_identifier} ---") following_response = client.blog_following(blog_identifier, limit=20) # Process followed blogs if following_response and following_response.get('blogs'): print(f"Total blogs publicly followed: {following_response.get('total_blogs', 0)}") print(f"First batch of {len(following_response['blogs'])} followed blogs:") for blog in following_response['blogs']: print(f" Blog Name: {blog.get('name', 'N/A')}") print(f" Blog URL: {blog.get('url', 'N/A')}") description = blog.get('description', 'No description') print(f" Blog Description: {description[:100]}{'...' if len(description) > 100 else ''}") print(" ---") else: print("No followed blogs found or could not retrieve the list.") # Pagination using offset print(f"\n--- Fetching ALL blogs followed by {blog_identifier} ---") offset = 0 all_following = [] while True: batch = client.blog_following('publicblog.tumblr.com', limit=20, offset=offset) blogs = batch.get('blogs', []) if not blogs: print("No more followed blogs to retrieve.") break all_following.extend(blogs) print(f"Retrieved batch of {len(blogs)} blogs. Total collected so far: {len(all_following)}.") offset += 20 # Increment offset for the next request print(f"\nSuccessfully retrieved a total of {len(all_following)} followed blogs.") ``` -------------------------------- ### Get Blog's Draft Posts using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Provides guidance on retrieving draft posts for a blog, which requires the user to be authenticated as the blog owner. The examples demonstrate fetching drafts, processing post details like ID, type, and state, and include a preview of content for text and photo posts. It also shows how to fetch drafts using the NPF format. ```python import pytumblr # Assuming 'client' is an authenticated pytumblr client instance # Get draft posts blog_identifier = 'myblog.tumblr.com' print(f"--- Fetching draft posts for {blog_identifier} ---") drafts_response = client.drafts(blog_identifier) # Process drafts if drafts_response and drafts_response.get('posts'): print(f"Number of draft posts found: {len(drafts_response['posts'])}") for post in drafts_response['posts']: print(f" Post ID: {post.get('id', 'N/A')}") print(f" Post Type: {post.get('type', 'N/A')}") print(f" Post State: {post.get('state', 'N/A')}") # Type-specific content preview if post['type'] == 'text': print(f" Title: {post.get('title', 'No title')}") body_preview = post.get('body', '') print(f" Body preview: {body_preview[:100]}{'...' if len(body_preview) > 100 else ''}") elif post['type'] == 'photo': photos = post.get('photos', []) print(f" Number of photos: {len(photos)}") if photos: print(f" Caption preview: {photos[0].get('caption', '')[:100]}{'...' if len(photos[0].get('caption', '')) > 100 else ''}") print(" ---") else: print("No draft posts found or could not retrieve.") # Get drafts with NPF format for modern content print(f"\n--- Fetching draft posts with NPF format ---") npf_drafts = client.drafts(blog_identifier, npf=True) if npf_drafts and npf_drafts.get('posts'): print(f"Retrieved {len(npf_drafts['posts'])} posts in NPF format.") # Process NPF posts similar to other post types else: print("Could not retrieve NPF draft posts.") ``` -------------------------------- ### Create Tumblr Photo Posts Source: https://github.com/tumblr/pytumblr/blob/master/README.rst Examples of creating photo posts and photosets using PyTumblr. Supports publishing, drafts, or queued posts with tags, captions, and options for using image URLs or local file paths. Supports markdown or HTML formatting for captions. ```python #Creates a photo post using a source URL client.create_photo(blogName, state="published", tags=["testing", "ok"], source="https://68.media.tumblr.com/b965fbb2e501610a29d80ffb6fb3e1ad/tumblr_n55vdeTse11rn1906o1_500.jpg") #Creates a photo post using a local filepath client.create_photo(blogName, state="queue", tags=["testing", "ok"], tweet="Woah this is an incredible sweet post [URL]", data="/Users/johnb/path/to/my/image.jpg") #Creates a photoset post using several local filepaths client.create_photo(blogName, state="draft", tags=["jb is cool"], format="markdown", data=["/Users/johnb/path/to/my/image.jpg", "/Users/johnb/Pictures/kittens.jpg"], caption="## Mega sweet kittens") ``` -------------------------------- ### Get Blog Followers using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Illustrates how to retrieve a list of followers for a specific blog using the pytumblr library. This function requires authentication as the blog owner. The examples show basic retrieval, processing follower data, and implementing pagination using an offset to fetch all followers. ```python import pytumblr # Assuming 'client' is an authenticated pytumblr client instance # Get blog followers with limit and offset blog_identifier = 'myblog.tumblr.com' print(f"--- Fetching followers for {blog_identifier} ---") followers_response = client.followers(blog_identifier, limit=20, offset=0) # Process followers if followers_response and followers_response.get('users'): print(f"Total followers reported by API: {followers_response.get('total_users', 'N/A')}") print(f"First batch of {len(followers_response['users'])} followers:") for user in followers_response['users']: print(f" Follower Name: {user.get('name', 'N/A')}") print(f" Follower URL: {user.get('url', 'N/A')}") print(f" Following this blog: {user.get('following', False)}") print(" ---") else: print("No followers found or could not retrieve followers.") # Get all followers using pagination with offset print(f"\n--- Fetching ALL followers for {blog_identifier} ---") offset = 0 all_followers = [] while True: batch = client.followers(blog_identifier, limit=20, offset=offset) users = batch.get('users', []) if not users: print("No more followers to retrieve.") break all_followers.extend(users) print(f"Retrieved batch of {len(users)} followers. Total collected so far: {len(all_followers)}.") offset += 20 # Increment offset for the next request print(f"\nSuccessfully retrieved a total of {len(all_followers)} followers.") ``` -------------------------------- ### Tumblr User API Methods Source: https://github.com/tumblr/pytumblr/blob/master/README.rst Provides Python examples for various user-related operations using the TumblrRestClient. Includes fetching user info, dashboard, likes, following, and performing follow/unfollow and like/unlike actions on posts. ```python client.info() # get information about the authenticating user client.dashboard() # get the dashboard for the authenticating user client.likes() # get the likes for the authenticating user client.following() # get the blogs followed by the authenticating user client.follow('codingjester.tumblr.com') # follow a blog client.unfollow('codingjester.tumblr.com') # unfollow a blog client.like(id, reblogkey) # like a post client.unlike(id, reblogkey) # unlike a post ``` -------------------------------- ### Get Blog Avatar URL (Python) Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves the URL of a blog's avatar image at a specified size. Provides a simple example of how to get the avatar URL. ```python # Get blog avatar avatar = client.avatar('staff.tumblr.com', size=128) ``` -------------------------------- ### Create Tumblr Chat Posts with PyTumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Provides examples for creating chat posts, including posts without titles and those with HTML formatting. Requires an active PyTumblr client connection. ```python # Create a chat post result = client.create_chat( 'myblog.tumblr.com', state="published", title="Funny Conversation", conversation="""Alice: Did you finish the project? Bob: Almost! Just debugging the last feature. Alice: Need any help? Bob: Actually, yes! Can you review my code? Alice: Sure, send it over!""", tags=['chat', 'conversation', 'coding'] ) # Check result if result.get('meta', {}).get('status') == 201: print(f"Chat post created! ID: {result['response']['id']}") # Create chat without title result = client.create_chat( 'myblog.tumblr.com', state="published", conversation="""Customer: Is this the customer service? Support: Yes! How can I help you today? Customer: I love your product! Support: Thank you so much! We're glad you're enjoying it.""", tags=['customer-service', 'testimonial'] ) # Create formatted chat post result = client.create_chat( 'myblog.tumblr.com', state="published", title="Technical Discussion", conversation="""Dev1: Have you tried the new Python library? Dev2: Yes! It's amazing for API integrations. Dev1: What's the learning curve like? Dev2: Pretty gentle. The docs are excellent. Dev1: Perfect, I'll check it out!""", format="html", tags=['programming', 'python', 'discussion'] ) # Queue chat post queued_chat = client.create_chat( 'myblog.tumblr.com', state="queue", title="Daily Chat", conversation="""Person1: Good morning! Person2: Morning! Ready for the day? Person1: Absolutely! Let's do this.""", tags=['daily', 'morning', 'motivation'] ) ``` -------------------------------- ### Follow a Blog in Python Source: https://context7.com/tumblr/pytumblr/llms.txt Follows a specified blog. Accepts the blog name with or without the .tumblr.com suffix. This functionality is not fully implemented in the example given. ```Python # Follow a blog # client.follow(blog_name='blogname.tumblr.com') # client.follow(blog_name='blogname') ``` -------------------------------- ### Get Blog's Liked Posts using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Shows how to retrieve a list of posts that a specific blog has liked, provided the likes are public. This includes examples of fetching liked posts, processing them, and implementing pagination using timestamps to retrieve older liked posts. ```python import pytumblr import time # Assuming 'client' is an authenticated pytumblr client instance # Get a blog's liked posts likes = client.blog_likes('staff.tumblr.com', limit=20) # Process liked posts if likes.get('liked_posts'): print(f"Total liked posts retrieved: {len(likes['liked_posts'])}") for post in likes['liked_posts']: print(f"Liked by: {post.get('blog_name', 'N/A')} - Type: {post.get('type', 'N/A')}") print(f"Post URL: {post.get('post_url', 'N/A')}") print(f"Liked Timestamp: {post.get('liked_timestamp')}") print("---") else: print("No liked posts found or accessible.") # Pagination with timestamps print("\n--- Fetching older liked posts ---") # Get current timestamp for 'before' parameter current_timestamp = int(time.time()) before_timestamp = current_timestamp all_likes = [] # Fetch up to 100 liked posts, going back in time while len(all_likes) < 100: batch = client.blog_likes('publicblog.tumblr.com', limit=20, before=before_timestamp) liked_posts = batch.get('liked_posts', []) if not liked_posts: print("No more liked posts to retrieve.") break all_likes.extend(liked_posts) # Use the timestamp of the last post in the batch for the next request before_timestamp = liked_posts[-1]['liked_timestamp'] print(f"Fetched {len(liked_posts)} posts. Total collected: {len(all_likes)}. Next 'before' timestamp: {before_timestamp}") print(f"\nSuccessfully collected {len(all_likes)} liked posts in total.") ``` -------------------------------- ### Get and process post notes Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves notes (likes, reblogs, replies) for a specific Tumblr post with pagination support. Requires blog identifier and post ID. Examples show basic note retrieval with type processing, pagination through large note sets using timestamp, and counting different note types. ```python notes = client.notes('myblog.tumblr.com', id='123456789') if notes.get('notes'): print(f"Total notes: {notes.get('total_notes', 0)}") for note in notes['notes']: print(f"Type: {note['type']}") # like, reblog, reply, etc. print(f"Blog: {note.get('blog_name', 'Anonymous')}") print(f"Timestamp: {note.get('timestamp')}") if note['type'] == 'reblog': print(f"Reblog URL: {note.get('post_url')}") print(f"Added tags: {note.get('added_tags', [])}") elif note['type'] == 'reply': print(f"Reply text: {note.get('reply_text', '')}") print("---") before_timestamp = None all_notes = [] while True: params = {'id': '123456789'} if before_timestamp: params['before_timestamp'] = before_timestamp batch = client.notes('myblog.tumblr.com', **params) notes_list = batch.get('notes', []) if not notes_list: break all_notes.extend(notes_list) # Check if there are more notes if not batch.get('_links', {}).get('next'): break before_timestamp = notes_list[-1]['timestamp'] print(f"Retrieved {len(all_notes)} total notes") note_counts = {'like': 0, 'reblog': 0, 'reply': 0} notes_data = client.notes('myblog.tumblr.com', id='123456789') for note in notes_data.get('notes', []): note_type = note['type'] note_counts[note_type] = note_counts.get(note_type, 0) + 1 print(f"Likes: {note_counts['like']}") print(f"Reblogs: {note_counts['reblog']}") print(f"Replies: {note_counts['reply']}") ``` -------------------------------- ### Get Blogs User Follows in Python Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves a list of blogs the user follows. Includes pagination to fetch all followed blogs, even beyond the default limit. ```Python # Get followed blogs following = client.following(limit=50, offset=0) # Process followed blogs if following.get('blogs'): print(f"Total following: {following['total_blogs']}") for blog in following['blogs']: print(f"Blog: {blog['name']}") print(f"Title: {blog.get('title', 'No title')}") print(f"URL: {blog['url']}") print(f"Updated: {blog.get('updated', 0)}") print("---") # Get all followed blogs with pagination offset = 0 all_following = [] while True: batch = client.following(limit=20, offset=offset) blogs = batch.get('blogs', []) if not blogs: break all_following.extend(blogs) offset += 20 ``` -------------------------------- ### Get and Download Blog Avatar using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Demonstrates how to retrieve a blog's avatar URL and download the avatar image using the pytumblr library and the requests library. It covers fetching avatars at various sizes and saving the downloaded image to a file. ```python import pytumblr import requests # Assuming 'client' is an authenticated pytumblr client instance # Print Avatar URL avatar_data = client.avatar('example.tumblr.com') print(f"Avatar URL: {avatar_data.get('avatar_url')}") # Get avatars at different sizes sizes = [16, 24, 30, 40, 48, 64, 96, 128, 512] avatars = {} for size in sizes: result = client.avatar('example.tumblr.com', size=size) avatars[size] = result.get('avatar_url') print(f"{size}px: {avatars[size]}") # Download avatar avatar_result = client.avatar('myblog.tumblr.com', size=512) if avatar_result.get('avatar_url'): response = requests.get(avatar_result['avatar_url']) with open('avatar.png', 'wb') as f: f.write(response.content) print("Avatar downloaded successfully as avatar.png") else: print("Could not retrieve avatar URL.") ``` -------------------------------- ### GET /blog/{blog-identifier}/notes Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves notes (likes, reblogs, replies) for a specific post with optional pagination support. ```APIDOC ## GET /blog/{blog-identifier}/notes ### Description Returns a collection of notes (likes, reblogs, replies) associated with a given post. Supports pagination via the `before_timestamp` parameter. ### Method GET ### Endpoint /blog/{blog-identifier}/notes ### Parameters #### Path Parameters - **blog-identifier** (string) - Required - Blog hostname. - **id** (string) - Required - The ID of the post whose notes are requested. #### Query Parameters - **before_timestamp** (integer) - Optional - Return notes created before this Unix timestamp to paginate results. #### Request Body - *None* ### Request Example GET /blog/myblog.tumblr.com/notes?id=123456789&before_timestamp=1700000000 ### Response #### Success Response (200) - **notes** (array) - List of note objects. - **total_notes** (integer) - Total number of notes for the post. - **_links.next** (string) - URL for the next page of notes (if any). ### Response Example { "notes": [ {"type": "like", "blog_name": "user1", "timestamp": 1701234567}, {"type": "reblog", "blog_name": "user2", "timestamp": 1701234000, "post_url": "https://...", "added_tags": ["fun"]} ], "total_notes": 2, "_links": {"next": "..."} } ``` -------------------------------- ### Get User's Dashboard Feed in Python Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves posts from the user's dashboard. The dashboard feed is similar to viewing the Tumblr homepage. Demonstrates pagination to retrieve more than the default limit. ```Python # Get recent dashboard posts dashboard = client.dashboard(limit=20, type='photo') # Process dashboard posts if dashboard.get('posts'): for post in dashboard['posts']: print(f"Post ID: {post['id']}") print(f"Blog: {post['blog_name']}") print(f"Type: {post['type']}") print(f"Tags: {', '.join(post.get('tags', []))}") print(f"Note count: {post.get('note_count', 0)}") print("---") # Pagination example offset = 0 all_posts = [] while len(all_posts) < 100: batch = client.dashboard(limit=20, offset=offset, reblog_info=True, notes_info=True) if not batch.get('posts'): break all_posts.extend(batch['posts']) offset += 20 ``` -------------------------------- ### Get Blog Submitted Posts - PyTumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves posts from a blog's submission queue. Requires authentication as the blog owner. Handles pagination to fetch all submissions and iterates through them, printing details like post ID, type, and content. Dependencies: PyTumblr client. ```python # Get submitted posts submissions = client.submission('myblog.tumblr.com', offset=0) # Process submissions if submissions.get('posts'): print(f"Submissions: {len(submissions['posts'])}") for post in submissions['posts']: print(f"Post ID: {post['id']}") print(f"Type: {post['type']}") print(f"Submitter: {post.get('submitter', 'Anonymous')}") print(f"Submission timestamp: {post.get('timestamp')}") # Review submission content if post['type'] == 'text': print(f"Body: {post.get('body', '')[:200]}") print("---") # Pagination through submissions offset = 0 all_submissions = [] while True: batch = client.submission('myblog.tumblr.com', offset=offset) posts = batch.get('posts', []) if not posts: break all_submissions.extend(posts) offset += 20 ``` -------------------------------- ### Reblog post with comment and tags Source: https://context7.com/tumblr/pytumblr/llms.txt Reblogs a Tumblr post with a custom comment and tags. Requires a valid client instance, blog identifier, post ID, and reblog key. The example shows reblogging with different states (published, draft, queue) and demonstrates batch reblogging of dashboard content based on tags. ```python result = client.reblog( 'myblog.tumblr.com', id=987654321, reblog_key="xyz789abc", comment="This is exactly what I was thinking! Great post.", tags=['reblog', 'agree', 'interesting'] ) draft_reblog = client.reblog( 'myblog.tumblr.com', id=456789123, reblog_key="key123", state="draft", comment="Need to review this before publishing" ) queued_reblog = client.reblog( 'myblog.tumblr.com', id=789123456, reblog_key="keyabc", state="queue", comment="Great content!", tags=['queued', 'reblog'] ) dashboard = client.dashboard(limit=10, type='photo') for post in dashboard.get('posts', []): if 'photography' in post.get('tags', []): result = client.reblog( 'myblog.tumblr.com', id=post['id'], reblog_key=post['reblog_key'], comment="Beautiful photo!", tags=['photography', 'reblog'], state="queue" ) print(f"Reblogged post {post['id']}") ``` -------------------------------- ### Create Tumblr Link Posts with PyTumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Shows how to create link posts with various options including custom thumbnails, HTML descriptions, and slugs. Assumes a PyTumblr client is initialized. ```python # Create a simple link post result = client.create_link( 'myblog.tumblr.com', state="published", title="PyTumblr Documentation", url="https://github.com/tumblr/pytumblr", description="Official Python client for the Tumblr API", tags=['python', 'tumblr', 'api', 'documentation'] ) # Check result if result.get('meta', {}).get('status') == 201: print(f"Link post created! ID: {result['response']['id']}") # Create link with custom thumbnail result = client.create_link( 'myblog.tumblr.com', state="published", title="Amazing Article", url="https://example.com/article", description="This article changed my perspective on web development", thumbnail="https://example.com/thumbnail.jpg", tags=['web-development', 'articles', 'reading'] ) # Create link with HTML description result = client.create_link( 'myblog.tumblr.com', state="published", title="New Tool Release", url="https://newtool.com", description="
Check out this amazing new tool!
Listen to track 5 from our new album!
", external_url="https://soundcloud.com/track-url", format="html", tags=['music', 'album', 'release'] ) ``` ```python # Queue audio post queued_audio = client.create_audio( 'myblog.tumblr.com', state="queue", caption="Weekend vibes playlist", external_url="https://example.com/playlist.mp3", tags=['playlist', 'weekend', 'music'] ) ``` ```python # Create draft audio post draft_audio = client.create_audio( 'myblog.tumblr.com', state="draft", caption="Work in progress audio", data="/path/to/demo.mp3", tags=['wip', 'demo'] ) ``` -------------------------------- ### Like a Post (Python) Source: https://context7.com/tumblr/pytumblr/llms.txt This snippet demonstrates how to like a post given its ID and reblog key. It also shows how to like a post from the dashboard by iterating through posts. ```python # Like a post (requires post ID and reblog_key) post_id = 123456789 reblog_key = "abcdef123456" result = client.like(id=post_id, reblog_key=reblog_key) # Check if like was successful if result.get('meta', {}).get('status') == 200: print("Post liked successfully!") # Like posts from dashboard dashboard = client.dashboard(limit=10) for post in dashboard.get('posts', []): if 'cats' in post.get('tags', []): result = client.like( id=post['id'], reblog_key=post['reblog_key'] ) print(f"Liked post {post['id']}") ``` -------------------------------- ### Create Video Post using pytumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Enables the creation of video posts from YouTube/Vimeo embed codes or by uploading local video files. Supports states like published, queue, and draft, along with HTML captions. Requires a blog name and either an embed code or a local file path. ```python # Create video post with YouTube embed result = client.create_video( 'myblog.tumblr.com', state="published", caption="Amazing tutorial on Python programming", embed="", tags=['video', 'tutorial', 'python'] ) # Check result if result.get('meta', {}).get('status') == 201: print(f"Video post created! ID: {result['response']['id']}") ``` ```python # Upload local video file result = client.create_video( 'myblog.tumblr.com', state="published", caption="My vacation video from Hawaii", data="/path/to/local/video.mp4", tags=['vacation', 'hawaii', 'travel', 'video'] ) ``` ```python # Create video with HTML caption result = client.create_video( 'myblog.tumblr.com', state="published", caption="Check out our latest behind-the-scenes footage!
", embed="", format="html", tags=['video', 'behind-the-scenes', 'production'] ) ``` ```python # Queue video post queued_video = client.create_video( 'myblog.tumblr.com', state="queue", caption="Weekly video update", embed="", tags=['weekly', 'update', 'video'] ) ``` ```python # Create draft video draft_video = client.create_video( 'myblog.tumblr.com', state="draft", caption="Video draft for review", data="/path/to/draft-video.mp4", tags=['draft', 'review'] ) ``` -------------------------------- ### GET /tagged Source: https://context7.com/tumblr/pytumblr/llms.txt Fetches recent posts that contain a specific tag, with optional filters for content type, pagination, and timestamps. ```APIDOC ## GET /tagged ### Description Retrieves public posts across Tumblr that contain the specified tag. Supports limiting the number of results and filtering by content type or timestamp. ### Method GET ### Endpoint /tagged ### Parameters #### Query Parameters - **tag** (string) - Required - The tag to search for (e.g., "python"). - **limit** (integer) - Optional - Maximum number of posts to return (default 20, max 100). - **before** (integer) - Optional - Unix timestamp; returns posts created before this time. - **filter** (string) - Optional - Filter by post type (e.g., "text", "photo"). #### Path Parameters - *None* #### Request Body - *None* ### Request Example GET /tagged?tag=python&limit=20 ### Response #### Success Response (200) - **posts** (array) - List of post objects containing fields such as `blog_name`, `type`, `post_url`, `note_count`, and `tags`. ### Response Example [ { "blog_name": "exampleblog", "type": "photo", "post_url": "https://tumblr.com/post/123456", "note_count": 42, "tags": ["python", "coding"] }, { "blog_name": "anotherblog", "type": "text", "post_url": "https://tumblr.com/post/654321", "note_count": 15, "tags": ["python", "tips"] } ] ``` -------------------------------- ### Follow a Blog (Python) Source: https://context7.com/tumblr/pytumblr/llms.txt This snippet demonstrates how to follow a blog using different domain formats. It checks the response status and prints a success or error message. The function accepts various domain formats (blog name, full domain, custom domain). ```python result = client.follow('staff') # Automatically adds .tumblr.com # Or use full domain result = client.follow('staff.tumblr.com') # Or custom domain result = client.follow('blog.johnbunting.me') # Check if follow was successful if result.get('meta', {}).get('status') == 200: print("Successfully followed the blog!") else: print(f"Error: {result.get('meta', {}).get('msg', 'Unknown error')}") # Follow multiple blogs blogs_to_follow = ['staff', 'engineering', 'art'] for blog in blogs_to_follow: result = client.follow(blog) if result.get('meta', {}).get('status') == 200: print(f"Followed {blog}") ``` -------------------------------- ### Get User's Liked Posts in Python Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves posts liked by the authenticated user, including pagination with timestamps. The code prioritizes timestamp-based pagination over offset which is more reliable. ```Python # Get recent likes likes = client.likes(limit=20) # Process liked posts if likes.get('liked_posts'): for post in likes['liked_posts']: print(f"Liked post from: {post['blog_name']}") print(f"Post URL: {post['post_url']}") print(f"Liked at: {post.get('liked_timestamp')}") # Pagination using timestamps (preferred over offset) import time before_timestamp = int(time.time()) all_likes = [] while True: batch = client.likes(limit=20, before=before_timestamp) liked_posts = batch.get('liked_posts', []) if not liked_posts: break all_likes.extend(liked_posts) before_timestamp = liked_posts[-1]['liked_timestamp'] ``` -------------------------------- ### Create Tumblr Quote Posts with PyTumblr Source: https://context7.com/tumblr/pytumblr/llms.txt Demonstrates creating quote posts with different states (published, draft, queue) and options like HTML source and tweeting. Requires a connected Tumblr client instance. ```python result = client.create_quote( 'myblog.tumblr.com', state="published", quote="In the middle of difficulty lies opportunity.", source='Albert Einstein', format="html", tags=['einstein', 'quotes', 'wisdom'] ) # Create quote as draft draft_quote = client.create_quote( 'myblog.tumblr.com', state="draft", quote="Life is what happens when you're busy making other plans.", source="John Lennon" ) # Queue quote for posting queued_quote = client.create_quote( 'myblog.tumblr.com', state="queue", quote="The future belongs to those who believe in the beauty of their dreams.", source="Eleanor Roosevelt", tags=['quotes', 'dreams', 'future'] ) # Tweet quote automatically tweeted_quote = client.create_quote( 'myblog.tumblr.com', state="published", quote="Be yourself; everyone else is already taken.", source="Oscar Wilde", tweet="New quote posted! #quotes #wisdom", tags=['oscar-wilde', 'quotes'] ) ``` -------------------------------- ### Create Audio Post - PyTumblr Python Source: https://github.com/tumblr/pytumblr/blob/master/README.rst Creates an audio post with caption and either local file path or external URL. Cannot use both data and external_url parameters simultaneously. The data parameter requires a file path, while external_url points to hosted audio content. ```python #Creating an audio file client.create_audio(blogName, caption="Rock out.", data="/Users/johnb/Music/my/new/sweet/album.mp3") #lets use soundcloud! client.create_audio(blogName, caption="Mega rock out.", external_url="https://soundcloud.com/skrillex/sets/recess") ``` -------------------------------- ### Unlike a Post (Python) Source: https://context7.com/tumblr/pytumblr/llms.txt This snippet demonstrates how to unlike a post given its ID and reblog key. It checks the response status and prints a success or error message, including examples of unlikeing old posts. ```python # Unlike a post post_id = 123456789 reblog_key = "abcdef123456" result = client.unlike(id=post_id, reblog_key=reblog_key) # Check result if result.get('meta', {}).get('status') == 200: print("Post unliked successfully!") # Unlike old posts likes = client.likes(limit=50) for post in likes.get('liked_posts', []): if post.get('liked_timestamp', 0) < old_timestamp: result = client.unlike( id=post['id'], reblog_key=post['reblog_key'] ) print(f"Unliked post {post['id']}") ``` -------------------------------- ### Post Tags and Notes - PyTumblr Python Source: https://github.com/tumblr/pytumblr/blob/master/README.rst Demonstrates creating text posts with tags as lists and retrieving post notes. Tags must be passed as lists, not comma-separated strings. Notes retrieval supports pagination with timestamps. ```python client.create_text(blogName, tags=['hello', 'world'], ...) ``` ```python data = client.notes(blogName, id='123456') ``` ```python data = client.notes(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"]) ``` -------------------------------- ### Get Authenticated User Information in Python Source: https://context7.com/tumblr/pytumblr/llms.txt Retrieves information about the authenticated user. It provides access to user details like name, blogs, following count, and account details. The code checks for a status code of 200 before accessing user properties. ```Python # Get user information user_info = client.info() # Access user properties if user_info.get('meta', {}).get('status') == 200: user = user_info['user'] print(f"Username: {user['name']}") print(f"Following: {user['following']}") print(f"Likes: {user['likes']}) # List all blogs owned by the user for blog in user['blogs']: print(f"Blog: {blog['name']} - {blog['title']}") print(f" Posts: {blog['posts']}") print(f" URL: {blog['url']}") ``` -------------------------------- ### Create Tumblr Text Posts Source: https://github.com/tumblr/pytumblr/blob/master/README.rst Demonstrates how to create text posts with PyTumblr. Supports specifying a state, tags, slug, and optional title and body content, which can be formatted in HTML or markdown. ```python #Creating a text post client.create_text(blogName, state="published", slug="testing-text-posts", title="Testing", body="testing1 2 3 4") ```