Browse Source

feat: 支持facebook photo文章获取

wuwenyi 6 months ago
parent
commit
ac67b39cac
1 changed files with 4 additions and 2 deletions
  1. 4 2
      facebook/data_handler.py

+ 4 - 2
facebook/data_handler.py

@@ -22,11 +22,13 @@ def get_post_by_doc(response):
     # comet_sections.context_layout.story.comet_sections.actor_photo.story.actors
     actor = jsonpath.jsonpath(data, '$..comet_sections.context_layout.story.comet_sections.actor_photo.story.actors[0]')[0]
     actor = {k: v for k, v in actor.items() if k in user_require_fields}
+    image_candidates = jsonpath.jsonpath(data, '$..styles.attachment.all_subattachments.nodes')
+    photo_meida_candidate = jsonpath.jsonpath(data, '$..styles.attachment.media')
+    attachments = image_candidates[0] if image_candidates else photo_meida_candidate
     result = {
         'text': content_story['message']['text'],
-        'attachments': jsonpath.jsonpath(data, '$..styles.attachment.all_subattachments.nodes')[0],
+        'attachments': attachments,
         'post_id': content_story['post_id'],
-
         'actor': actor,
         'creation_time': jsonpath.jsonpath(data, '$..comet_sections.context_layout.story.comet_sections.metadata[0].story.creation_time')[0],
         'id': content_story['id'],