add WaybackTweets class default values, update cli, docs
authorClaromes <claromes@hey.com>
Sat, 15 Jun 2024 22:48:41 +0000 (19:48 -0300)
committerClaromes <claromes@hey.com>
Sat, 15 Jun 2024 22:48:41 +0000 (19:48 -0300)
docs/api.rst
waybacktweets/api/request_tweets.py
waybacktweets/cli/main.py
waybacktweets/utils/utils.py

index 820cbd8b23aa0f9335c837fbeef2f06956c4781f..822085798fecb62ddde27264698d82090747838e 100644 (file)
@@ -56,5 +56,4 @@ Utils
 .. autofunction:: delete_tweet_pathnames
 .. autofunction:: is_tweet_url
 .. autofunction:: get_response
-.. autofunction:: parse_date
 .. autofunction:: semicolon_parser
index 83f04053732e879ac05dbd5418a83136bcc02a13..b00925a6ec8bebb8f764699e5989ec847f6e8de2 100644 (file)
@@ -16,18 +16,18 @@ class WaybackTweets:
     :param timestamp_to: The timestamp to stop retrieving tweets at.
     :param limit: The maximum number of results to return.
     :param offset: The number of lines to skip in the results.
-    :param matchType: Results matching a certain prefix, a certain host or all subdomains. # noqa: E501
-    """
+    :param matchType: Results matching a certain prefix, a certain host or all subdomains.
+    """  # noqa: E501
 
     def __init__(
         self,
         username: str,
-        collapse: str,
-        timestamp_from: str,
-        timestamp_to: str,
-        limit: int,
-        offset: int,
-        matchtype: str,
+        collapse: str = None,
+        timestamp_from: str = None,
+        timestamp_to: str = None,
+        limit: int = None,
+        offset: int = None,
+        matchtype: str = None,
     ):
         self.username = username
         self.collapse = collapse
index 987bac2a554a00807b65937e5b8aebb08b0fe077..19fbdcb2502e393333a82b4a5f1ecd9f3bb7902f 100644 (file)
@@ -1,8 +1,9 @@
 """
-CLI function for retrieving archived tweets.
+CLI functions for retrieving archived tweets.
 """
 
-from typing import Optional
+from datetime import datetime
+from typing import Any, Optional
 
 import click
 from requests import exceptions
@@ -11,7 +12,30 @@ from rich import print as rprint
 from waybacktweets.api.export_tweets import TweetsExporter
 from waybacktweets.api.parse_tweets import TweetsParser
 from waybacktweets.api.request_tweets import WaybackTweets
-from waybacktweets.utils.utils import parse_date
+
+
+def parse_date(
+    ctx: Optional[Any] = None, param: Optional[Any] = None, value: Optional[str] = None
+) -> Optional[str]:
+    """
+    Parses a date string and returns it in the format "YYYYMMDD".
+
+    :param ctx: Necessary when used with the click package. Defaults to None.
+    :param param: Necessary when used with the click package. Defaults to None.
+    :param value: A date string in the "YYYYMMDD" format. Defaults to None.
+
+    :returns: The input date string formatted in the "YYYYMMDD" format,
+        or None if no date string was provided.
+    """
+    try:
+        if value is None:
+            return None
+
+        date = datetime.strptime(value, "%Y%m%d")
+
+        return date.strftime("%Y%m%d")
+    except ValueError:
+        raise click.BadParameter("Date must be in format YYYYmmdd")
 
 
 @click.command()
@@ -54,7 +78,7 @@ from waybacktweets.utils.utils import parse_date
     "--matchtype",
     type=click.Choice(["exact", "prefix", "host", "domain"], case_sensitive=False),
     default=None,
-    help="Results matching a certain prefix, a certain host or all subdomains. Default: exact",  # noqa: E501
+    help="Results matching a certain prefix, a certain host or all subdomains.",  # noqa: E501
 )
 def cli(
     username: str,
index 5163b336ceed658f4ea377dcaa8b0a7c575835e8..cf5fe9387840ecf95d2a4edf7c9248086be9f7a6 100644 (file)
@@ -3,10 +3,8 @@ Module containing utility functions for handling HTTP requests and manipulating
 """
 
 import re
-from datetime import datetime
-from typing import Any, Optional
+from typing import Optional
 
-import click
 import requests
 from requests.adapters import HTTPAdapter
 from urllib3.util.retry import Retry
@@ -157,30 +155,6 @@ def semicolon_parser(string: str) -> str:
     return "".join("%3B" if c == ";" else c for c in string)
 
 
-def parse_date(
-    ctx: Optional[Any] = None, param: Optional[Any] = None, value: Optional[str] = None
-) -> Optional[str]:
-    """
-    Parses a date string and returns it in the format "YYYYMMDD".
-
-    :param ctx: Necessary when used with the click package. Defaults to None.
-    :param param: Necessary when used with the click package. Defaults to None.
-    :param value: A date string in the "YYYYMMDD" format. Defaults to None.
-
-    :returns: The input date string formatted in the "YYYYMMDD" format,
-        or None if no date string was provided.
-    """
-    try:
-        if value is None:
-            return None
-
-        date = datetime.strptime(value, "%Y%m%d")
-
-        return date.strftime("%Y%m%d")
-    except ValueError:
-        raise click.BadParameter("Date must be in format YYYYmmdd")
-
-
 def is_tweet_url(twitter_url: str) -> bool:
     """
     Checks if the provided URL is a Twitter status URL.