-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
106 lines (86 loc) · 2.94 KB
/
cli.py
File metadata and controls
106 lines (86 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
"""
Reddit Ban Tracker Bot - Command Line Interface
Enhanced version with proper argument parsing and configuration options.
"""
import argparse
import sys
from reddit_ban_tracker import RedditBanTracker
def create_parser():
"""Create and configure the command line argument parser."""
parser = argparse.ArgumentParser(
description='Reddit Ban Tracker - Monitor and track bans from Reddit subreddits',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s # Monitor default subreddits
%(prog)s -s announcements,help,reddit # Monitor specific subreddits
%(prog)s --limit 100 # Fetch up to 100 entries
%(prog)s --config mybot.env # Use custom config file
%(prog)s --storage my_bans.json # Use custom storage file
%(prog)s --subreddits askreddit --limit 50 # Monitor askreddit with limit
""")
parser.add_argument(
'-s', '--subreddits',
type=str,
default='announcements,reddit',
help='Comma-separated list of subreddits to monitor (default: announcements,reddit)'
)
parser.add_argument(
'-l', '--limit',
type=int,
default=50,
help='Maximum number of entries to fetch per subreddit (default: 50)'
)
parser.add_argument(
'-c', '--config',
type=str,
default='.env',
help='Path to configuration file (default: .env)'
)
parser.add_argument(
'--storage',
type=str,
default='banned_users.json',
help='Path to JSON storage file (default: banned_users.json)'
)
parser.add_argument(
'-v', '--verbose',
action='store_true',
help='Enable verbose logging output'
)
parser.add_argument(
'--version',
action='version',
version='Reddit Ban Tracker 1.0'
)
return parser
def main():
"""Main entry point with enhanced CLI."""
parser = create_parser()
args = parser.parse_args()
# Parse subreddits list
subreddits = [s.strip() for s in args.subreddits.split(',') if s.strip()]
if not subreddits:
print("Error: No subreddits specified")
sys.exit(1)
print(f"Reddit Ban Tracker v1.0")
print(f"Monitoring subreddits: {', '.join(subreddits)}")
print(f"Fetch limit: {args.limit}")
print(f"Config file: {args.config}")
print(f"Storage file: {args.storage}")
print("-" * 50)
try:
# Initialize and run the tracker
tracker = RedditBanTracker(
config_file=args.config,
storage_file=args.storage
)
tracker.run(subreddits, limit=args.limit)
except KeyboardInterrupt:
print("\nBot stopped by user.")
except Exception as e:
print(f"Fatal error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()