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

Commit

Permalink
Add PageStoryValue and PostReactionType [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmer0125 committed Oct 28, 2021
1 parent f1858f0 commit 4c21100
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions python_fb_page_insights_client/fb_page_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PostMetric(Enum):
post_engaged_fan = auto()
# post_clicks
post_clicks_unique = auto()
# post_clicks_by_type
# x post_clicks_by_type
# "value": {
# "other clicks": 147,
# "photo view": 9,
Expand All @@ -116,7 +116,7 @@ class PostMetric(Enum):
post_impressions_viral_unique = auto()
post_impressions_nonviral = auto()
post_impressions_nonviral_unique = auto()
# "value": {
# x "value": { # PageStoryValue
# "other": 6502
# }
post_impressions_by_story_type = auto() # by type
Expand All @@ -125,15 +125,15 @@ class PostMetric(Enum):
# Page Post Reactions
post_reactions_sorry_total = auto()
post_reactions_anger_total = auto()
# "value": {
# x "value": {
# "like": 69,
# "love": 1
# }
post_reactions_by_type_total = auto() # by type

# Stories
post_activity_unique = auto()
# "value": {
# x "value": { # PostActivityValue
# "share": 13,
# "like": 58,
# "comment": 6
Expand Down Expand Up @@ -178,14 +178,22 @@ class PostMetric(Enum):
post_video_view_time = auto()
post_video_view_time_organic = auto()
# "data": [] ????
# TODO 1: like page_impressions_by_age_gender_unique?
post_video_view_time_by_age_bucket_and_gender = auto()
# "value": {}
# "values": [
# {
# "value": {} // usually it is just a simple "value": 0
# }
# ],
# TODO: find a sample !!!!???
post_video_view_time_by_region_id = auto()
# "value": {}
# TODO: like page_impressions_viral_frequency_distribution?
post_video_views_by_distribution_type = auto()
# "value": {}
# "value": {},
post_video_view_time_by_distribution_type = auto()
# "value": {}
# should like page_impressions_by_country_unique
post_video_view_time_by_country_id = auto()

# Video Ad Breaks
Expand Down Expand Up @@ -349,7 +357,7 @@ class PageMetric(Enum):
page_impressions_viral_unique = auto()
page_impressions_nonviral = auto()
page_impressions_nonviral_unique = auto()
# "page post": 422,
# x "page post": 422,
# "other": 10
page_impressions_by_story_type = auto()
page_impressions_by_story_type_unique = auto()
Expand Down Expand Up @@ -385,7 +393,7 @@ class PageMetric(Enum):
# "3": 1,
# "5": 1,
# "6-10": 4
# },
# },
page_impressions_viral_frequency_distribution = auto()

# Page Posts
Expand Down Expand Up @@ -486,7 +494,7 @@ class PageMetric(Enum):
# "none": 13
page_views_by_referers_logged_in_unique = auto()

# Stories:
# x Stories:
# "fan": 56,
# "other": 262,
# "mention": 4,
Expand All @@ -498,9 +506,17 @@ class PageMetric(Enum):
page_content_activity_by_country_unique = auto()
page_content_activity_by_locale_unique = auto()
page_content_activity = auto()
# x PageStoryValue
# "fan": 4,
# "page post": 2,
# "other": 29
# {
# "value": {
# "other": 12,
# "fan": 10
# },
# "end_time": "2021-10-25T07:00:00+0000"
# },
page_content_activity_by_action_type = auto() # by type

# Video Ad Breaks
Expand Down Expand Up @@ -541,7 +557,29 @@ class PostClickValue(BaseModel):
other_clicks: int = Field(None, alias="other clicks")


class ByTypeValue(PostActivityValue, PostClickValue):
class PageStoryValue(BaseModel):
# use by Page & Page, too
checkin: int = None
coupon: int = None
event: int = None
fan: int = None
mention: int = None
page_post: int = Field(None, alias="page post")
question: int = None
user_post: int = Field(None, alias="user post")
other: int = None


class PostReactionType(BaseModel):
sorry: Optional[int]
anger: Optional[int]
like: Optional[int]
love: Optional[int]
wow: Optional[int]
haha: Optional[int]


class ByTypeValue(PostActivityValue, PostClickValue, PageStoryValue, PostReactionType):
"""since pydantic union has some bug, so combine them (intersection)"""

# TODO: add more ByTypeValue, e.g. page_positive_feedback_by_type
Expand Down Expand Up @@ -1271,7 +1309,8 @@ def _organize_to_web_page_data_shape(
"""currently it only support one period, it querying with on specific period in low level api,
will return multiple periods"""

insight_dict: Dict[int:PageDefaultWebInsight] = {}
# TODO: test it, previously it is using [int, PageDefaultWebInsight]
insight_dict: Dict[int, PageDefaultWebInsight] = {}

for page_insight_data in page_data:
key = page_insight_data.name
Expand Down

0 comments on commit 4c21100

Please sign in to comment.