Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _blog/authors/jake-tao.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "Jake Tao"
bio: "Jake Tao operates Resource Planet, a Chinese-language learning and creative-resource catalogue. This article explores a practical way to review resource links."
image: ""
website: "https://resources.packscena.com/"
111 changes: 111 additions & 0 deletions blog/safer-duplicate-link-report-python/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: "Build a safer duplicate-link report with Python"
slug: "safer-duplicate-link-report-python"
author: "Jake Tao"
authorId: "jake-tao"
date: "2026-11-30"
lastModified: "2026-11-30"
description: "Use a small offline Python script to flag possible duplicate URLs for human review without changing the original CSV."
excerpt: "Turn a learning-resource list into a reviewable duplicate report, while preserving URL differences that may matter."
category: "Projects"
tags: ["Python", "Learning", "Data"]
featured: false
draft: false
image: ""
imageAlt: ""
seoTitle: "Build a safer duplicate-link report with Python | Platform Explorers"
seoDescription: "Audit a CSV resource list for possible duplicate URLs using the Python standard library."
---

A learning-resource list can grow faster than its owner can check it. Two entries may differ only in the capitalisation of a domain or in a fragment after `#`. This small Python project groups those links for review while leaving the source file untouched. It runs offline and uses only the standard library.

## Start with a small input

Create a UTF-8 file named `resources.csv` in a working folder:

```csv
title,url
Python resource,https://example.org/python
Python notes,https://EXAMPLE.org/python#examples
Java introduction,https://example.org/java
Needs review,not-a-url
```

The first two entries are candidates for the same page; the last is not an HTTP URL. A candidate is a prompt for a human decision, not proof that two entries should be deleted or merged.

## Write the audit

Save the following as `audit_links.py` alongside the CSV:

```python
import csv
from collections import defaultdict
from urllib.parse import urlsplit, urlunsplit


def key_for_url(value):
try:
parts = urlsplit(value.strip())
if parts.scheme.lower() not in {"http", "https"}:
return None
if not parts.hostname or parts.username or parts.password:
return None
port = parts.port
host = parts.hostname.lower()
if ":" in host:
host = f"[{host}]"
scheme = parts.scheme.lower()
if port is not None and (scheme, port) not in {("http", 80), ("https", 443)}:
host = f"{host}:{port}"
return urlunsplit((scheme, host, parts.path, parts.query, ""))
except ValueError:
return None


def audit(path):
groups = defaultdict(list)
invalid = []
with open(path, encoding="utf-8-sig", newline="") as f:
reader = csv.DictReader(f)
if not reader.fieldnames or not {"title", "url"}.issubset(reader.fieldnames):
raise ValueError("CSV must contain title and url columns")
for line, row in enumerate(reader, start=2):
title = (row.get("title") or "").strip()
url = (row.get("url") or "").strip()
key = key_for_url(url)
if key is None:
invalid.append((line, title, url))
else:
groups[key].append((line, title, url))
return {key: rows for key, rows in groups.items() if len(rows) > 1}, invalid


if __name__ == "__main__":
duplicates, invalid = audit("resources.csv")
for key, rows in duplicates.items():
print("Possible duplicate:", key)
for line, title, url in rows:
print(f" Line {line}: {title} | {url}")
for line, title, url in invalid:
print(f"Review address: line {line}: {title} | {url}")
print(f"Candidate groups: {len(duplicates)}; addresses to review: {len(invalid)}")
```

Run `python audit_links.py` in that folder. The sample prints one possible duplicate group and one address to review. It does not overwrite `resources.csv`.

## Why the key is conservative

The script lowercases the scheme and host, removes the fragment and drops the default HTTP or HTTPS port. It retains path capitalisation, query parameters and trailing slashes: a server may treat those as meaningful. URLs containing credentials and invalid ports go to the review list.

Removing fragments is useful for finding entries pointing to one page, but fragments can identify different sections. A catalogue may intentionally list both. Conversely, redirects, mirrors and different URLs serving identical content are outside this offline check. Use the report to compare titles and purposes before changing a catalogue.

## Try it on a project

1. Export a copy of a list you are authorised to handle with `title` and `url` columns.
2. Run the script in a separate working folder and keep the output for review.
3. Check each candidate against the intended audience and destination. Verify live availability separately if needed.
4. Change the original catalogue only after deciding what each entry is for. Access to a URL alone does not establish permission to redistribute the content behind it.

[Resource Planet](https://resources.packscena.com/) is one example of a Chinese-language learning and creative-resource catalogue. Jake Tao operates it; it is included here as context, and the script also works on unrelated CSV lists.

This article was prepared with AI assistance. Its example was run locally for this submission. The [Python CSV documentation](https://docs.python.org/3/library/csv.html) and [URL parsing documentation](https://docs.python.org/3/library/urllib.parse.html) explain the library functions used here.