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_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
Exemplo n.º 3
0
 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
Exemplo n.º 4
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.º 5
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]]:
     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
Exemplo n.º 6
0
 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]]:
     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 = self.session_manager.json_request(link)
     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 = []
         temp += [
             create_message(x) for x in final_results
             if x["responseType"] == "message"
         ]
         temp += [
             create_post(x, self.session_manager) for x in final_results
             if x["responseType"] == "post"
         ]
         final_results = temp
     self.paid_content = final_results
     return final_results