mirror of
https://github.com/K-Dense-AI/claude-scientific-skills.git
synced 2026-01-26 16:58:56 +08:00
refactor: replace manual argv parsing with argparse
- Convert uniprot_client.py to use argparse module - Convert peds_client.py to use argparse module - Convert trademark_client.py to use argparse module - Add mutually exclusive argument groups for better UX - Implement comprehensive help text with examples - Add short and long argument options for all commands - Improve error handling with proper parser.error() calls Replaces error-prone manual sys.argv parsing with robust argparse implementation for better user experience and input validation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -213,30 +213,62 @@ class PEDSHelper:
|
||||
|
||||
def main():
|
||||
"""Command-line interface for PEDS data."""
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage:")
|
||||
print(" python peds_client.py <application_number>")
|
||||
print(" python peds_client.py --patent <patent_number>")
|
||||
print(" python peds_client.py --status <application_number>")
|
||||
print(" python peds_client.py --analyze <application_number>")
|
||||
sys.exit(1)
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Query USPTO Patent Examination Data System (PEDS)',
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Get application data by application number
|
||||
%(prog)s --application 16123456
|
||||
|
||||
# Get patent data by patent number
|
||||
%(prog)s --patent 11234567
|
||||
|
||||
# Get status summary
|
||||
%(prog)s --status 16123456
|
||||
|
||||
# Analyze prosecution history
|
||||
%(prog)s --analyze 16123456
|
||||
|
||||
# Get transaction history
|
||||
%(prog)s --transactions 16123456
|
||||
|
||||
# Get office actions
|
||||
%(prog)s --office-actions 16123456
|
||||
"""
|
||||
)
|
||||
|
||||
if not HAS_USPTO_LIB:
|
||||
print("Error: uspto-opendata-python library not installed")
|
||||
print("Install with: pip install uspto-opendata-python")
|
||||
sys.exit(1)
|
||||
parser.error("uspto-opendata-python library not installed. Install with: pip install uspto-opendata-python")
|
||||
|
||||
helper = PEDSHelper()
|
||||
# Main operation arguments (mutually exclusive)
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('--application', '-a', help='Get application by application number')
|
||||
group.add_argument('--patent', '-p', help='Get patent by patent number')
|
||||
group.add_argument('--status', '-s', help='Get status summary for application')
|
||||
group.add_argument('--analyze', help='Analyze prosecution history for application')
|
||||
group.add_argument('--transactions', '-t', help='Get transaction history for application')
|
||||
group.add_argument('--office-actions', '-o', help='Get office actions for application')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
if sys.argv[1] == "--patent":
|
||||
result = helper.get_patent(sys.argv[2])
|
||||
elif sys.argv[1] == "--status":
|
||||
result = helper.get_status_summary(sys.argv[2])
|
||||
elif sys.argv[1] == "--analyze":
|
||||
result = helper.analyze_prosecution(sys.argv[2])
|
||||
else:
|
||||
result = helper.get_application(sys.argv[1])
|
||||
helper = PEDSHelper()
|
||||
|
||||
if args.application:
|
||||
result = helper.get_application(args.application)
|
||||
elif args.patent:
|
||||
result = helper.get_patent(args.patent)
|
||||
elif args.status:
|
||||
result = helper.get_status_summary(args.status)
|
||||
elif args.analyze:
|
||||
result = helper.analyze_prosecution(args.analyze)
|
||||
elif args.transactions:
|
||||
result = helper.get_transaction_history(args.transactions)
|
||||
elif args.office_actions:
|
||||
result = helper.get_office_actions(args.office_actions)
|
||||
|
||||
if result:
|
||||
print(json.dumps(result, indent=2))
|
||||
|
||||
@@ -225,35 +225,83 @@ class TrademarkClient:
|
||||
|
||||
def main():
|
||||
"""Command-line interface for trademark search."""
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage:")
|
||||
print(" python trademark_client.py <serial_or_registration_number>")
|
||||
print(" python trademark_client.py --status <number>")
|
||||
print(" python trademark_client.py --health <number>")
|
||||
print(" python trademark_client.py --goods <number>")
|
||||
sys.exit(1)
|
||||
import argparse
|
||||
|
||||
client = TrademarkClient()
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Query USPTO Trademark Status & Document Retrieval (TSDR) API',
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Get trademark by serial number
|
||||
%(prog)s --serial 87654321
|
||||
|
||||
# Get trademark by registration number
|
||||
%(prog)s --registration 5678901
|
||||
|
||||
# Get status summary
|
||||
%(prog)s --status 87654321
|
||||
|
||||
# Check trademark health
|
||||
%(prog)s --health 87654321
|
||||
|
||||
# Get goods and services
|
||||
%(prog)s --goods 87654321
|
||||
|
||||
# Get owner information
|
||||
%(prog)s --owner 87654321
|
||||
|
||||
# Get prosecution history
|
||||
%(prog)s --prosecution 87654321
|
||||
|
||||
Environment:
|
||||
Set USPTO_API_KEY environment variable with your API key from:
|
||||
https://account.uspto.gov/api-manager/
|
||||
"""
|
||||
)
|
||||
|
||||
# Main operation arguments (mutually exclusive)
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('--serial', '-s', help='Get trademark by serial number')
|
||||
group.add_argument('--registration', '-r', help='Get trademark by registration number')
|
||||
group.add_argument('--status', help='Get status summary (serial or registration number)')
|
||||
group.add_argument('--health', help='Check trademark health (serial or registration number)')
|
||||
group.add_argument('--goods', '-g', help='Get goods and services (serial or registration number)')
|
||||
group.add_argument('--owner', '-o', help='Get owner information (serial or registration number)')
|
||||
group.add_argument('--prosecution', '-p', help='Get prosecution history (serial or registration number)')
|
||||
|
||||
# API key option
|
||||
parser.add_argument('--api-key', '-k', help='USPTO API key (overrides USPTO_API_KEY env var)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
if sys.argv[1] == "--status":
|
||||
result = client.get_trademark_status(sys.argv[2])
|
||||
elif sys.argv[1] == "--health":
|
||||
result = client.check_trademark_health(sys.argv[2])
|
||||
elif sys.argv[1] == "--goods":
|
||||
result = client.get_goods_and_services(sys.argv[2])
|
||||
else:
|
||||
# Get full trademark data
|
||||
result = client.get_trademark_by_serial(sys.argv[1])
|
||||
if not result:
|
||||
result = client.get_trademark_by_registration(sys.argv[1])
|
||||
client = TrademarkClient(api_key=args.api_key)
|
||||
|
||||
if args.serial:
|
||||
result = client.get_trademark_by_serial(args.serial)
|
||||
elif args.registration:
|
||||
result = client.get_trademark_by_registration(args.registration)
|
||||
elif args.status:
|
||||
result = client.get_trademark_status(args.status)
|
||||
elif args.health:
|
||||
result = client.check_trademark_health(args.health)
|
||||
elif args.goods:
|
||||
result = client.get_goods_and_services(args.goods)
|
||||
elif args.owner:
|
||||
result = client.get_owner_info(args.owner)
|
||||
elif args.prosecution:
|
||||
result = client.get_prosecution_history(args.prosecution)
|
||||
|
||||
if result:
|
||||
print(json.dumps(result, indent=2))
|
||||
else:
|
||||
print(f"Trademark {sys.argv[1]} not found", file=sys.stderr)
|
||||
number = (args.serial or args.registration or args.status or
|
||||
args.health or args.goods or args.owner or args.prosecution)
|
||||
print(f"Trademark {number} not found", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except ValueError as e:
|
||||
parser.error(str(e))
|
||||
except Exception as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user