Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature: reload feed lookup in CLI via hotkey (Issue #14) #20

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions defe/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import argparse
import sys
import keyboard
import pynput

from colorama import Fore, Style, init

Expand Down Expand Up @@ -101,35 +103,51 @@ def main():

args = parser.parse_args()

if args.feed == "general":
hotkey_listener()
set_feed(args.feed, args.max_feed_count, False)


def set_feed(feed_arg, max_feed_count, refresh):
if feed_arg == "general":
data = feedcore.all_feed()
for item in data[: args.max_feed_count]:
for item in data[:max_feed_count]:
print(Fore.RED + Style.BRIGHT + str(data.index(item) + 1), end=". ")
defy(item["feed_src"], item["title"], item["link"])
defy_prompt(data)

if args.feed == "news":
if not refresh:
defy_prompt(data, feed_arg, max_feed_count)
else:
return data
if feed_arg == "news":
data = feedcore.news_feed()
for item in data[: args.max_feed_count]:
for item in data[:max_feed_count]:
print(Fore.RED + Style.BRIGHT + str(data.index(item) + 1), end=". ")
defy(item["feed_src"], item["title"], item["link"])
defy_prompt(data)
if args.feed == "newsletters":
if not refresh:
defy_prompt(data, feed_arg, max_feed_count)
else:
return data
if feed_arg == "newsletters":
data = feedcore.newsletters_feeds()
for item in data[: args.max_feed_count]:
for item in data[:max_feed_count]:
print(Fore.RED + Style.BRIGHT + str(data.index(item) + 1), end=". ")
defy(item["feed_src"], item["title"], item["link"])
defy_prompt(data)
if args.feed == "podcasts":
if not refresh:
defy_prompt(data, feed_arg, max_feed_count)
else:
return data
if feed_arg == "podcasts":
data = feedcore.podcasts_feeds()
for item in data[: args.max_feed_count]:
for item in data[:max_feed_count]:
print(Fore.RED + Style.BRIGHT + str(data.index(item) + 1), end=". ")
if item:
defy(item["feed_src"], item["title"], item["link"])
else:
pass
defy_prompt(data)
if args.feed == "feeders":
if not refresh:
defy_prompt(data, feed_arg, max_feed_count)
else:
return data
if feed_arg == "feeders":
feeds = ["general", "news", "podcasts", "newsletters"]
print(
Style.BRIGHT + "\ndefe fetches feeds of these sources 😃", end="\n\n",
Expand All @@ -148,5 +166,14 @@ def main():
)


def on_press():
controller = pynput.keyboard.Controller()
controller.type("REFRESH\n")


def hotkey_listener():
keyboard.add_hotkey("alt+r", on_press)


if __name__ == "__main__":
main()
13 changes: 10 additions & 3 deletions defe/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def defy(src, title, link):
print(Fore.BLUE + Style.BRIGHT + link, end="\n\n")


def defy_prompt(feed):
def defy_prompt(feed, feed_type, max_feed_count):
init(autoreset=True)
while 1:
try:
Expand All @@ -27,10 +27,17 @@ def defy_prompt(feed):
input(Fore.GREEN + Style.BRIGHT + "Enter Feed Index to open : ")
)
print(Style.RESET_ALL)
print(Style.BRIGHT + "Opening Link in your default browser ...")
webbrowser.open(feed[int(feed_to_open) - 1].link)
if "REFRESH" not in feed_to_open:
print(Style.BRIGHT + "Opening Link in your default browser ...")
webbrowser.open(feed[int(feed_to_open) - 1].link)
else:
print(chr(27) + "[2J") # clear the output
feed = set_feed(feed_type, max_feed_count, True)
except ValueError:
print(Style.BRIGHT + "Enter Valid Index 😟")
except KeyboardInterrupt:
# Oh no!, come back again :(
sys.exit()


from defe.__main__ import set_feed