Unread feed filter & oauth refactoring
* Filters unread feed to not include folders (categories) in which the feed is present. To avoid get double notification * Refactores oauth process with functions to run the process according to development or production mode Refactores thread function to ensure flask server has started before opening the browsermaster
parent
f647a4fdee
commit
442a89b81b
70
ino.py
70
ino.py
|
@ -35,7 +35,7 @@ import time
|
|||
import sys
|
||||
import os
|
||||
from config import config
|
||||
from test2 import app, run_app
|
||||
from oauth import app, run_app
|
||||
from refresh import refresh
|
||||
|
||||
"""
|
||||
|
@ -79,7 +79,14 @@ client_id = config['client_id']
|
|||
client_secret = config['client_secret']
|
||||
refresh_token = config['refresh_token']
|
||||
summary = config['summary']
|
||||
singular_article = config['singular_article']
|
||||
plural_articles = config['plural_articles']
|
||||
singular_article = config['singular_article']
|
||||
plural_articles = config['plural_articles']
|
||||
|
||||
unreadcounts = {}
|
||||
subscriptions = {}
|
||||
categories = []
|
||||
|
||||
# Make a request to get unread counts
|
||||
unread_response = APIrequest(unread_counts_url, bearer)
|
||||
|
@ -129,49 +136,42 @@ print(feeds_list_data)
|
|||
print('\n\n')
|
||||
print(unread_data)
|
||||
|
||||
for item in unread_data['unreadcounts']:
|
||||
for unread in unread_data['unreadcounts']:
|
||||
|
||||
# Get the count of unread items
|
||||
count = int(item['count'])
|
||||
unread['count'] = int(unread['count'])
|
||||
if unread['count'] > 0:
|
||||
unreadcounts[unread['id']] = unread['count']
|
||||
|
||||
# If there are unread items
|
||||
# get the ID of the items
|
||||
for subscribed in feeds_list_data['subscriptions']:
|
||||
|
||||
if count > 0:
|
||||
ID = item['id']
|
||||
if subscribed['categories']:
|
||||
if subscribed['categories'][0]['id'] not in categories:
|
||||
categories.append(subscribed['categories'][0]['id'])
|
||||
|
||||
"""
|
||||
Loop through the feeds subscriptions.
|
||||
If the ID of unread feed is found in
|
||||
subscriptions (feeds), update ID with
|
||||
the feed title. Otherwise, extract the
|
||||
last part of the ID.
|
||||
subscriptions[subscribed['id']] = subscribed['title']
|
||||
|
||||
This is because Inoreader feeds IDs are not
|
||||
human friendly labels.
|
||||
"""
|
||||
|
||||
for item in feeds_list_data['subscriptions']:
|
||||
if ID in item['id']:
|
||||
ID = item['title']
|
||||
else:
|
||||
ID = ID.split("/")[-1]
|
||||
|
||||
"""
|
||||
Use singular or plural forms
|
||||
depending on number of unread
|
||||
articles.
|
||||
|
||||
Convert count to string and
|
||||
format the message.
|
||||
"""
|
||||
for unread_id, count in unreadcounts.items():
|
||||
|
||||
if count == 1:
|
||||
new_articles = config['singular_article']
|
||||
new_articles = singular_article
|
||||
else:
|
||||
new_articles = config['plural_articles']
|
||||
new_articles = plural_articles
|
||||
|
||||
count = str(count)
|
||||
message = message + count + " " + new_articles + " " + ID + "\n"
|
||||
|
||||
if not unread_id in categories:
|
||||
if unread_id.split("/")[-1] == "reading-list":
|
||||
|
||||
pass
|
||||
|
||||
else:
|
||||
|
||||
if unread_id in (k for k,v in subscriptions.items()):
|
||||
title = next(v for k, v in subscriptions.items() if k == unread_id)
|
||||
else:
|
||||
title = unread_id.split("/")[-1]
|
||||
|
||||
message = message + count + " " + new_articles + " " + title + "\n"
|
||||
else:
|
||||
pass
|
||||
|
||||
|
|
22
oauth.py
22
oauth.py
|
@ -118,11 +118,12 @@ def shutdown():
|
|||
|
||||
serve(app, host=host, port=port)'''
|
||||
|
||||
def run_prod():
|
||||
# Function to start the Flask server
|
||||
def start_server():
|
||||
# Function to start the Flask server
|
||||
def start_server():
|
||||
serve(app, host=host, port=port)
|
||||
|
||||
def run_prod():
|
||||
|
||||
# Create a new thread for the Flask server
|
||||
server_thread = threading.Thread(target=start_server)
|
||||
|
||||
|
@ -138,7 +139,19 @@ def run_prod():
|
|||
# Launch Firefox with the new profile and open the URL
|
||||
subprocess.run([browser_path, "-P", "new_profile", "-no-remote", home_url])
|
||||
|
||||
def run_dev():
|
||||
|
||||
# Create a new thread for the Flask server
|
||||
server_thread = threading.Thread(target=start_server)
|
||||
|
||||
# Start the Flask server thread
|
||||
server_thread.start()
|
||||
|
||||
# Wait for the Flask server to start (adjust the delay as needed)
|
||||
time.sleep(2)
|
||||
|
||||
webbrowser.open(home_url)
|
||||
app.run()
|
||||
|
||||
def run_app():
|
||||
|
||||
|
@ -147,8 +160,7 @@ def run_app():
|
|||
run_prod()
|
||||
else:
|
||||
print(prod_status)
|
||||
webbrowser.open(home_url)
|
||||
app.run()
|
||||
run_dev()
|
||||
|
||||
if __name__ == '__main__':
|
||||
#app.run()
|
||||
|
|
Loading…
Reference in New Issue