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

Commit

Permalink
Fixed KeyError: 'author' error
Browse files Browse the repository at this point in the history
It was due to posts being reported.
  • Loading branch information
DIGITALCRIMINAL committed Oct 16, 2021
1 parent f28910c commit 6392f87
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apis/api_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ def restore_missing_data(master_set2, media_set, split_by):
return new_set


async def scrape_endpoint_links(links, session_manager: session_manager, api_type):
media_set = []
async def scrape_endpoint_links(links:list[str], session_manager: Union[session_manager,None], api_type:str):
media_set:list[dict[str,str]] = []
max_attempts = 100
api_type = api_type.capitalize()
for attempt in list(range(max_attempts)):
Expand Down Expand Up @@ -404,8 +404,8 @@ async def scrape_endpoint_links(links, session_manager: session_manager, api_typ
else:
media_set.extend(not_faulty)
break
media_set = list(chain(*media_set))
return media_set
final_media_set = list(chain(*media_set))
return final_media_set


def calculate_the_unpredictable(link, limit, multiplier=1):
Expand Down
2 changes: 1 addition & 1 deletion apis/onlyfans/classes/create_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, option, user) -> None:
self.postedAt: str = option.get("postedAt")
self.postedAtPrecise: str = option.get("postedAtPrecise")
self.expiredAt: Any = option.get("expiredAt")
self.author = create_user.create_user(option["author"])
self.author = create_user.create_user(option.get("author", {}))
self.text: str = option.get("text")
self.rawText: str = option.get("rawText")
self.lockedText: bool = option.get("lockedText")
Expand Down
26 changes: 19 additions & 7 deletions apis/onlyfans/classes/create_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def is_me(self) -> bool:
status = True
return status

async def get_stories(self, refresh=True, limit=100, offset=0) -> list[create_story]:
async def get_stories(
self, refresh=True, limit=100, offset=0
) -> list[create_story]:
api_type = "stories"
if not refresh:
result = handle_refresh(self, api_type)
Expand All @@ -251,7 +253,7 @@ async def get_stories(self, refresh=True, limit=100, offset=0) -> list[create_st

async def get_highlights(
self, identifier="", refresh=True, limit=100, offset=0, hightlight_id=""
) -> Union[list[create_highlight] , list[create_story]]:
) -> Union[list[create_highlight], list[create_story]]:
api_type = "highlights"
if not refresh:
result = handle_refresh(self, api_type)
Expand All @@ -275,7 +277,7 @@ async def get_highlights(
return results

async def get_posts(
self, links: Optional[list] = None, limit=10, offset=0, refresh=True
self, links: Optional[list[str]] = None, limit=10, offset=0, refresh=True
) -> Optional[list[create_post]]:
api_type = "posts"
if not refresh:
Expand All @@ -299,9 +301,7 @@ async def get_posts(
results = await api_helper.scrape_endpoint_links(
links, self.session_manager, api_type
)
# Filter out posts that are reported by the user as these will not have content
filtered_results = list(filter(lambda opt: not ("isReportedByMe" in opt and opt["isReportedByMe"]), results))
final_results = [create_post(x, self) for x in filtered_results]
final_results = self.finalize_content_set(results)
self.temp_scraped.Posts = final_results
return final_results

Expand Down Expand Up @@ -427,7 +427,8 @@ async def get_archived_posts(
results = await api_helper.scrape_endpoint_links(
links, self.session_manager, api_type
)
final_results = [create_post(x, self) for x in results if x]
final_results = self.finalize_content_set(results)

self.temp_scraped.Archived.Posts = final_results
return final_results

Expand Down Expand Up @@ -516,3 +517,14 @@ async def buy_subscription(self):

def set_scraped(self, name, scraped):
setattr(self.scraped, name, scraped)
def finalize_content_set(self,results:list[dict[str,str]]):
final_results:list[create_post] = []
for result in results:
content_type = result["responseType"]
match content_type:
case "post":
created = create_post(result,self)
final_results.append(created)
case _:
print
return final_results

0 comments on commit 6392f87

Please sign in to comment.