Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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