Skip to content

Commit

Permalink
Reshape data; restyle table
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed May 1, 2024
1 parent b5d9fcb commit 3c0ed61
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
36 changes: 26 additions & 10 deletions output/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,42 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Community notes</title>
<link href="//cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="//cdn.datatables.net/v/bs5/jq-3.7.0/dt-2.0.5/datatables.min.css">
</head>
<body>

<table>
<table class="table table-striped">
{% for row in site.data.notes %}
{% if forloop.first %}
{% if forloop.first %}
<thead>
<tr>
{% for pair in row %}
<th>{{ pair[0] }}</th>
{% endfor %}
<th>Tweet</th>
<th>Classification</th>
<th>Reasons</th>
<th>Summary</th>
</tr>
{% endif %}
</thead>
<tbody>
{% endif %}

{% tablerow pair in row %}
{{ pair[1] }}
{% endtablerow %}
<tr>
<td><a target="_blank" href="https://twitter.com/_/status/{{ row['tweet_id'] }}">{{ row['created_at'] }}</a></td>
<td>{{ row['classification'] }}</td>
<td>{{ row['reasons'] }}</td>
<td>{{ row['summary'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.2/Sortable.min.js" integrity="sha512-TelkP3PCMJv+viMWynjKcvLsQzx6dJHvIGhfqzFtZKgAjKM1YPqcwzzDEoTc/BHjf43PcPzTQOjuTr4YdE8lNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- <script src="//code.jquery.com/jquery-3.7.1.slim.min.js" integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous"></script> -->
<script src="//cdn.datatables.net/v/bs5/jq-3.7.0/dt-2.0.5/datatables.min.js"></script>
<script>
let table = new DataTable('table', {
// options
});
</script>
</body>
</html>
<html>
47 changes: 39 additions & 8 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@


def to_isoformat(ms_since_epoch):
return str(datetime.utcfromtimestamp(int(ms_since_epoch) / 1000))
return str(datetime.utcfromtimestamp(int(ms_since_epoch[:-3])))


reasons = {
"misleadingOther": "Other",
"misleadingFactualError": "Factual error",
"misleadingManipulatedMedia": "Manipulated media",
"misleadingOutdatedInformation": "Outdated information",
"misleadingMissingImportantContext": "Missing important context",
"misleadingUnverifiedClaimAsFact": "Unverified claim as fact",
"misleadingSatire": "Satire",
"notMisleadingOther": "Other",
"notMisleadingFactuallyCorrect": "Factually correct",
"notMisleadingOutdatedButNotWhenWritten": "Outdated (but not when written)",
"notMisleadingClearlySatire": "Clearly satire",
"notMisleadingPersonalOpinion": "Personal opinion",
}
def get_reasons(row):
return ", ".join([
v for k, v in reasons.items()
if bool(int(row[k]))
])


def get_data(date):
Expand Down Expand Up @@ -39,10 +60,20 @@ def get_generator():
with open("output/_data/notes.csv", "w") as fh:
writer = None
for row in get_generator():
if "fullfact" in row["summary"].lower():
row["createdAt"] = to_isoformat(row["createdAtMillis"])
del row["createdAtMillis"]
if not writer:
writer = csv.DictWriter(fh, fieldnames=row.keys())
writer.writeheader()
_ = writer.writerow(row)
if "fullfact" not in row["summary"].lower():
# filter out non-fullfact stuff
continue
output = {
"tweet_id": row["tweetId"],
"note_id": row["noteId"],
"note_author_id": row["noteAuthorParticipantId"],
"classification": row["classification"].replace("_", " ").lower().capitalize(),
"reasons": get_reasons(row),
"summary": row["summary"],
"trustworthy_source": bool(row["trustworthySources"]),
"created_at": to_isoformat(row["createdAtMillis"]),
}
if not writer:
writer = csv.DictWriter(fh, fieldnames=output.keys())
writer.writeheader()
_ = writer.writerow(output)

0 comments on commit 3c0ed61

Please sign in to comment.