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
76
ino.py
76
ino.py
|
@ -35,7 +35,7 @@ import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from config import config
|
from config import config
|
||||||
from test2 import app, run_app
|
from oauth import app, run_app
|
||||||
from refresh import refresh
|
from refresh import refresh
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -79,7 +79,14 @@ client_id = config['client_id']
|
||||||
client_secret = config['client_secret']
|
client_secret = config['client_secret']
|
||||||
refresh_token = config['refresh_token']
|
refresh_token = config['refresh_token']
|
||||||
summary = config['summary']
|
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
|
# Make a request to get unread counts
|
||||||
unread_response = APIrequest(unread_counts_url, bearer)
|
unread_response = APIrequest(unread_counts_url, bearer)
|
||||||
|
@ -129,49 +136,42 @@ print(feeds_list_data)
|
||||||
print('\n\n')
|
print('\n\n')
|
||||||
print(unread_data)
|
print(unread_data)
|
||||||
|
|
||||||
for item in unread_data['unreadcounts']:
|
for unread in unread_data['unreadcounts']:
|
||||||
|
|
||||||
# Get the count of unread items
|
unread['count'] = int(unread['count'])
|
||||||
count = int(item['count'])
|
if unread['count'] > 0:
|
||||||
|
unreadcounts[unread['id']] = unread['count']
|
||||||
|
|
||||||
# If there are unread items
|
for subscribed in feeds_list_data['subscriptions']:
|
||||||
# get the ID of the items
|
|
||||||
|
|
||||||
if count > 0:
|
if subscribed['categories']:
|
||||||
ID = item['id']
|
if subscribed['categories'][0]['id'] not in categories:
|
||||||
|
categories.append(subscribed['categories'][0]['id'])
|
||||||
"""
|
|
||||||
Loop through the feeds subscriptions.
|
subscriptions[subscribed['id']] = subscribed['title']
|
||||||
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.
|
|
||||||
|
|
||||||
This is because Inoreader feeds IDs are not
|
for unread_id, count in unreadcounts.items():
|
||||||
human friendly labels.
|
|
||||||
"""
|
if count == 1:
|
||||||
|
new_articles = singular_article
|
||||||
|
else:
|
||||||
|
new_articles = plural_articles
|
||||||
|
|
||||||
|
count = str(count)
|
||||||
|
|
||||||
|
if not unread_id in categories:
|
||||||
|
if unread_id.split("/")[-1] == "reading-list":
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
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.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if count == 1:
|
|
||||||
new_articles = config['singular_article']
|
|
||||||
else:
|
else:
|
||||||
new_articles = config['plural_articles']
|
|
||||||
count = str(count)
|
if unread_id in (k for k,v in subscriptions.items()):
|
||||||
message = message + count + " " + new_articles + " " + ID + "\n"
|
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:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
22
oauth.py
22
oauth.py
|
@ -118,10 +118,11 @@ def shutdown():
|
||||||
|
|
||||||
serve(app, host=host, port=port)'''
|
serve(app, host=host, port=port)'''
|
||||||
|
|
||||||
|
# Function to start the Flask server
|
||||||
|
def start_server():
|
||||||
|
serve(app, host=host, port=port)
|
||||||
|
|
||||||
def run_prod():
|
def run_prod():
|
||||||
# Function to start the Flask server
|
|
||||||
def start_server():
|
|
||||||
serve(app, host=host, port=port)
|
|
||||||
|
|
||||||
# Create a new thread for the Flask server
|
# Create a new thread for the Flask server
|
||||||
server_thread = threading.Thread(target=start_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
|
# Launch Firefox with the new profile and open the URL
|
||||||
subprocess.run([browser_path, "-P", "new_profile", "-no-remote", home_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():
|
def run_app():
|
||||||
|
|
||||||
|
@ -147,8 +160,7 @@ def run_app():
|
||||||
run_prod()
|
run_prod()
|
||||||
else:
|
else:
|
||||||
print(prod_status)
|
print(prod_status)
|
||||||
webbrowser.open(home_url)
|
run_dev()
|
||||||
app.run()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#app.run()
|
#app.run()
|
||||||
|
|
Loading…
Reference in New Issue