Skip to content

Commit

Permalink
Avoiding CrowdTanglePostWithLink shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Dec 13, 2023
1 parent df7e16d commit a77df73
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
8 changes: 4 additions & 4 deletions minet/cli/crowdtangle/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from minet.cli.crowdtangle.utils import with_crowdtangle_utilities
from minet.crowdtangle.constants import (
CROWDTANGLE_SUMMARY_CSV_HEADERS,
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK,
CROWDTANGLE_POST_CSV_HEADERS,
)

# TODO: could be a nested loading bar
Expand All @@ -25,7 +25,7 @@ def action(cli_args, client, enricher, loading_bar):

if cli_args.posts is not None:
posts_writer = casanova.writer(
cli_args.posts, fieldnames=CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK
cli_args.posts, fieldnames=["url"] + CROWDTANGLE_POST_CSV_HEADERS
)

for row, url in enricher.cells(cli_args.column, with_rows=True):
Expand All @@ -42,9 +42,9 @@ def action(cli_args, client, enricher, loading_bar):
if cli_args.posts is not None:
stats, posts = stats

if posts is not None:
if posts is not None and posts_writer is not None:
for post in posts:
posts_writer.writerow(post.as_csv_row())
posts_writer.writerow([url], post)

enricher.writerow(row, stats.as_csv_row() if stats is not None else None)

Expand Down
2 changes: 0 additions & 2 deletions minet/crowdtangle/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
CROWDTANGLE_POST_CSV_HEADERS += CROWDTANGLE_ACCOUNT_CSV_HEADERS
CROWDTANGLE_POST_CSV_HEADERS += CROWDTANGLE_MEDIA_CSV_HEADERS

CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK = ["url"] + CROWDTANGLE_POST_CSV_HEADERS

CROWDTANGLE_SUMMARY_CSV_HEADERS = ["%s_count" % t for t in CROWDTANGLE_REACTION_TYPES]

CROWDTANGLE_LEADERBOARD_CSV_HEADERS = [
Expand Down
17 changes: 1 addition & 16 deletions minet/crowdtangle/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
CROWDTANGLE_POST_TYPES,
CROWDTANGLE_REACTION_TYPES,
CROWDTANGLE_POST_CSV_HEADERS,
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK,
CROWDTANGLE_SUMMARY_CSV_HEADERS,
CROWDTANGLE_LEADERBOARD_CSV_HEADERS,
CROWDTANGLE_LEADERBOARD_CSV_HEADERS_WITH_BREAKDOWN,
Expand All @@ -27,14 +26,6 @@
json=["media"],
)

CrowdTanglePostWithLink = namedrecord(
"CrowdTanglePostWithLink",
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK,
boolean=["account_verified"],
plural=["links", "expanded_links"],
json=["media"],
)

CrowdTangleSummary = namedrecord("CrowdTangleSummary", CROWDTANGLE_SUMMARY_CSV_HEADERS)

CrowdTangleLeaderboard = namedrecord(
Expand All @@ -54,7 +45,7 @@ def map_key(key, target):
return [item[key] for item in target]


def format_post(post, link=None):
def format_post(post):
row = [
post["id"],
post["platformId"],
Expand All @@ -74,9 +65,6 @@ def format_post(post, link=None):
post.get("liveVideoStatus"),
]

if link:
row = [link] + row

stats = post["statistics"]
actual_stats = stats["actual"]
expected_stats = stats["expected"]
Expand Down Expand Up @@ -110,9 +98,6 @@ def format_post(post, link=None):
]
)

if link is not None:
return CrowdTanglePostWithLink(*row)

return CrowdTanglePost(*row)


Expand Down
2 changes: 1 addition & 1 deletion minet/crowdtangle/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ def crowdtangle_summary(

else:
if not raw:
posts = [format_post(post, link=link) for post in posts]
posts = [format_post(post) for post in posts]

return stats, posts

0 comments on commit a77df73

Please sign in to comment.