code: def tumblr2fields(api_key, blogname):
      """Imports Tumblr posts (API v2)"""
      offset = 0
      posts = _get_tumblr_posts(api_key, blogname, offset)
      subs = DEFAULT_CONFIG["SLUG_REGEX_SUBSTITUTIONS"]
      while len(posts) > 0:
          for post in posts:
              title = (
                  post.get("title")
                  or post.get("source_title")
                  or post.get("type").capitalize()
              )
              slug = post.get("slug") or slugify(title, regex_subs=subs)
              tags = post.get("tags")
              timestamp = post.get("timestamp")
              date = SafeDatetime.fromtimestamp(
                  int(timestamp), tz=datetime.timezone.utc
              ).strftime("%Y-%m-%d %H:%M:%S%z")
              slug = (
                  SafeDatetime.fromtimestamp(
                      int(timestamp), tz=datetime.timezone.utc
                  ).strftime("%Y-%m-%d-")
                  + slug
              )
              format = post.get("format")
              content = post.get("body")
              type = post.get("type")
              if type == "photo":
                  if format == "markdown":
                      fmtstr = "![%s](%s)"
                  else:
                      fmtstr = '<img alt="%s" src="%s" />'
                  content = "\n".join(
                      fmtstr
                      % (
                          photo.get("caption"),
                          photo.get("original_size").get("url"),
                      )
                      for photo in post.get("photos")
                  )
              elif type == "quote":
                  if format == "markdown":
                      fmtstr = "\n\n&mdash; %s"
                  else:
                      fmtstr = "<p>&mdash; %s</p>"
                  content = post.get("text") + fmtstr % post.get(
                      "source"
                  )
              elif type == "link":
                  if format == "markdown":
                      fmtstr = "[via](%s)\n\n"
                  else:
                      fmtstr = '<p><a href="%s">via</a></p>\n'
                  content = fmtstr % post.get("url") + post.get(
                      "description"
                  )
              elif type == "audio":
                  if format == "markdown":
                      fmtstr = "[via](%s)\n\n"
                  else:
                      fmtstr = '<p><a href="%s">via</a></p>\n'
                  content = (
                      fmtstr % post.get("source_url")
                      + post.get("caption")
                      + post.get("player")
                  )
              elif type == "video":
                  if format == "markdown":
                      fmtstr = "[via](%s)\n\n"
                  else:
                      fmtstr = '<p><a href="%s">via</a></p>\n'
                  source = fmtstr % post.get("source_url")
                  caption = post.get("caption")
                  players = [
                      # If embed_code is False, couldn't get the video
                      player.get("embed_code") or None
                      for player in post.get("player")
                  ]
                  # If there are no embeddable players, say so, once
                  if len(players) > 0 and all(
                      player is None for player in players
                  ):
                      players = "<p>(This video isn't available anymore.)</p>\n"
                  else:
                      players = "\n".join(players)
                  content = source + caption + players
              elif type == "answer":
                  title = post.get("question")
                  content = (
                      "<p>"
                      '<a href="%s" rel="external nofollow">%s</a>'
                      ": %s"
                      "</p>\n"
                      " %s"
                      % (
                          post.get("asking_name"),
                          post.get("asking_url"),
                          post.get("question"),
                          post.get("answer"),
                      )
                  )
  
              content = content.rstrip() + "\n"
              kind = "article"
              status = "published"  # TODO: Find a way for draft posts
  
              yield (
                  title,
                  content,
                  slug,
                  date,
                  post.get("blog_name"),
                  [type],
                  tags,
                  status,
                  kind,
                  format,
              )
  
          offset += len(posts)
          posts = _get_tumblr_posts(api_key, blogname, offset)
  
imports: import argparse
  import datetime
  import logging
  import os
  import re
  import subprocess
  import sys
  import tempfile
  import time
  from collections import defaultdict
  from html import unescape
  from urllib.error import URLError
  from urllib.parse import quote, urlparse, urlsplit, urlunsplit
  from urllib.request import urlretrieve
  from pelican.log import init
  from pelican.settings import DEFAULT_CONFIG
  from pelican.utils import SafeDatetime, slugify
label_desc: Use image node_id 8 for calling a global function with example usage: tumblr2fields(api_key, blogname) without return types