[~] Refactor
This commit is contained in:
		
							parent
							
								
									7dff2a98f2
								
							
						
					
					
						commit
						45e289cea7
					
				@ -66,6 +66,7 @@ async def tiktok_videos_links_get(
 | 
				
			|||||||
    query: Optional[str]=None,
 | 
					    query: Optional[str]=None,
 | 
				
			||||||
    screenshot_path: Optional[str]=None,
 | 
					    screenshot_path: Optional[str]=None,
 | 
				
			||||||
    max_time: Optional[int | float]=None,
 | 
					    max_time: Optional[int | float]=None,
 | 
				
			||||||
 | 
					    max_links: Optional[int]=None,
 | 
				
			||||||
) -> Iterable[str]:
 | 
					) -> Iterable[str]:
 | 
				
			||||||
    import datetime
 | 
					    import datetime
 | 
				
			||||||
    import TikTokApi
 | 
					    import TikTokApi
 | 
				
			||||||
@ -73,6 +74,9 @@ async def tiktok_videos_links_get(
 | 
				
			|||||||
    import asyncio
 | 
					    import asyncio
 | 
				
			||||||
    import re
 | 
					    import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if max_links is None:
 | 
				
			||||||
 | 
					        max_links = 100
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if max_time is None:
 | 
					    if max_time is None:
 | 
				
			||||||
        max_time = 10
 | 
					        max_time = 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -91,7 +95,8 @@ async def tiktok_videos_links_get(
 | 
				
			|||||||
                path=screenshot_path,
 | 
					                path=screenshot_path,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        links = set()
 | 
					        links = list()
 | 
				
			||||||
 | 
					        links_set = set()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        started_at = datetime.datetime.now()
 | 
					        started_at = datetime.datetime.now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -104,7 +109,9 @@ async def tiktok_videos_links_get(
 | 
				
			|||||||
            old_size = len(links)
 | 
					            old_size = len(links)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for o in new_links:
 | 
					            for o in new_links:
 | 
				
			||||||
                links.add(o)
 | 
					                if not o in links_set:
 | 
				
			||||||
 | 
					                    links_set.add(o)
 | 
				
			||||||
 | 
					                    links.append(o)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await session.page.mouse.wheel(0, 100)
 | 
					            await session.page.mouse.wheel(0, 100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -115,6 +122,9 @@ async def tiktok_videos_links_get(
 | 
				
			|||||||
            if elapsed > max_time:
 | 
					            if elapsed > max_time:
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if len(links_set) > max_links:
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if old_size < len(links):
 | 
					            if old_size < len(links):
 | 
				
			||||||
                logger.info(json.dumps(dict(
 | 
					                logger.info(json.dumps(dict(
 | 
				
			||||||
                    total=len(links),
 | 
					                    total=len(links),
 | 
				
			||||||
@ -122,7 +132,7 @@ async def tiktok_videos_links_get(
 | 
				
			|||||||
                    scroll_y=await session.page.evaluate('window.scrollY'),
 | 
					                    scroll_y=await session.page.evaluate('window.scrollY'),
 | 
				
			||||||
                )))
 | 
					                )))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return links
 | 
					    return list(links)[:max_links]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def tiktok_videos_meta(links: Iterable[str]) -> Iterable[dict[str, Any]]:
 | 
					def tiktok_videos_meta(links: Iterable[str]) -> Iterable[dict[str, Any]]:
 | 
				
			||||||
    res = []
 | 
					    res = []
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user