feat: 增加 subscription set-url 方法
This commit is contained in:
@ -40,6 +40,11 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
rename_parser.add_argument('name', help='Current name of the subscription')
|
||||
rename_parser.add_argument('new_name', help='New name for the subscription')
|
||||
|
||||
# Set URL subscription command
|
||||
set_url_parser = subscription_subparsers.add_parser('set-url', help='Update the URL for a subscription')
|
||||
set_url_parser.add_argument('name', help='Name of the subscription')
|
||||
set_url_parser.add_argument('url', help='New URL for the subscription')
|
||||
|
||||
# Activate subscription command
|
||||
activate_parser = subscription_subparsers.add_parser('activate', help='Activate a subscription')
|
||||
activate_parser.add_argument('name', help='Name of the subscription to activate')
|
||||
@ -164,6 +169,8 @@ def main() -> None:
|
||||
subscription_manager.delete_subscription(args.name)
|
||||
elif args.subcommand == 'rename':
|
||||
subscription_manager.rename_subscription(args.name, args.new_name)
|
||||
elif args.subcommand == 'set-url':
|
||||
subscription_manager.set_subscription_url(args.name, args.url)
|
||||
elif args.subcommand == 'activate':
|
||||
subscription_manager.activate_subscription(args.name)
|
||||
elif args.subcommand == 'list':
|
||||
@ -262,7 +269,6 @@ def main() -> None:
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
raise
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -107,3 +107,11 @@ class SubscriptionsData(BaseModel):
|
||||
subscription.name = new_name
|
||||
self.subscriptions[new_name] = subscription
|
||||
return True
|
||||
|
||||
def set_subscription_url(self, name: str, url: str) -> bool:
|
||||
"""Update the URL for a subscription."""
|
||||
if name not in self.subscriptions:
|
||||
return False
|
||||
|
||||
self.subscriptions[name].url = url
|
||||
return True
|
||||
@ -21,7 +21,7 @@ class SubscriptionManager:
|
||||
self.subscriptions_dir = self.storage.config_dir / "subscriptions"
|
||||
self.subscriptions_dir.mkdir(exist_ok=True)
|
||||
|
||||
def add_subscription(self, url: str, name: str) -> None:
|
||||
def add_subscription(self, name: str, url: str) -> None:
|
||||
"""Add a new subscription."""
|
||||
subscription = self.subscriptions_data.add_subscription(name, url)
|
||||
|
||||
@ -45,11 +45,12 @@ class SubscriptionManager:
|
||||
try:
|
||||
# Download the subscription content
|
||||
headers = {
|
||||
'User-Agent': self.config.default_user_agent
|
||||
# 'User-Agent': self.config.default_user_agent
|
||||
}
|
||||
timeout = self.config.timeout_seconds
|
||||
# timeout = self.config.timeout_seconds
|
||||
|
||||
response = requests.get(url, headers=headers, timeout=timeout)
|
||||
# response = requests.get(url, headers=headers, timeout=timeout)
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
|
||||
# File path without timestamp
|
||||
@ -121,6 +122,16 @@ class SubscriptionManager:
|
||||
else:
|
||||
print(f"❌ Failed to rename subscription: '{old_name}' not found or '{new_name}' already exists")
|
||||
|
||||
def set_subscription_url(self, name: str, url: str) -> None:
|
||||
"""Update the URL for a subscription."""
|
||||
if self.subscriptions_data.set_subscription_url(name, url):
|
||||
if self.storage.save_subscriptions(self.subscriptions_data):
|
||||
print(f"✅ Updated URL for subscription '{name}': {url}")
|
||||
else:
|
||||
print("❌ Failed to save subscription")
|
||||
else:
|
||||
print(f"❌ Subscription '{name}' not found")
|
||||
|
||||
def activate_subscription(self, name: str) -> None:
|
||||
"""Activate a subscription."""
|
||||
if self.subscriptions_data.set_active(name):
|
||||
|
||||
Reference in New Issue
Block a user