.. autofunction:: delete_tweet_pathnames
.. autofunction:: is_tweet_url
.. autofunction:: get_response
-.. autofunction:: parse_date
.. autofunction:: semicolon_parser
: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
"""
-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
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()
"--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,
"""
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
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.