Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes for handling deactivated models #15

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion ultima_scraper_api/apis/api_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async def remove_errors(results: Any):
final_results.append(results)
else:
final_results = results
final_results = [x for x in final_results if not isinstance(x, error_types)]
final_results = [x for x in final_results if not isinstance(x, error_types) and not (isinstance(x, dict) and "error" in x)]
if wrapped and final_results:
final_results = final_results[0]
return final_results
Expand Down
8 changes: 5 additions & 3 deletions ultima_scraper_api/apis/fansly/classes/auth_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def get_user(self, identifier: int | str):
url = endpoint_links(identifier).users_by_username
pass
response = await self.session_manager.json_request(url)
if "error" not in response:
if response["response"]:
response["session_manager"] = self.session_manager
response = create_user(response["response"][0], self)
return response
Expand Down Expand Up @@ -300,6 +300,8 @@ async def get_chats(
for account in aggregationData["accounts"]:
if result["partnerAccountId"] == account["id"]:
result["withUser"] = create_user(account, self)
if "withUser" not in result:
continue
for group in aggregationData["groups"]:
found_user = [
x
Expand All @@ -311,13 +313,13 @@ async def get_chats(
result["lastMessage"] = create_message(
last_message, result["withUser"]
)
final_results = final_results["data"]
final_results = [x for x in final_results["data"] if "withUser" in x]
final_results.sort(key=lambda x: x["withUser"].id, reverse=True)
self.chats = final_results
return final_results

async def get_scrapable_users(self):
followed_users = self.followed_users
subscription_users = [x.user for x in self.subscriptions]
subscription_users = [x.user for x in self.subscriptions if x.user.active]
unique_users = list(set(followed_users) | set(subscription_users))
return unique_users
7 changes: 4 additions & 3 deletions ultima_scraper_api/apis/onlyfans/classes/auth_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ async def get_chats(
final_results = list(chain.from_iterable(final_results))
for result in final_results:
result["withUser"] = create_user(result["withUser"], self)
result["lastMessage"] = create_message(
result["lastMessage"], result["withUser"]
)
if result["lastMessage"]:
result["lastMessage"] = create_message(
result["lastMessage"], result["withUser"]
)

if has_more:
results2 = await self.get_chats(
Expand Down