Skip to content

Commit 5df1291

Browse files
committed
v0.1
1 parent 1f110d9 commit 5df1291

5 files changed

+87
-9
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
.env*

core/notifier.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# core/notifier.py
2+
3+
class Notifier:
4+
def __init__(self):
5+
pass
6+
7+
def notify(self, updates):
8+
# Implement the notification logic here
9+
print("Notifying about updates:", updates)

core/report_generator.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# core/report_generator.py
2+
3+
class ReportGenerator:
4+
def __init__(self):
5+
pass
6+
7+
def generate_report(self, updates):
8+
# Implement the report generation logic here
9+
print("Generating report for updates:", updates)

core/subscription_manager.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# core/subscription_manager.py
2+
3+
class SubscriptionManager:
4+
def __init__(self):
5+
self.subscriptions = []
6+
7+
def get_subscription(self):
8+
print("Getting subscriptions")
9+
return self.subscriptions
10+
11+
def add_subscription(self, repository):
12+
if repository not in self.subscriptions:
13+
self.subscriptions.append(repository)
14+
print(f"Added subscription: {repository}")
15+
else:
16+
print(f"Subscription already exists: {repository}")
17+
18+
def remove_subscription(self, repository):
19+
if repository in self.subscriptions:
20+
self.subscriptions.remove(repository)
21+
print(f"Removed subscription: {repository}")
22+
else:
23+
print(f"Subscription not found: {repository}")

main.py

+44-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
1-
from core.subscription import SubscriptionManager
1+
import argparse
2+
import threading
3+
import time
4+
from core.subscription_manager import SubscriptionManager
25
from core.update_fetcher import UpdateFetcher
36
from core.notifier import Notifier
47
from core.report_generator import ReportGenerator
58

69
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+
716
subscription_manager = SubscriptionManager()
817
fetcher = UpdateFetcher()
918
notifier = Notifier()
1019
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
1954

2055
if __name__ == "__main__":
2156
main()

0 commit comments

Comments
 (0)