-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# ============================================================================= | ||
# Minet Reddit Posts CLI Action | ||
# ============================================================================= | ||
# | ||
# Logic of the `rd user_posts` action. | ||
# | ||
from minet.cli.utils import with_enricher_and_loading_bar | ||
from minet.reddit.scraper import RedditScraper | ||
from minet.reddit.types import RedditUserPost | ||
from minet.reddit.exceptions import RedditInvalidTargetError | ||
|
||
|
||
@with_enricher_and_loading_bar( | ||
headers=RedditUserPost, | ||
title="Scraping user posts", | ||
unit="groups", | ||
nested=True, | ||
sub_unit="user", | ||
) | ||
def action(cli_args, enricher, loading_bar): | ||
scraper = RedditScraper() | ||
|
||
for i, row, url in enricher.enumerate_cells( | ||
cli_args.column, with_rows=True, start=1 | ||
): | ||
with loading_bar.step(url): | ||
try: | ||
if cli_args.number: | ||
if cli_args.text: | ||
posts = scraper.get_user_posts(url, cli_args.number) | ||
else: | ||
posts = scraper.get_user_posts(url, cli_args.number) | ||
else: | ||
if cli_args.text: | ||
posts = scraper.get_user_posts(url) | ||
else: | ||
posts = scraper.get_user_posts(url) | ||
except RedditInvalidTargetError: | ||
loading_bar.print( | ||
"the script could not complete normally on line %i" % (i) | ||
) | ||
continue | ||
|
||
for post in posts: | ||
loading_bar.nested_advance() | ||
enricher.writerow(row, post) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters