|
1 |
| -from core.subscription import SubscriptionManager |
| 1 | +import argparse |
| 2 | +import threading |
| 3 | +import time |
| 4 | +from core.subscription_manager import SubscriptionManager |
2 | 5 | from core.update_fetcher import UpdateFetcher
|
3 | 6 | from core.notifier import Notifier
|
4 | 7 | from core.report_generator import ReportGenerator
|
5 | 8 |
|
6 | 9 | def main():
|
| 10 | + parser = argparse.ArgumentParser(description="Interactive Tool for Managing Subscriptions and Updates") |
| 11 | + parser.add_argument('-a', '--add-subscription', type=str, nargs='?', const='', help='Add a new subscription') |
| 12 | + parser.add_argument('-r', '--remove-subscription', type=str, help='Remove an existing subscription') |
| 13 | + parser.add_argument('-f', '--fetch-updates', action='store_true', help='Fetch updates immediately') |
| 14 | + args = parser.parse_args() |
| 15 | + |
7 | 16 | subscription_manager = SubscriptionManager()
|
8 | 17 | fetcher = UpdateFetcher()
|
9 | 18 | notifier = Notifier()
|
10 | 19 | report_generator = ReportGenerator()
|
11 |
| - |
12 |
| - repositories = subscription_manager.get_subscribed_repositories() |
13 |
| - updates = fetcher.fetch_updates(repositories) |
14 |
| - |
15 |
| - if updates: |
16 |
| - notifier.notify(updates) |
17 |
| - |
18 |
| - report_generator.generate_report(updates) |
| 20 | + |
| 21 | + if args.add_subscription: |
| 22 | + subscription_manager.add(args.add_subscription) |
| 23 | + print(f"Added subscription: {args.add_subscription}") |
| 24 | + |
| 25 | + if args.remove_subscription: |
| 26 | + subscription_manager.remove(args.remove_subscription) |
| 27 | + print(f"Removed subscription: {args.remove_subscription}") |
| 28 | + |
| 29 | + if args.fetch_updates: |
| 30 | + repositories = subscription_manager.get_subscription() |
| 31 | + updates = fetcher.fetch_updates(repositories) |
| 32 | + if updates: |
| 33 | + notifier.notify(updates) |
| 34 | + report_generator.generate_report(updates) |
| 35 | + print("Fetched and processed updates") |
| 36 | + |
| 37 | + # Start the scheduler in the background |
| 38 | + scheduler_thread = threading.Thread(target=scheduler, args=(subscription_manager, fetcher, notifier, report_generator)) |
| 39 | + scheduler_thread.daemon = True |
| 40 | + scheduler_thread.start() |
| 41 | + |
| 42 | + # Keep the main thread alive to accept commands |
| 43 | + while True: |
| 44 | + time.sleep(1) |
| 45 | + |
| 46 | +def scheduler(subscription_manager, fetcher, notifier, report_generator): |
| 47 | + while True: |
| 48 | + repositories = subscription_manager.get_subscription() |
| 49 | + updates = fetcher.fetch_updates(repositories) |
| 50 | + if updates: |
| 51 | + notifier.notify(updates) |
| 52 | + report_generator.generate_report(updates) |
| 53 | + time.sleep(3 * 3600) # Run every three hour |
19 | 54 |
|
20 | 55 | if __name__ == "__main__":
|
21 | 56 | main()
|
0 commit comments