Skip to content

Commit 745d9c2

Browse files
committed
Avoiding CrowdTanglePostWithLink shenanigans
1 parent df7e16d commit 745d9c2

File tree

5 files changed

+6
-28
lines changed

5 files changed

+6
-28
lines changed

minet/cli/crowdtangle/summary.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from minet.cli.crowdtangle.utils import with_crowdtangle_utilities
1111
from minet.crowdtangle.constants import (
1212
CROWDTANGLE_SUMMARY_CSV_HEADERS,
13-
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK,
13+
CROWDTANGLE_POST_CSV_HEADERS,
1414
)
1515

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

2626
if cli_args.posts is not None:
2727
posts_writer = casanova.writer(
28-
cli_args.posts, fieldnames=CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK
28+
cli_args.posts, fieldnames=["url"] + CROWDTANGLE_POST_CSV_HEADERS
2929
)
3030

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

45-
if posts is not None:
45+
if posts is not None and posts_writer is not None:
4646
for post in posts:
47-
posts_writer.writerow(post.as_csv_row())
47+
posts_writer.writerow([url], post)
4848

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

minet/crowdtangle/constants.py

-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@
137137
CROWDTANGLE_POST_CSV_HEADERS += CROWDTANGLE_ACCOUNT_CSV_HEADERS
138138
CROWDTANGLE_POST_CSV_HEADERS += CROWDTANGLE_MEDIA_CSV_HEADERS
139139

140-
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK = ["url"] + CROWDTANGLE_POST_CSV_HEADERS
141-
142140
CROWDTANGLE_SUMMARY_CSV_HEADERS = ["%s_count" % t for t in CROWDTANGLE_REACTION_TYPES]
143141

144142
CROWDTANGLE_LEADERBOARD_CSV_HEADERS = [

minet/crowdtangle/formatters.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
CROWDTANGLE_POST_TYPES,
1111
CROWDTANGLE_REACTION_TYPES,
1212
CROWDTANGLE_POST_CSV_HEADERS,
13-
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK,
1413
CROWDTANGLE_SUMMARY_CSV_HEADERS,
1514
CROWDTANGLE_LEADERBOARD_CSV_HEADERS,
1615
CROWDTANGLE_LEADERBOARD_CSV_HEADERS_WITH_BREAKDOWN,
@@ -27,14 +26,6 @@
2726
json=["media"],
2827
)
2928

30-
CrowdTanglePostWithLink = namedrecord(
31-
"CrowdTanglePostWithLink",
32-
CROWDTANGLE_POST_CSV_HEADERS_WITH_LINK,
33-
boolean=["account_verified"],
34-
plural=["links", "expanded_links"],
35-
json=["media"],
36-
)
37-
3829
CrowdTangleSummary = namedrecord("CrowdTangleSummary", CROWDTANGLE_SUMMARY_CSV_HEADERS)
3930

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

5647

57-
def format_post(post, link=None):
48+
def format_post(post):
5849
row = [
5950
post["id"],
6051
post["platformId"],
@@ -74,9 +65,6 @@ def format_post(post, link=None):
7465
post.get("liveVideoStatus"),
7566
]
7667

77-
if link:
78-
row = [link] + row
79-
8068
stats = post["statistics"]
8169
actual_stats = stats["actual"]
8270
expected_stats = stats["expected"]
@@ -110,9 +98,6 @@ def format_post(post, link=None):
11098
]
11199
)
112100

113-
if link is not None:
114-
return CrowdTanglePostWithLink(*row)
115-
116101
return CrowdTanglePost(*row)
117102

118103

minet/crowdtangle/summary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ def crowdtangle_summary(
7676

7777
else:
7878
if not raw:
79-
posts = [format_post(post, link=link) for post in posts]
79+
posts = [format_post(post) for post in posts]
8080

8181
return stats, posts

minet/crowdtangle/types.py

-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ class CrowdTanglePost(TabularRecord):
6767
media: Any = tabular_field(as_json=True)
6868

6969

70-
@dataclass
71-
class CrowdTanglePostWithLink(TabularRecord):
72-
pass
73-
74-
7570
@dataclass
7671
class CrowdTangleSummary(TabularRecord):
7772
pass

0 commit comments

Comments
 (0)