Conversation
reddit_top/reddit_scrabber.py
Outdated
|
|
||
| time.sleep(1) | ||
|
|
||
| if created_utc >= before: |
There was a problem hiding this comment.
У тебя тут буквально написано: «остановиться, если самый старый пост на странице новее текущего момента»
Ты не остановишься, выйдя за пределы трех дней и будешь постоянно листать назад
Правильно
created_utc < after
reddit_top/reddit_scrabber.py
Outdated
|
|
||
|
|
||
| def main() -> None: | ||
| subreddit = "python" |
There was a problem hiding this comment.
ты захардкодил название сабреддита, а по заданию его должен ввести пользователь
reddit_top/reddit_scrabber.py
Outdated
| continue | ||
|
|
||
| for c in comments: | ||
| if c["kind"] != "t1": |
There was a problem hiding this comment.
хорошо бы рекурсивно вытаскивать реплаи на комментарий
reddit_top/reddit_scrabber.py
Outdated
| return int((datetime.now(timezone.utc) - timedelta(days=days_ago)).timestamp()) | ||
|
|
||
|
|
||
| def fetch_posts(subreddit: str, after: int, before: int) -> list[dict[str, any]]: |
There was a problem hiding this comment.
any - это встроенная функция питона, а Any - это тип
reddit_top/reddit_scrabber.py
Outdated
|
|
||
| def get_utc_timestamp(days_ago: int) -> int: | ||
| """Возвращает UTC timestamp n дней назад (timezone-aware).""" | ||
| from datetime import timezone |
reddit_top/reddit_scrabber.py
Outdated
| top_posters = Counter(post_authors).most_common(10) | ||
|
|
||
| # 3. ВСЕ ПОСТЫ | ||
| all_posts = posts |
There was a problem hiding this comment.
зачем ты присваиваешь переменной новое имя без изменения содержимого?
reddit_top/reddit_scrabber.py
Outdated
| if last_fullname: | ||
| params["after"] = last_fullname | ||
|
|
||
| response = requests.get(url, headers=HEADERS, params=params, timeout=10) |
There was a problem hiding this comment.
запрос без обработки ошибок - опасное занятие
reddit_top/reddit_scrabber.py
Outdated
| """Собираем все посты за промежуток времени через JSON сабреддита.""" | ||
| all_posts = [] | ||
| url = f"https://www.reddit.com/r/{subreddit}/new.json" | ||
| params = {"limit": 100} |
There was a problem hiding this comment.
выноси подобные константные значения наверх в глобальный скоп
LIMIT = 100
reddit_top/reddit_scrabber.py
Outdated
| if author and author != "[deleted]": | ||
| all_comments.append({"author": author, "created_utc": comment["created_utc"]}) | ||
|
|
||
| time.sleep(0.5) |
reddit_top/reddit_scrabber.py
Outdated
|
|
||
| # 1. ТОП КОММЕНТАТОРОВ | ||
| comment_authors = [c["author"] for c in comments] | ||
| top_commenters = Counter(comment_authors).most_common(10) |
No description provided.