Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug where crawl_span (int of num days for crawl span) is overwritten with CrawlSpan object in run_repeated #36

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/tiktok_api_helper/cli_data_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
_DAYS_PER_ITER = 28
_DEFAULT_CREDENTIALS_FILE_PATH = Path("./secrets.yaml")

CrawlSpan = namedtuple("CrawlSpan", ["start_date", "end_date"])
CrawlDateWindow = namedtuple("CrawlDateWindow", ["start_date", "end_date"])


def run_long_query(config: ApiClientConfig):
Expand Down Expand Up @@ -273,14 +273,14 @@ def print_query(
print(json.dumps(query, cls=QueryJSONEncoder, indent=2))


def make_crawl_span(crawl_span: int, crawl_lag: int) -> CrawlSpan:
"""Returns a CrawlSpan with an end_date crawl_lag days before today, and start_date crawl_span
days before end_date.
def make_crawl_date_window(crawl_span: int, crawl_lag: int) -> CrawlDateWindow:
"""Returns a CrawlDateWindow with an end_date crawl_lag days before today, and start_date
crawl_span days before end_date.
"""
assert crawl_span > 0 and crawl_lag > 0, "crawl_span and crawl_lag must be non-negative"
end_date = date.today() - timedelta(days=crawl_lag)
start_date = end_date - timedelta(days=crawl_span)
return CrawlSpan(start_date=start_date, end_date=end_date)
return CrawlDateWindow(start_date=start_date, end_date=end_date)


@APP.command()
Expand Down Expand Up @@ -335,16 +335,16 @@ def run_repeated(
utils.setup_logging_info_level()

while True:
crawl_span = make_crawl_span(crawl_span=crawl_span, crawl_lag=crawl_lag)
crawl_date_window = make_crawl_date_window(crawl_span=crawl_span, crawl_lag=crawl_lag)
logging.info(
"Starting scheduled run. start_date: %s, end_date: %s",
crawl_span.start_date,
crawl_span.end_date,
crawl_date_window.start_date,
crawl_date_window.end_date,
)
execution_start_time = pendulum.now()
run(
start_date_str=utils.date_to_tiktok_str_format(crawl_span.start_date),
end_date_str=utils.date_to_tiktok_str_format(crawl_span.end_date),
start_date_str=utils.date_to_tiktok_str_format(crawl_date_window.start_date),
end_date_str=utils.date_to_tiktok_str_format(crawl_date_window.end_date),
db_file=db_file,
db_url=db_url,
crawl_tag=crawl_tag,
Expand Down
Loading