From 23f33ffb898a373466c0b76cc8b0e1bdc44fad4c Mon Sep 17 00:00:00 2001 From: jueyaye Date: Sun, 18 Oct 2020 15:21:26 +1000 Subject: [PATCH 1/2] add random colour to progress bar for fetcher --- core/feedcore.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/feedcore.py b/core/feedcore.py index 1ef3662..c3650d7 100644 --- a/core/feedcore.py +++ b/core/feedcore.py @@ -38,6 +38,8 @@ def get_domain(link): def fetcher(category, latest=False, show_progress=False, workers=27): data = read_data(category) feeddata = cache(latest) + colour = "%06x" % random.randint(0, 0xFFFFFF) + with ThreadPoolExecutor(max_workers=workers) as executor: results = list( tqdm( @@ -46,6 +48,7 @@ def fetcher(category, latest=False, show_progress=False, workers=27): total=len(data), disable=show_progress, leave=False, + colour="#" + str(colour) ) ) From c3a37f12a7d0c383b03f57d5668f97d8b0891b8d Mon Sep 17 00:00:00 2001 From: jueyaye Date: Sun, 18 Oct 2020 15:44:58 +1000 Subject: [PATCH 2/2] pass through linter --- core/feedcore.py | 4 +++- defe/__main__.py | 6 ++++-- defe/defe.py | 4 ++-- defe/formatter.py | 52 +++++++++++++++++++++++++++++++---------------- 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/core/feedcore.py b/core/feedcore.py index c3650d7..a8e230c 100644 --- a/core/feedcore.py +++ b/core/feedcore.py @@ -48,12 +48,13 @@ def fetcher(category, latest=False, show_progress=False, workers=27): total=len(data), disable=show_progress, leave=False, - colour="#" + str(colour) + colour="#" + str(colour), ) ) return results + def filter_mpeg_link(result): for item in result: # filter only mp3 links @@ -63,6 +64,7 @@ def filter_mpeg_link(result): return result + def podcasts_feeds(show_progress=False, workers=27): result = fetcher("podcasts", True, show_progress, workers) diff --git a/defe/__main__.py b/defe/__main__.py index c0d0143..a4531cd 100644 --- a/defe/__main__.py +++ b/defe/__main__.py @@ -132,7 +132,8 @@ def main(): if args.feed == "feeders": feeds = ["general", "news", "podcasts", "newsletters"] print( - Style.BRIGHT + "\ndefe fetches feeds of these sources 😃", end="\n\n", + Style.BRIGHT + "\ndefe fetches feeds of these sources 😃", + end="\n\n", ) for f in feeds: print("\n" + Fore.BLUE + Style.BRIGHT + f.capitalize(), end=" ") @@ -144,7 +145,8 @@ def main(): print("\n\n" + Style.BRIGHT + "Want to add more ? 🤔") print( - Style.BRIGHT + "Open a PR at https://github.com/Bhupesh-V/defe", end="\n\n", + Style.BRIGHT + "Open a PR at https://github.com/Bhupesh-V/defe", + end="\n\n", ) diff --git a/defe/defe.py b/defe/defe.py index 259721b..6dab4e3 100644 --- a/defe/defe.py +++ b/defe/defe.py @@ -14,8 +14,8 @@ class NoSuchFeederCategory(Exception): class feed: def __init__(self, progress=True): """Args - - progress - - workers + - progress + - workers """ self.show_progress = progress self.feeder_categories = ["general", "news", "podcasts", "newsletters"] diff --git a/defe/formatter.py b/defe/formatter.py index a6efb60..3d2cb8d 100644 --- a/defe/formatter.py +++ b/defe/formatter.py @@ -4,7 +4,7 @@ from colorama import Fore, Style, init import webbrowser import sys -import vlc## +import vlc ## def defy(src, title, link): @@ -29,23 +29,39 @@ def defy_prompt(feed, podcasts=False): ) print(Style.RESET_ALL) if podcasts: - player = vlc.MediaPlayer(feed[int(feed_to_open) -1]["links"][0]["href"]) - print(Fore.GREEN + Style.BRIGHT + "Now playing: " + Fore.YELLOW + Style.BRIGHT + feed[int(feed_to_open)-1]["title"]) - player.play() - while 1: - action = str(input(Fore.GREEN + Style.BRIGHT + "pause/stop [p/s] : ")).lower() - if action == "p": - player.pause() - input(Fore.GREEN + Style.BRIGHT + "Press enter to continue : ") - player.play() - elif action == "s": - player.stop() - break - else: - print(Style.BRIGHT + "Please type 'p' to pause or 's' to stop the podcast") - else: - print(Style.BRIGHT + "Opening Link in your default browser ...") - webbrowser.open(feed[int(feed_to_open) - 1].link) + player = vlc.MediaPlayer( + feed[int(feed_to_open) - 1]["links"][0]["href"] + ) + print( + Fore.GREEN + + Style.BRIGHT + + "Now playing: " + + Fore.YELLOW + + Style.BRIGHT + + feed[int(feed_to_open) - 1]["title"] + ) + player.play() + while 1: + action = str( + input(Fore.GREEN + Style.BRIGHT + "pause/stop [p/s] : ") + ).lower() + if action == "p": + player.pause() + input( + Fore.GREEN + Style.BRIGHT + "Press enter to continue : " + ) + player.play() + elif action == "s": + player.stop() + break + else: + print( + Style.BRIGHT + + "Please type 'p' to pause or 's' to stop the podcast" + ) + else: + print(Style.BRIGHT + "Opening Link in your default browser ...") + webbrowser.open(feed[int(feed_to_open) - 1].link) except ValueError: print(Style.BRIGHT + "Enter Valid Index 😟") except KeyboardInterrupt: