@gen.coroutine
  def _RepairMissingPosts(self, activities, existing_posts):
    @gen.coroutine
    def _RebuildActivity(activity, act_args):
      rebuilt_episodes = []
      for ep_dict in act_args['episodes']:
        if ep_dict['episode_id'] in existing_posts:
          new_ep_dict = {'episode_id': ep_dict['episode_id']}
          for photo_id in list(ep_dict['photo_ids']):
            if photo_id in existing_posts[ep_dict['episode_id']]:
              new_ep_dict.setdefault('photo_ids', []).append(photo_id)
          rebuilt_episodes.append(new_ep_dict)
        else:
          # Rebuilding the activity is problematic without any posts in an episode.  Creating an activity with an
          #   empty episode will lead to other dbchk errors.  Currently, there are no known cases of this, so we'll
          #   just log it and skip processing of this activity for now.  If we ever hit a
          #   case of this, we can address it then.
          logging.warning('  unable to rebuild activity: %s; missing all posts for episode: %s',
                          activity.activity_id,
                          ep_dict['episode_id'])
          return
      act_args['episodes'] = rebuilt_episodes
      update_activity = Activity.CreateFromKeywords(viewpoint_id=activity.viewpoint_id,
                                                    activity_id=activity.activity_id,
                                                    name=activity.name,
                                                    json=json.dumps(act_args))
      yield gen.Task(update_activity.Update, self._client)
      logging.warning('  updated activity: %s', activity.activity_id)

    def _IsEpisodeMissingAnyPosts(ep_dict):
      for photo_id in ep_dict['photo_ids']:
        if photo_id not in existing_posts[ep_dict['episode_id']]:
          return True
      return False

    for activity in activities:
      if activity.name in ['share_new', 'share_existing']:
        act_args = json.loads(activity.json)
        for ep_dict in act_args['episodes']:
          if ep_dict['episode_id'] not in existing_posts or _IsEpisodeMissingAnyPosts(ep_dict):
            yield _RebuildActivity(activity, act_args)
            # Move on to next activity.
            break
Produce code for a single object
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/tools/dbchk.py/DatabaseChecker._RepairMissingPosts--crossover with--dataset/ETHPy150Open correl/Transmission-XBMC/resources/lib/basictypes/xmlgenerator.py/Store.handleObject