-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a twitter followers-you-know command
- Loading branch information
1 parent
be4554f
commit ef3e288
Showing
9 changed files
with
278 additions
and
4 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
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,6 @@ | ||
from minet.twitter import TwitterAPIScraper | ||
|
||
scraper = TwitterAPIScraper("firefox") | ||
|
||
for user in scraper.followers_you_know("794083798912827393"): | ||
print(user) |
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 |
---|---|---|
|
@@ -158,6 +158,7 @@ | |
}, | ||
] | ||
|
||
|
||
def delete(o, k): | ||
try: | ||
del o[k] | ||
|
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
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,51 @@ | ||
# ============================================================================= | ||
# Minet Twitter Scrape CLI Action | ||
# ============================================================================= | ||
# | ||
# Logic of the `tw scrape` action. | ||
# | ||
from twitwi.constants import USER_FIELDS | ||
from twitwi import format_user_as_csv_row | ||
|
||
from minet.cli.utils import with_enricher_and_loading_bar | ||
from minet.cli.exceptions import FatalError | ||
from minet.twitter import TwitterAPIScraper | ||
from minet.twitter.exceptions import ( | ||
TwitterPublicAPIInvalidCookieError, | ||
TwitterPublicAPIBadAuthError, | ||
) | ||
|
||
|
||
@with_enricher_and_loading_bar( | ||
headers=USER_FIELDS, | ||
title="Scraping", | ||
unit="users", | ||
nested=True, | ||
sub_unit="followers", | ||
) | ||
def action(cli_args, enricher, loading_bar): | ||
try: | ||
scraper = TwitterAPIScraper(cli_args.cookie) | ||
except TwitterPublicAPIInvalidCookieError: | ||
raise FatalError( | ||
[ | ||
"Invalid Twitter cookie!", | ||
"Try giving another browser to --cookie and sure you are correctly logged in.", | ||
] | ||
) | ||
|
||
for row, user_id in enricher.cells(cli_args.column, with_rows=True): | ||
with loading_bar.step(user_id): | ||
iterator = scraper.followers_you_know(user_id, locale=cli_args.timezone) | ||
|
||
try: | ||
for user in iterator: | ||
addendum = format_user_as_csv_row(user) | ||
enricher.writerow(row, addendum) | ||
loading_bar.nested_advance() | ||
|
||
except TwitterPublicAPIBadAuthError as error: | ||
raise FatalError( | ||
"Bad authentication (%i). Double check your --cookie and make sure you are logged in." | ||
% error.status | ||
) |
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