Пример #1
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 = await 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.session_manager.json_request(link)
         results = [create_story(x) for x in results["stories"]]
     return results
Пример #2
0
    async 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 = getattr(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 = await self.session_manager.async_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 = await 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
Пример #3
0
 async def get_posts(self,
                     links: Optional[list] = None,
                     limit: int = 10,
                     offset: int = 0,
                     refresh=True) -> Optional[list[create_post]]:
     api_type = "posts"
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     if links is None:
         links = []
     temp_results: list[Any] = []
     while True:
         link = endpoint_links(identifier=self.id,
                               global_offset=offset).post_api
         response = await self.session_manager.json_request(link)
         data = response["response"]
         temp_posts = data["posts"]
         if not temp_posts:
             break
         offset = temp_posts[-1]["id"]
         temp_results.append(data)
     results: dict[Any, Any] = merge({},
                                     *temp_results,
                                     strategy=Strategy.ADDITIVE)
     final_results = [
         create_post(x, self, results) for x in results["posts"]
     ]
     self.temp_scraped.Posts = final_results
     return final_results
Пример #4
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
Пример #5
0
 async def get_posts(
     self,
     links: Optional[list[str]] = None,
     limit: int = 10,
     offset: int = 0,
     refresh: bool = True,
 ) -> list[create_post]:
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     temp_results: list[Any] = []
     while True:
         link = endpoint_links(identifier=self.id, global_offset=offset).post_api
         response = await self.get_session_manager().json_request(link)
         data = response["response"]
         temp_posts = data.get("posts")
         if not temp_posts:
             break
         offset = temp_posts[-1]["id"]
         temp_results.append(data)
     results = api_helper.merge_dictionaries(temp_results)
     final_results = []
     if results:
         final_results = [
             post_model.create_post(x, self, results) for x in results["posts"]
         ]
         self.temp_scraped.Posts = final_results
     return final_results
Пример #6
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
Пример #7
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
Пример #8
0
 async def get_authed(self):
     if not self.active:
         link = endpoint_links().settings
         response = await self.session_manager.json_request(link)
         if isinstance(response, dict):
             link = endpoint_links(response["response"]["accountId"]).customer
             response = await self.session_manager.json_request(link)
             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
Пример #9
0
 async def get_groups(self) -> ErrorDetails | dict[str, Any]:
     link = endpoint_links().groups_api
     response: ErrorDetails | dict[
         str, Any
     ] = await self.get_session_manager().json_request(link)
     if isinstance(response, dict):
         final_response: dict[str, Any] = response["response"]
         return final_response
     return response
Пример #10
0
 async def favorite(self):
     link = endpoint_links(
         identifier=f"{self.responseType}s",
         identifier2=self.id,
         identifier3=self.author.id,
     ).favorite
     results = await self.user.session_manager.json_request(link, method="POST")
     self.isFavorite = True
     return results
Пример #11
0
    async def get_subscriptions(
        self, refresh: bool = True, identifiers: list[int | str] = []
    ) -> list[create_user]:
        result, status = await api_helper.default_data(self, refresh)
        if status:
            return result
        subscriptions_link = endpoint_links().subscriptions
        temp_subscriptions = await self.session_manager.json_request(subscriptions_link)
        subscriptions = temp_subscriptions["response"]["subscriptions"]

        # If user is a creator, add them to the subscription list
        results: list[list[create_user]] = []
        if self.isPerformer:
            subscription = await self.convert_to_user()
            if isinstance(subscription, ErrorDetails):
                return result
            subscription.subscribedByData = {}
            new_date = datetime.now() + relativedelta(years=1)
            subscription.subscribedByData["expiredAt"] = new_date.isoformat()
            subscriptions_ = [subscription]
            results.append(subscriptions_)
        if not identifiers:

            async def multi(item: dict[str, Any]):
                subscription = await self.get_user(item["accountId"])
                valid_subscriptions: list[create_user] = []

                if (
                    isinstance(subscription, create_user)
                    and subscription.following
                    and not subscription.subscribedByData
                ):
                    new_date = datetime.now() + relativedelta(years=1)
                    new_date = int(new_date.timestamp() * 1000)
                    subscription.subscribedByData = {}
                    subscription.subscribedByData["endsAt"] = new_date
                    valid_subscriptions.append(subscription)
                return valid_subscriptions

            pool = self.pool
            tasks = pool.starmap(multi, product(subscriptions))
            results += await asyncio.gather(*tasks)
        else:
            for identifier in identifiers:
                results_2 = await self.get_user(identifier)
                results_2 = await api_helper.remove_errors(results_2)
                if isinstance(results_2, create_user):
                    x = [x for x in subscriptions if x["accountId"] == results_2.id]
                    if x:
                        results_2.subscribedByData = {}
                        results_2.subscribedByData["endsAt"] = x[0]["endsAt"]
                    results.append([results_2])
        results = [x for x in results if x is not None]
        results = list(chain(*results))
        self.subscriptions = results
        return results
Пример #12
0
 async def get_user(self, identifier: int | str) -> Union[create_user, ErrorDetails]:
     link = endpoint_links().list_users([identifier])
     response = await self.session_manager.json_request(link)
     if not isinstance(response, ErrorDetails):
         if response["response"]:
             response["session_manager"] = self.session_manager
             response = create_user(response["response"][0], self)
         else:
             response = ErrorDetails({"code": 69, "message": "User Doesn't Exist"})
     return response
Пример #13
0
 async def get_followings(self, identifiers: list[str]) -> list[create_user]:
     followings_link = endpoint_links(self.id).followings
     temp_followings: dict[str, Any] = await self.session_manager.json_request(
         followings_link
     )
     followings = temp_followings["response"]
     if followings:
         followings_id: str = ",".join([x["accountId"] for x in followings])
         customer_link = endpoint_links(followings_id).customer
         followings = await self.session_manager.json_request(customer_link)
         followings = [create_user(x, self) for x in followings["response"]]
         for following in followings:
             if not following.subscribedByData:
                 new_date = datetime.now() + relativedelta(years=1)
                 new_date = new_date.timestamp()
                 following.subscribedByData = {}
                 following.subscribedByData["endsAt"] = new_date
                 print
     return followings
Пример #14
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
Пример #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
Пример #16
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
Пример #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 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
Пример #18
0
 async def get_user(
     self, identifier: Union[str, int]
 ) -> Union[create_user, error_details]:
     link = endpoint_links(identifier).customer
     response = await self.session_manager.json_request(link)
     if not isinstance(response, error_details):
         if response["response"]:
             response["session_manager"] = self.session_manager
             response = create_user(response["response"][0], self)
         else:
             response = error_details({"code": 69, "message": "User Doesn't Exist"})
     return response
Пример #19
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
Пример #20
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, temp_result)
         return final_result
     return result
Пример #21
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
Пример #22
0
 async def get_followings(self, identifiers: list[int | str]) -> list[create_user]:
     offset_count = 0
     followings: list[dict[str, Any]] = []
     while True:
         followings_link = endpoint_links().list_followings(self.id, offset_count)
         temp_followings: dict[str, Any] = await self.session_manager.json_request(
             followings_link
         )
         account_ids = temp_followings["response"]
         if account_ids:
             followings.extend(account_ids)
             offset_count += 100
         else:
             break
     final_followings: list[create_user] = []
     if followings:
         followings_id: str = ",".join([x["accountId"] for x in followings])
         customer_link = endpoint_links(followings_id).customer
         temp_followings = await self.session_manager.json_request(customer_link)
         if identifiers:
             final_followings = [
                 create_user(x, self)
                 for x in temp_followings["response"]
                 for identifier in identifiers
                 if x["username"] == identifier or x["id"] == identifier
             ]
         else:
             final_followings = [
                 create_user(x, self) for x in temp_followings["response"]
             ]
         for following in final_followings:
             if not following.subscribedByData:
                 new_date = datetime.now() + relativedelta(years=1)
                 new_date = int(new_date.timestamp() * 1000)
                 following.subscribedByData = {}
                 following.subscribedByData["endsAt"] = new_date
     return final_followings
Пример #23
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
Пример #24
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.session_manager)
     results = [create_story(x) for x in results]
     self.temp_scraped.Stories = results
     return results
Пример #25
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
Пример #26
0
 async def get_stories(self, refresh=True, limit=100, offset=0) -> list:
     api_type = "stories"
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     if not self.hasStories:
         return []
     link = [
         endpoint_links(identifier=self.id,
                        global_limit=limit,
                        global_offset=offset).stories_api
     ]
     results = await api_helper.scrape_endpoint_links(
         link, self.session_manager, api_type)
     results = [create_story(x) for x in results]
     self.temp_scraped.Stories = results
     return results
Пример #27
0
 async def get_message_by_id(
     self, user_id=None, message_id=None, refresh=True, limit=10, offset=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.session_manager.json_request(link)
     if isinstance(response, dict):
         results = [x for x in 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
Пример #28
0
 async def get_paid_content(
     self,
     check: bool = False,
     refresh: bool = True,
     limit: int = 99,
     offset: int = 0,
     inside_loop: bool = False,
 ) -> list[Union[create_message, create_post]]:
     return []
     api_type = "paid_content"
     if not self.active:
         return []
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             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, error_details):
         if len(final_results) >= limit and not check:
             results2 = self.get_paid_content(limit=limit,
                                              offset=limit + offset,
                                              inside_loop=True)
             final_results.extend(results2)
         if not inside_loop:
             temp = []
             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
Пример #29
0
    async def get_mass_messages(self,
                                resume=None,
                                refresh=True,
                                limit=10,
                                offset=0) -> list:
        api_type = "mass_messages"
        if not self.active:
            return []
        if not refresh:
            result = handle_refresh(self, api_type)
            if result:
                return result
        link = endpoint_links(global_limit=limit,
                              global_offset=offset).mass_messages_api
        results = await self.session_manager.json_request(link)
        items = results.get("list", [])
        if not items:
            return items
        if resume:
            for item in items:
                if any(x["id"] == item["id"] for x in resume):
                    resume.sort(key=lambda x: x["id"], reverse=True)
                    self.mass_messages = resume
                    return resume
                else:
                    resume.append(item)

        if results["hasMore"]:
            results2 = self.get_mass_messages(resume=resume,
                                              limit=limit,
                                              offset=limit + offset)
            items.extend(results2)
        if resume:
            items = resume

        items.sort(key=lambda x: x["id"], reverse=True)
        self.mass_messages = items
        return items
Пример #30
0
 async def buy_subscription(self):
     """
     This function will subscribe to a model. If the model has a promotion available, it will use it.
     """
     subscription_price = await self.subscription_price()
     x = {
         "paymentType": "subscribe",
         "userId": self.id,
         "subscribeSource": "profile",
         "amount": subscription_price,
         "token": "",
         "unavailablePaymentGates": [],
     }
     if self.subscriber.creditBalance >= subscription_price:
         link = endpoint_links().pay
         result = await self.session_manager.json_request(
             link, method="POST", payload=x
         )
     else:
         result = ErrorDetails(
             {"code": 2011, "message": "Insufficient Credit Balance"}
         )
     return result