Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed Jul 30, 2021
1 parent dd37538 commit 56d3878
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
19 changes: 9 additions & 10 deletions twarc/command2.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,12 @@ def counts(
)
else:
_write(result, outfile)

# Progress and limits:
if len(result["data"]) > 0:
progress.update_with_dates(result["data"][0]["start"], result["data"][-1]["end"])
progress.update_with_dates(
result["data"][0]["start"], result["data"][-1]["end"]
)
progress.tweet_count += result["meta"]["total_tweet_count"]
count += len(result["data"])

Expand Down Expand Up @@ -895,11 +897,9 @@ def timelines(
users = set([line])

# otherwise try to flatten the data and get the user ids
else:
else:
try:
users = set(
[t["author"]["id"] for t in ensure_flattened(data)]
)
users = set([t["author"]["id"] for t in ensure_flattened(data)])
except (KeyError, ValueError):
log.warn(
"ignored line %s which didn't contain users", line_count
Expand Down Expand Up @@ -929,11 +929,9 @@ def timelines(

# ignore what don't appear to be a username or user id since
# they can cause the Twitter API to throw a 400 error
if not re.match(r'^((\w{1,15})|(\d+))$', user):
if not re.match(r"^((\w{1,15})|(\d+))$", user):
log.warn(
'invalid username or user id "%s" on line %s',
line,
line_count
'invalid username or user id "%s" on line %s', line, line_count
)
continue

Expand Down Expand Up @@ -1354,6 +1352,7 @@ def _error_str(errors):

return click.style("\n".join(parts), fg="red")


def _write(results, outfile, pretty=False):
indent = 2 if pretty else None
click.echo(json.dumps(results, indent=indent), file=outfile)
8 changes: 3 additions & 5 deletions twarc/decorators2.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,10 @@ def update_with_dates(self, start_span, end_span):
try:
if isinstance(start_span, str):
start_span = datetime.datetime.strptime(
start_span, "%Y-%m-%dT%H:%M:%S.%fZ"
)
start_span, "%Y-%m-%dT%H:%M:%S.%fZ"
)
if isinstance(end_span, str):
end_span = datetime.datetime.strptime(
end_span, "%Y-%m-%dT%H:%M:%S.%fZ"
)
end_span = datetime.datetime.strptime(end_span, "%Y-%m-%dT%H:%M:%S.%fZ")
n = _date2millis(end_span) - _date2millis(start_span)
if self.n + n > self.total:
self.n = self.total
Expand Down

0 comments on commit 56d3878

Please sign in to comment.