DeaD_EyE

q-posts console

Jan 26th, 2021
863
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. """
  3. Script to scrape q-posts
  4.  
  5. Requirements:
  6. - Python
  7. - requests_html
  8. - typer
  9.  
  10. Installation:
  11.     python3 -m pip install requests_html typer
  12. """
  13. import time
  14. from typing import Generator, List, Tuple
  15.  
  16. import typer
  17. from requests_html import Element, HTMLResponse, HTMLSession
  18.  
  19. app = typer.Typer()
  20.  
  21.  
  22. def get_range(start: int, stop: int) -> Generator[Tuple[int, str], None, None]:
  23.     session = HTMLSession()
  24.     for n in range(start, stop + 1):
  25.         req: HTMLResponse = session.get(f"https://qalerts.app/?n={n}")
  26.         if req.status_code == 200:
  27.             results: List[Element] = req.html.find(".dont-break-out")
  28.             for result in results:
  29.                 yield n, result.text
  30.         time.sleep(1.5)
  31.  
  32.  
  33. @app.command()
  34. def print_drops(start: int, stop: int) -> None:
  35.     """
  36.    Print q-posts from start to stop in console
  37.    """
  38.     last_n = None
  39.     for n, drop in get_range(start, stop):
  40.         if last_n != n:
  41.             print(f"== Drop {n:04} ==")
  42.         print(drop)
  43.         print()
  44.         print()
  45.         last_n = n
  46.  
  47.  
  48. if __name__ == "__main__":
  49.     app()
  50.  
RAW Paste Data