Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
PostDetailMetric is depreciated and use PostMetric instead
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmer0125 committed Oct 6, 2021
1 parent 407e66e commit ad9f24f
Showing 1 changed file with 53 additions and 18 deletions.
71 changes: 53 additions & 18 deletions python_fb_page_insights_client/fb_page_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,59 @@ class QueryValue(Enum):
fb_exchange_token = auto()


class PostDetailMetric(Enum):
""" support period: lifetime """
post_clicks_by_type = auto()
post_activity_by_action_type = auto()
post_reactions_like_total = auto()
post_reactions_love_total = auto()
post_reactions_wow_total = auto()
post_reactions_haha_total = auto()
# class PostDetailMetric(Enum):
# """ support period: lifetime """
# post_clicks_by_type = auto()
# post_activity_by_action_type = auto()
# post_reactions_like_total = auto()
# post_reactions_love_total = auto()
# post_reactions_wow_total = auto()
# post_reactions_haha_total = auto()

# not sure web uses it or below
# post_negative_feedback_by_type_unique = auto()
# post_negative_feedback_by_type = auto()


# class PostMetric(Enum):
# """ support period: lifetime """
# post_impressions_organic_unique = auto()
# post_clicks = auto()
# post_activity = auto()


class PostMetric(Enum):
""" support period: lifetime """
## web basic ##
post_impressions_organic_unique = auto()
post_clicks = auto()
post_activity = auto()

## web detail ##
post_clicks_by_type = auto()
post_activity_by_action_type = auto()
post_reactions_like_total = auto()
post_reactions_love_total = auto()
post_reactions_wow_total = auto()
post_reactions_haha_total = auto()


post_web_basic_metric_list = [PostMetric.post_impressions_organic_unique,
PostMetric.post_clicks,
PostMetric.post_activity
]
post_web_detail_metric_list = [PostMetric.post_clicks_by_type,
PostMetric.post_activity_by_action_type,
PostMetric.post_reactions_like_total,
PostMetric.post_reactions_love_total,
PostMetric.post_reactions_wow_total,
PostMetric.post_reactions_haha_total
]

post_web_basic_metric_set = set()
for metric in post_web_basic_metric_list:
post_web_basic_metric_set.add(metric.name)


class PageMetric(Enum):
""" support period: day/week/days_28/month """
Expand Down Expand Up @@ -662,10 +695,11 @@ def get_post_insight(self, post_id: str, basic_metric=True, complement_metric=Tr
if len(user_defined_metric_list) == 0:
metric_list = []
if basic_metric is True:
metric_list += [
e for e in PostMetric]
metric_list += post_web_basic_metric_list # [
# e for e in PostMetric]
if complement_metric is True:
metric_list += [e for e in PostDetailMetric]
# [e for e in PostDetailMetric]
metric_list += post_web_detail_metric_list
else:
metric_list = user_defined_metric_list
metric_value = self._convert_metric_list(metric_list)
Expand Down Expand Up @@ -783,7 +817,8 @@ def get_post_default_web_insight(self, page_id: str = None, since_date: Tuple[st
f"post insight error:P{post_insight.error.message}")
post_insight_data = post_insight.data
for post_insight in post_insight_data:
if post_insight.name in PostMetric.__members__:
# PostMetric.__members__:
if post_insight.name in post_web_basic_metric_set:
composite_data.insight_data.append(post_insight)
else:
composite_data.insight_data_complement.append(post_insight)
Expand Down Expand Up @@ -887,14 +922,14 @@ def _organize_to_web_posts_data_shape(self, posts_data: List[PostCompositeData],
for post_inisght_data in insight_data_complement:
key = post_inisght_data.name
# desc_dict[key] = post_inisght_data.description
if key == PostDetailMetric.post_activity_by_action_type.name:
if key == PostMetric.post_activity_by_action_type.name:
data = post_inisght_data.values[0].value
# on web, this value = sum(on post + on shares) but no api to get sub part
insight.likes = data.like
insight.comments = data.comment
insight.shares = data.share

elif key == PostDetailMetric.post_clicks_by_type.name:
elif key == PostMetric.post_clicks_by_type.name:
data = post_inisght_data.values[0].value

insight.photo_views = data.photo_view
Expand All @@ -912,13 +947,13 @@ def _organize_to_web_posts_data_shape(self, posts_data: List[PostCompositeData],
else:
value_obj = post_inisght_data.values[0]
value = value_obj.value
if key == PostDetailMetric.post_reactions_like_total.name:
if key == PostMetric.post_reactions_like_total.name:
insight.likes_like = value
elif key == PostDetailMetric.post_reactions_love_total.name:
elif key == PostMetric.post_reactions_love_total.name:
insight.likes_love = value
elif key == PostDetailMetric.post_reactions_wow_total.name:
elif key == PostMetric.post_reactions_wow_total.name:
insight.likes_wow = value
elif key == PostDetailMetric.post_reactions_haha_total.name:
elif key == PostMetric.post_reactions_haha_total.name:
insight.likes_haha = value

# e.g.
Expand Down

0 comments on commit ad9f24f

Please sign in to comment.