Skip to content

Commit

Permalink
CrowdTangleList
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Dec 13, 2023
1 parent 745d9c2 commit 0bb7481
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions minet/cli/crowdtangle/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import casanova

from minet.cli.crowdtangle.utils import with_crowdtangle_utilities
from minet.crowdtangle.constants import CROWDTANGLE_LIST_CSV_HEADERS
from minet.crowdtangle.types import CrowdTangleList


@with_crowdtangle_utilities
def action(cli_args, client):
writer = casanova.writer(cli_args.output, fieldnames=CROWDTANGLE_LIST_CSV_HEADERS)
writer = casanova.writer(cli_args.output, fieldnames=CrowdTangleList)

lists = client.lists()

Expand Down
2 changes: 0 additions & 2 deletions minet/crowdtangle/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,4 @@
"%s_%s" % (post_type, substitute_key)
)

CROWDTANGLE_LIST_CSV_HEADERS = ["id", "title", "type"]

CROWDTANGLE_DEFAULT_START_DATE = "2010"
7 changes: 0 additions & 7 deletions minet/crowdtangle/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
CROWDTANGLE_SUMMARY_CSV_HEADERS,
CROWDTANGLE_LEADERBOARD_CSV_HEADERS,
CROWDTANGLE_LEADERBOARD_CSV_HEADERS_WITH_BREAKDOWN,
CROWDTANGLE_LIST_CSV_HEADERS,
CROWDTANGLE_STATISTICS,
CROWDTANGLE_FULL_STATISTICS,
)
Expand All @@ -38,8 +37,6 @@
boolean=["verified"],
)

CrowdTangleList = namedrecord("CrowdTangleList", CROWDTANGLE_LIST_CSV_HEADERS)


def map_key(key, target):
return [item[key] for item in target]
Expand Down Expand Up @@ -141,7 +138,3 @@ def format_leaderboard(item, with_breakdown=False):
return CrowdTangleLeaderboardWithBreakdown(*row)

return CrowdTangleLeaderboard(*row)


def format_list(item):
return CrowdTangleList(item["id"], item["title"], item["type"])
4 changes: 2 additions & 2 deletions minet/crowdtangle/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Function used to retrieved lists from a given dashboard.
#
from minet.crowdtangle.exceptions import CrowdTangleMissingTokenError
from minet.crowdtangle.formatters import format_list
from minet.crowdtangle.types import CrowdTangleList

URL_TEMPLATE = "https://api.crowdtangle.com/lists?token=%s"

Expand All @@ -21,6 +21,6 @@ def crowdtangle_lists(request, token=None, raw=False):
lists = data["lists"]

if not raw:
return [format_list(l) for l in lists]
return [CrowdTangleList.from_payload(l) for l in lists]

return lists
8 changes: 7 additions & 1 deletion minet/crowdtangle/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ class CrowdTangleLeaderboardWithBreakdown(TabularRecord):

@dataclass
class CrowdTangleList(TabularRecord):
pass
id: str
title: str
type: str

@classmethod
def from_payload(cls, payload) -> "CrowdTangleList":
return cls(payload["id"], payload["title"], payload["type"])

0 comments on commit 0bb7481

Please sign in to comment.