💾 Archived View for woodpeckersnest.space › ~schapps › projects › newsline.gmi captured on 2024-12-17 at 09:46:56. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
A news bar for Conky which is powered by the Python computer language.
Newsline is a news reader which appears as a horizontal bar and is intended to be utilized with feeds that are expected to be updated at a higher frequency, mostly announcements, issue trackers, forums, geographical (e.g. weather) and vehicle traffic data.
This bar is namrly intended to be utilized on "box" desktops, such as AwesomeWM, Blackbox, dwm, Fluxbox, FVWM, Hyprland, i3, Openbox, Sway, SXMO etc., yet it is functional on Budgie, LXDE, LXQt, MATE, Trinity and Xfce desktops as well.
conky.config = { -- CORE background = true, update_interval = 20, total_run_times = 0, cpu_avg_samples = 2, net_avg_samples = 2, double_buffer = true, -- no_buffers = true, template0 = '\n', -- COLOURS default_color = '#000', -- own_window_argb_value = 70, -- own_window_argb_visual = true, own_window_colour = '#dfdfdf', -- DIMENSIONS -- minimum_height = 10, -- minimum_size = 300, minimum_width = 1920, maximum_width = 1920, -- GRAPHICS draw_borders = false, draw_graph_borders = false, draw_outline = false, draw_shades = false, short_units, -- POSITION alignment = 'bottom_middle', -- DISPLAY MONITOR -- xinerama_head = 2, -- TEXT font = 'DejaVu Sans Mono:size=17', override_utf8_locale = true, uppercase = false, use_xft = true, -- xftfont = 'Montserrat Regular:size=16', -- TYPE own_window = true, own_window_class = 'NewsLine', own_window_hints = undecorated,above,sticky,skip_taskbar,skip_pager, own_window_title = newsline, own_window_transparent = no, own_window_type = 'dock', -- for blackbox, fluxbox, i3 (top) and openbox -- own_window_type = 'panel', -- for i3 (bottom), xfce -- own_window_type = 'override', -- for xfce } conky.text = [[${scroll left 250 10 20 ${execpi 600 python newsline.py}}]]
import feedparser import sys import toml excerpts = [] toml_file = toml.load('newsline.toml') max_titles = toml_file['titles'] blacklist = toml_file['blacklist'] whitelist = toml_file['whitelist'] for url in toml_file['sources']: try: feed = feedparser.parse(url) except Exception as e: print(f"Error parsing {url}: {e}", file=sys.stderr) feed = None if feed: data = [] for entry in feed.entries: # Set whitelisted and blacklisted to False. blacklisted = whitelisted = False # Check whether a whitelisted keyword exists. for keyword in whitelist: if whitelisted: break for property in ['author', 'content', 'summary', 'title']: if whitelisted: break if property in entry: if isinstance(entry[property], list): entry_property = ' ' for content in entry[property]: if 'value' in entry[property]: entry_property += entry[property]['value'] entry[property] = entry_property if keyword.lower() in entry[property].lower(): whitelisted = True # If entry is not whitelisted, check whether a blacklisted keyword exists. if not whitelisted: for keyword in blacklist: if blacklisted: break for property in ['author', 'content', 'summary', 'title']: if blacklisted: break if property in entry: if isinstance(entry[property], list): entry_property = ' ' for content in entry[property]: if 'value' in entry[property]: entry_property += entry[property]['value'] entry[property] = entry_property if keyword.lower() in entry[property].lower(): blacklisted = True # If entry is not blacklisted, add it to the list. if not blacklisted: info = {'title' : entry['title'] if 'title' in entry else 'No title', 'author' : entry['author'] if 'author' in entry else '', 'updated' : entry['updated'] if 'updated' in entry else ''} data.append(info) if len(data) > max_titles: break excerpt = data else: excerpt = [] excerpts += excerpt # Sort entries by date. sorted_excerpts = sorted(excerpts, key=lambda x: x['updated'], reverse=True) excerpt_text = '' # Concatenate entries for excerpt in sorted_excerpts: if excerpt['author']: excerpt_text += f"{excerpt['author']}: {excerpt['title']} | " else: excerpt_text += f"{excerpt['title']} | " print(excerpt_text) sys.exit()
# Set the amount of titles per source titles = 3 # Feed URLs sources = [ "https://forum.cooltech.zone/syndication.php?type=atom1.0", "https://forums.rockbox.org/index.php?type=atom;action=.xml", "https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/issues.atom", "https://salsa.debian.org/Mobian-team.atom", "https://wiki.postmarketos.org/index.php?title=Special:RecentChanges&feed=atom", ] # Filters blacklist = ['global', 'goog', 'hmd', 'micros', 'noki', 'buntu'] whitelist = ['2780', '8110', 'argon', 'magdesign', 'weeknd']