Beispiel #1
0
    async def get_chats(
        self,
        links: Optional[list[str]] = None,
        limit: int = 100,
        offset: int = 0,
        refresh: bool = True,
        inside_loop: bool = False,
    ) -> list[dict[str, Any]]:
        result, status = await api_helper.default_data(self, refresh)
        if status:
            return result
        if links is None:
            links = []
        api_count = self.chatMessagesCount
        if api_count and not links:
            link = endpoint_links(
                identifier=self.id, global_limit=limit, global_offset=offset
            ).list_chats
            ceil = math.ceil(api_count / limit)
            numbers = list(range(ceil))
            for num in numbers:
                num = num * limit
                link = link.replace(f"limit={limit}", f"limit={limit}")
                new_link = link.replace("offset=0", f"offset={num}")
                links.append(new_link)
        multiplier = self.session_manager.max_threads
        if links:
            link = links[-1]
        else:
            link = endpoint_links(
                identifier=self.id, global_limit=limit, global_offset=offset
            ).list_chats
        links_2 = api_helper.calculate_the_unpredictable(link, limit, multiplier)
        final_links = links
        if not inside_loop:
            final_links += links_2
        else:
            final_links = links_2
        results = await self.session_manager.async_requests(final_links)
        has_more = results[-1]["hasMore"]
        final_results = [x["list"] for x in results]
        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 has_more:
            results2 = await self.get_chats(
                links=[final_links[-1]],
                limit=limit,
                offset=limit + offset,
                inside_loop=True,
            )
            final_results.extend(results2)

        final_results.sort(key=lambda x: x["withUser"].id, reverse=True)
        self.chats = final_results
        return final_results
Beispiel #2
0
 async def get_highlights(
     self,
     identifier: int | str = "",
     refresh: bool = True,
     limit: int = 100,
     offset: int = 0,
     hightlight_id: int | str = "",
 ) -> Union[list[create_highlight], list[create_story]]:
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     if not identifier:
         identifier = self.id
     if not hightlight_id:
         link = endpoint_links(
             identifier=identifier, global_limit=limit, global_offset=offset
         ).list_highlights
         results = await self.get_session_manager().json_request(link)
         results = await api_helper.remove_errors(results)
         results = [create_highlight(x) for x in results]
     else:
         link = endpoint_links(
             identifier=hightlight_id, global_limit=limit, global_offset=offset
         ).highlight
         results = await self.get_session_manager().json_request(link)
         results = [create_story(x) for x in results["stories"]]
     return results
Beispiel #3
0
 async def get_highlights(self,
                          identifier="",
                          refresh=True,
                          limit=100,
                          offset=0,
                          hightlight_id="") -> list:
     api_type = "highlights"
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     if not identifier:
         identifier = self.id
     if not hightlight_id:
         link = endpoint_links(identifier=identifier,
                               global_limit=limit,
                               global_offset=offset).list_highlights
         results = await self.session_manager.json_request(link)
         results = [create_highlight(x) for x in results]
     else:
         link = endpoint_links(identifier=hightlight_id,
                               global_limit=limit,
                               global_offset=offset).highlight
         results = await self.session_manager.json_request(link)
         results = [create_story(x) for x in results["stories"]]
     return results
Beispiel #4
0
    def get_chats(
        self,
        links: Optional[list] = None,
        limit=100,
        offset=0,
        refresh=True,
        inside_loop=False,
    ) -> list:
        api_type = "chats"
        if not self.active:
            return []
        if not refresh:
            result = handle_refresh(self, api_type)
            if result:
                return result
        if links is None:
            links = []
        api_count = self.chatMessagesCount
        if api_count and not links:
            link = endpoint_links(identifier=self.id,
                                  global_limit=limit,
                                  global_offset=offset).list_chats
            ceil = math.ceil(api_count / limit)
            numbers = list(range(ceil))
            for num in numbers:
                num = num * limit
                link = link.replace(f"limit={limit}", f"limit={limit}")
                new_link = link.replace("offset=0", f"offset={num}")
                links.append(new_link)
        multiplier = self.session_manager.pool._processes
        if links:
            link = links[-1]
        else:
            link = endpoint_links(identifier=self.id,
                                  global_limit=limit,
                                  global_offset=offset).list_chats
        links2 = api_helper.calculate_the_unpredictable(
            link, limit, multiplier)
        if not inside_loop:
            links += links2
        else:
            links = links2
        results = self.session_manager.parallel_requests(links)
        has_more = results[-1]["hasMore"]
        final_results = [x["list"] for x in results]
        final_results = list(chain.from_iterable(final_results))

        if has_more:
            results2 = self.get_chats(links=[links[-1]],
                                      limit=limit,
                                      offset=limit + offset,
                                      inside_loop=True)
            final_results.extend(results2)

        final_results.sort(key=lambda x: x["withUser"]["id"], reverse=True)
        self.chats = final_results
        return final_results
Beispiel #5
0
 async def get_paid_content(
     self,
     check: bool = False,
     refresh: bool = True,
     limit: int = 10,
     offset: int = 0,
     inside_loop: bool = False,
 ) -> list[create_message | create_post] | ErrorDetails:
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     link = endpoint_links(global_limit=limit, global_offset=offset).paid_api
     final_results = await self.session_manager.json_request(link)
     if not isinstance(final_results, ErrorDetails):
         if len(final_results) > 0 and not check:
             results2 = await self.get_paid_content(
                 limit=limit, offset=limit + offset, inside_loop=True
             )
             final_results.extend(results2)
         if not inside_loop:
             temp: list[create_message | create_post] = []
             for final_result in final_results:
                 content = None
                 if final_result["responseType"] == "message":
                     user = create_user(final_result["fromUser"], self)
                     content = create_message(final_result, user)
                     print
                 elif final_result["responseType"] == "post":
                     user = create_user(final_result["author"], self)
                     content = create_post(final_result, user)
                 if content:
                     temp.append(content)
             final_results = temp
         self.paid_content = final_results
     return final_results
Beispiel #6
0
 async def get_message_by_id(
     self,
     user_id: Optional[int] = None,
     message_id: Optional[int] = None,
     refresh: bool = True,
     limit: int = 10,
     offset: int = 0,
 ):
     if not user_id:
         user_id = self.id
     link = endpoint_links(
         identifier=user_id,
         identifier2=message_id,
         global_limit=limit,
         global_offset=offset,
     ).message_by_id
     response = await self.get_session_manager().json_request(link)
     if isinstance(response, dict):
         temp_response: dict[str, Any] = response
         results: list[dict[str, Any]] = [
             x for x in temp_response["list"] if x["id"] == message_id
         ]
         result = results[0] if results else {}
         final_result = message_model.create_message(result, self)
         return final_result
     return response
Beispiel #7
0
    async def get_archived_posts(
        self,
        links: Optional[list[str]] = None,
        refresh: bool = True,
        limit: int = 10,
        offset: int = 0,
    ):
        result, status = await api_helper.default_data(self, refresh)
        if status:
            return result
        if links is None:
            links = []
        api_count = self.archivedPostsCount
        if api_count and not links:
            link = endpoint_links(
                identifier=self.id, global_limit=limit, global_offset=offset
            ).archived_posts
            ceil = math.ceil(api_count / limit)
            numbers = list(range(ceil))
            for num in numbers:
                num = num * limit
                link = link.replace(f"limit={limit}", f"limit={limit}")
                new_link = link.replace("offset=0", f"offset={num}")
                links.append(new_link)
        results = await api_helper.scrape_endpoint_links(
            links, self.get_session_manager()
        )
        final_results = self.finalize_content_set(results)

        self.temp_scraped.Archived.Posts = final_results
        return final_results
Beispiel #8
0
 async def get_archived_posts(self,
                              links: Optional[list] = None,
                              limit=10,
                              offset=0,
                              refresh=True) -> list:
     api_type = "archived_posts"
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     if links is None:
         links = []
     api_count = self.archivedPostsCount
     if api_count and not links:
         link = endpoint_links(identifier=self.id,
                               global_limit=limit,
                               global_offset=offset).archived_posts
         ceil = math.ceil(api_count / limit)
         numbers = list(range(ceil))
         for num in numbers:
             num = num * limit
             link = link.replace(f"limit={limit}", f"limit={limit}")
             new_link = link.replace("offset=0", f"offset={num}")
             links.append(new_link)
     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]
     self.temp_scraped.Archived.Posts = final_results
     return final_results
Beispiel #9
0
 async def get_lists(self, refresh: bool = True, limit: int = 100, offset: int = 0):
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     link = endpoint_links(global_limit=limit, global_offset=offset).lists
     results = await self.session_manager.json_request(link)
     self.lists = results
     return results
Beispiel #10
0
 def favorite(self):
     link = endpoint_links(
         identifier=f"{self.responseType}s",
         identifier2=self.id,
         identifier3=self.author["id"],
     ).favorite
     results = self.session_manager.json_request(link, method="POST")
     self.isFavorite = True
     return results
Beispiel #11
0
 async def get_user(
         self, identifier: Union[str,
                                 int]) -> Union[create_user, error_details]:
     link = endpoint_links(identifier).users
     response = await self.session_manager.json_request(link)
     if not isinstance(response, error_details):
         response["session_manager"] = self.session_manager
         response = create_user(response, self)
     return response
Beispiel #12
0
 async def get_post(self, identifier=None, limit=10, offset=0):
     if not identifier:
         identifier = self.id
     link = endpoint_links(identifier=identifier,
                           global_limit=limit,
                           global_offset=offset).post_by_id
     result = await self.session_manager.json_request(link)
     final_result = create_post(result, self)
     return final_result
Beispiel #13
0
 async def search_chat(
     self, identifier="", text="", refresh=True, limit=10, offset=0
 ):
     if identifier:
         identifier = parse.urljoin(identifier, "messages")
     link = endpoint_links(
         identifier=identifier, text=text, global_limit=limit, global_offset=offset
     ).search_chat
     results = await self.session_manager.json_request(link)
     return results
Beispiel #14
0
 def get_archived_stories(self, refresh=True, limit=100, offset=0):
     api_type = "archived_stories"
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     link = endpoint_links(global_limit=limit,
                           global_offset=offset).archived_stories
     results = self.session_manager.json_request(link)
     self.archived_stories = results
     return results
Beispiel #15
0
 async def get_lists(self, refresh=True, limit=100, offset=0):
     api_type = "lists"
     if not self.active:
         return
     if not refresh:
         subscriptions = handle_refresh(self, api_type)
         return subscriptions
     link = endpoint_links(global_limit=limit, global_offset=offset).lists
     results = await self.session_manager.json_request(link)
     self.lists = results
     return results
Beispiel #16
0
 async def get_comments(self):
     api_type = "comments"
     final_results: list[Any] = []
     epl = endpoint_links()
     link = epl.list_comments(self.responseType, self.id)
     links = epl.create_links(link, self.commentsCount)
     if links:
         results = await api_helper.scrape_endpoint_links(
             links, self.author.get_session_manager(), api_type)
         self.comments = results
     return final_results
Beispiel #17
0
    async def get_messages(
        self,
        links: Optional[list] = None,
        limit=10,
        offset=0,
        refresh=True,
        inside_loop=False,
    ) -> list:
        api_type = "messages"
        if not self.subscriber or self.is_me():
            return []
        if not refresh:
            result = handle_refresh(self, api_type)
            if result:
                return result
        if links is None:
            links = []
        multiplier = getattr(self.session_manager.pool, "_processes")
        if links:
            link = links[-1]
        else:
            link = endpoint_links(identifier=self.id,
                                  global_limit=limit,
                                  global_offset=offset).message_api
            links.append(link)
        links2 = api_helper.calculate_the_unpredictable(
            link, limit, multiplier)
        if not inside_loop:
            links += links2
        else:
            links = links2
        results = await self.session_manager.async_requests(links)
        results = await api_helper.remove_errors(results)
        results = [x for x in results if x]
        has_more = results[-1]["hasMore"] if results else False
        final_results = [x["list"] for x in results if "list" in x]
        final_results = list(chain.from_iterable(final_results))

        if has_more:
            results2 = await self.get_messages(links=[links[-1]],
                                               limit=limit,
                                               offset=limit + offset,
                                               inside_loop=True)
            final_results.extend(results2)
        print
        if not inside_loop:
            final_results = [
                create_message.create_message(x, self) for x in final_results
                if x
            ]
        else:
            final_results.sort(key=lambda x: x["fromUser"]["id"], reverse=True)
        self.temp_scraped.Messages = final_results
        return final_results
Beispiel #18
0
 async def get_archived_stories(self, refresh=True, limit=100, offset=0):
     api_type = "archived_stories"
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     link = endpoint_links(global_limit=limit, global_offset=offset).archived_stories
     results = await self.session_manager.json_request(link)
     results = await remove_errors(results)
     results = [create_story(x) for x in results]
     return results
Beispiel #19
0
 async def get_archived_stories(
     self, refresh: bool = True, limit: int = 100, offset: int = 0
 ):
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     link = endpoint_links(global_limit=limit, global_offset=offset).archived_stories
     results = await self.get_session_manager().json_request(link)
     results = await api_helper.remove_errors(results)
     results = [create_story(x) for x in results]
     return results
Beispiel #20
0
    async def get_messages(
        self,
        links: Optional[list[str]] = None,
        limit: int = 10,
        offset: int = 0,
        refresh: bool = True,
        inside_loop: bool = False,
    ):
        result, status = await api_helper.default_data(self, refresh)
        if status:
            return result
        if links is None:
            links = []
        multiplier = self.get_session_manager().max_threads
        if links:
            link = links[-1]
        else:
            link = endpoint_links(
                identifier=self.id, global_limit=limit, global_offset=offset
            ).message_api
            links.append(link)
        links2 = api_helper.calculate_the_unpredictable(link, limit, multiplier)
        if not inside_loop:
            links += links2
        else:
            links = links2
        results = await self.get_session_manager().async_requests(links)
        results = await api_helper.remove_errors(results)
        final_results = []
        if isinstance(results, list):
            results = [x for x in results if x]
            has_more = results[-1]["hasMore"] if results else False
            final_results = [x["list"] for x in results if "list" in x]
            final_results = list(chain.from_iterable(final_results))

            if has_more:
                results2 = await self.get_messages(
                    links=[links[-1]],
                    limit=limit,
                    offset=limit + offset,
                    inside_loop=True,
                )
                final_results.extend(results2)
            print
            if not inside_loop:
                final_results = [
                    message_model.create_message(x, self) for x in final_results if x
                ]
            else:
                final_results.sort(key=lambda x: x["fromUser"]["id"], reverse=True)
            self.temp_scraped.Messages = final_results
        return final_results
Beispiel #21
0
 async def process_auth(self):
     if not self.active:
         link = endpoint_links().customer
         response = await self.session_manager.json_request(link)
         if response:
             await self.resolve_auth_errors(response)
             if not self.errors:
                 self.active = True
                 self.update(response)
         else:
             # 404'ed
             self.active = False
     return self
Beispiel #22
0
 async def get_post(
     self, identifier=None, limit=10, offset=0
 ) -> Union[create_post, error_details]:
     if not identifier:
         identifier = self.id
     link = endpoint_links(
         identifier=identifier, global_limit=limit, global_offset=offset
     ).post_by_id
     response = await self.session_manager.json_request(link)
     if isinstance(response, dict):
         final_result = create_post(response, self)
         return final_result
     return response
Beispiel #23
0
 def get_authed(self):
     if not self.active:
         link = endpoint_links().customer
         r = self.session_manager.json_request(
             link, self.session_manager.sessions[0], sleep=False)
         if r:
             self.resolve_auth_errors(r)
             if not self.errors:
                 self.active = True
                 self.update(r)
         else:
             # 404'ed
             self.active = False
     return self
Beispiel #24
0
 async def get_post(
     self, identifier: Optional[int | str] = None, limit: int = 10, offset: int = 0
 ) -> Union[create_post, ErrorDetails]:
     if not identifier:
         identifier = self.id
     link = endpoint_links(
         identifier=identifier, global_limit=limit, global_offset=offset
     ).post_by_id
     result = await self.get_session_manager().json_request(link)
     if isinstance(result, dict):
         temp_result: dict[str, Any] = result
         final_result = post_model.create_post(temp_result, self)
         return final_result
     return result
Beispiel #25
0
 async def get_authed(self):
     if not self.active:
         link = endpoint_links().customer
         response = await self.session_manager.json_request(link)
         if response:
             self.resolve_auth_errors(response)
             if not self.errors:
                 # merged = self.__dict__ | response
                 # self = create_auth(merged,self.pool,self.session_manager.max_threads)
                 self.active = True
                 self.update(response)
         else:
             # 404'ed
             self.active = False
     return self
Beispiel #26
0
 async def get_lists_users(
     self, identifier, check: bool = False, refresh=True, limit=100, offset=0
 ):
     if not self.active:
         return
     link = endpoint_links(
         identifier, global_limit=limit, global_offset=offset
     ).lists_users
     results = await self.session_manager.json_request(link)
     if len(results) >= limit and not check:
         results2 = await self.get_lists_users(
             identifier, limit=limit, offset=limit + offset
         )
         results.extend(results2)
     return results
Beispiel #27
0
 def search_messages(self,
                     identifier="",
                     text="",
                     refresh=True,
                     limit=10,
                     offset=0):
     if identifier:
         identifier = parse.urljoin(identifier, "messages")
     text = parse.quote_plus(text)
     link = endpoint_links(identifier=identifier,
                           text=text,
                           global_limit=limit,
                           global_offset=offset).search_messages
     session = self.session_manager.sessions[0]
     results = self.session_manager.json_request(link)
     return results
Beispiel #28
0
 async def search_messages(
     self,
     identifier: int | str = "",
     text: str = "",
     refresh: bool = True,
     limit: int = 10,
     offset: int = 0,
 ):
     # Onlyfans can't do a simple search, so this is broken. If you want it to "work", don't use commas, or basically any mysql injection characters (lol)
     if identifier:
         identifier = parse.urljoin(str(identifier), "messages")
     text = parse.quote_plus(text)
     link = endpoint_links(
         identifier=identifier, text=text, global_limit=limit, global_offset=offset
     ).search_messages
     results = await self.get_session_manager().json_request(link)
     return results
Beispiel #29
0
 async def get_stories(
     self, refresh: bool = True, limit: int = 100, offset: int = 0
 ) -> list[create_story]:
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     link = [
         endpoint_links(
             identifier=self.id, global_limit=limit, global_offset=offset
         ).stories_api
     ]
     results = await api_helper.scrape_endpoint_links(
         link, self.get_session_manager()
     )
     results = [create_story(x) for x in results]
     self.temp_scraped.Stories = results
     return results
Beispiel #30
0
 async def buy_message(self):
     """
     This function will buy a ppv message from a model.
     """
     message_price = self.price
     x = {
         "amount": message_price,
         "messageId": self.id,
         "paymentType": "message",
         "token": "",
         "unavailablePaymentGates": [],
     }
     link = endpoint_links().pay
     result = await self.user.session_manager.json_request(link,
                                                           method="POST",
                                                           payload=x)
     return result