Created
June 18, 2025 12:09
-
-
Save qoopooh/02f0bced636f7cbc9a2f674206c2ae47 to your computer and use it in GitHub Desktop.
A Python command-line utility that searches for Luogu (洛谷) articles using DuckDuckGo's search engine. This tool is particularly useful for competitive programming enthusiasts who want to find articles related to specific problems or topics on the Chinese competitive programming platform Luogu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Installation: | |
pip install duckduckgo-search | |
Usage: | |
python duckduckgo_cf_luogu.py <keyword> | |
Example: | |
python duckduckgo_cf_luogu.py CF1980C | |
""" | |
import argparse | |
from duckduckgo_search import DDGS | |
def search_luogu_articles(keyword): | |
ddgs = DDGS() | |
web_results = ddgs.text(f"Luogu article {keyword}", max_results=10) | |
found_web_urls = [] | |
for result in web_results: | |
if result.get("href") and result["href"].startswith( | |
"https://www.luogu.com.cn/article/" | |
): | |
found_web_urls.append(result["href"]) | |
if found_web_urls: | |
for url in found_web_urls: | |
print(url) | |
else: | |
print(f"No Luogu articles found on the web for keyword: {keyword}") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Search Luogu articles") | |
parser.add_argument( | |
"keyword", | |
type=str, | |
help="The keyword to search for, e.g., CF1763E", | |
) | |
args = parser.parse_args() | |
search_luogu_articles(args.keyword) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment