-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
106 lines (72 loc) · 3.59 KB
/
main.py
File metadata and controls
106 lines (72 loc) · 3.59 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
# from format import Format
# from argument import argparse_setup
# from API import API
# from Config import Config
import tvguide as tv
def print_currently_running(data_source: dict, user_channels: list) -> None:
channels_string = ", ".join(user_channels).upper()
print(f"\n----- Showing currently running programs for: {channels_string} -----", end="")
for channel in user_channels:
data_source[channel].print_currently_running()
def print_program_times(data_source: dict, user_channels: list, user_times: list) -> None:
channels_string = ", ".join(user_channels).upper()
user_times_string = ", ".join(user_times)
print(f"\n----- Showing programs that is running at: {user_times_string} for: {channels_string} -----", end="")
for channel in user_channels:
data_source[channel].print_times(user_times)
def print_program_categories(data_source: dict, user_channels: list, user_categories: list) -> None:
user_categories_string = ", ".join(user_categories)
print(f"\n----- Searching for categories: {user_categories_string} -----", end="")
for channel in user_channels:
data_source[channel].print_categories(user_categories)
def print_program_searches(data_source: dict, user_channels: list, user_searches: list) -> None:
user_search_string = tv.Format.user_search(", ".join(user_searches))
print(f"\n----- Searching for keywords: {user_search_string} -----", end="")
for channel in user_channels:
data_source[channel].print_searches(user_searches)
def print_program_all(data_source: dict, user_channels: list) -> None:
user_channels_string = ", ".join(user_channels).upper()
print(f"\n----- Showing all programs for: {user_channels_string} -----", end="")
for channel in user_channels:
data_source[channel].print_all_programs()
def change_defaults(args, data: dict):
if args.default_channels:
tv.Config.change_defaults_user_channels(args.default_channels)
default_channels_string = ", ".join(args.default_channels).upper()
print(f"Changed default channel(s) to: {default_channels_string}")
if args.default_space_seperator:
tv.Config.change_space_seperator(args.default_space_seperator)
print(f"Changed space seperator to: {args.default_space_seperator}")
if args.justify_length:
tv.Config.change_justify_length(args.justify_length)
print(f"Changed justify length to: {args.justify_length}")
if not args.channel:
args.channel = tv.Config.get_defaults_user_channels()
default_channels_string = ", ".join(args.channel).upper()
print(f"No channel(s) chosen: using default channels ({default_channels_string})")
elif args.channel[0].lower() == "all":
args.channel = [channel for channel in data.keys()]
def print_programs(args, data):
if args.now:
print_currently_running(data, args.channel)
if args.time:
print_program_times(data, args.channel, args.time)
if args.category:
print_program_categories(data, args.channel, args.category)
if args.search:
print_program_searches(data, args.channel, args.search)
if args.all:
print_program_all(data, args.channel)
def main():
args = tv.argparse_setup()
api_data = tv.API.get_data(args.day)
my_data = tv.API.format_data(api_data, args.verbose)
change_defaults(args, my_data)
print_programs(args, my_data)
if __name__ == "__main__":
try:
main()
except KeyError:
print("Check channel name or this scraper can't use this channel")
except KeyboardInterrupt:
print("Stopped by user")