Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📰 News display module for Polybar & i3blocks

License

NotificationsYou must be signed in to change notification settings

zemmsoares/polybar-news

Repository files navigation

A module to display the latest news on Polybar and i3blocks from multiple sources.

Polybar-news

Table of Contents

Dependencies

  • requests - Python requests
  • zscroll - For Polybar text scrolling(optional)
  • scroll - For i3blocks text scrolling(optional)

Setup Instructions

  1. Clone the repository

  2. Set up a Python environment and install dependencies(optional but recommended)

    # Create the environmentpython -m venv /path/to/environment# Activate the environmentsource /path/to/environment/bin/activate# Install the dependenciespip install requests
    *Note: If you don't want to use a Python virtual environment, you can install the dependencies globally with pip install requests, but be aware this might conflict with other Python software on your system.

  3. Create aconfig.py file in the root of the project folder. You can use the following examples as a template depending on the news source you want to use.

    For Hackernews:

    news_source="hackernews"# Number of news articles to fetchnumber_news=5

    For NewsAPI:

    news_source="newsapi"# Number of news articles to fetchnumber_news=5# Register at NewsAPI.org to receive your API key.api_key="<your_api_key_here>"# Configure your desired news sources.# For available options, refer to NewsAPI.org/sources.sources="<your_desired_sources_here>"# Configure your desired country.# Note: You can only filter either by sources or country. (leave one empty "")country="<your_desired_country_here>"
  4. Add the following modules to your Polybar or i3blocks configuration file. Be sure to replace/path/to/environment and/path/to/polybar-news with your own paths.

    Polybar Modules

    ; Fetches news from API and saves it into articles.json[module/news-fetcher]type = custom/scriptexec = /path/to/environment/bin/python /path/to/polybar-news/news_fetcher.py; This module runs every 900 seconds (15 minutes) if the news source is NewsAPI due to its API limit of 100 calls per day for free tier accountsinterval = 900; Rotates through the list of news articles in articles.json; and saves the current article's title and URL in separate text files; This module runs every X seconds to change the displayed article[module/news-rotator]type = custom/scriptinterval = 60exec = /path/to/environment/bin/python /path/to/polybar-news/news_rotator.py; Displays the current news article title; Refreshes every second to ensure updated information is displayed; On left click, opens the current article's URL in the default web browser[module/news-display]type = custom/scripttail = trueinterval = 1format-prefix =""format = <label>label-padding = 1label-maxlen = 50exec = /path/to/polybar-news/print_current_article.shclick-left = < /path/to/polybar-news/current_article_url.txt xargs -I % xdg-open %

    i3Blocks

    # Fetches news from API and saves it into articles.json[news-fetcher]command=/path/to/environment/bin/python /path/to/polybar-news/news_fetcher.pyinterval=900separator=false# Rotates through the list of news articles in articles.json# and saves the current article's title and URL in separate text files# This module runs every X seconds to change the displayed article[news-rotator]command=/path/to/environment/bin/python /path/to/polybar-news/news_rotator.pyinterval=60separator=false# Displays the current news article title# Refreshes every second to ensure updated information is displayed# On left click, opens the current article's URL in the default web browser[news-display]command=path/to/polybar-news/print_current_article.shinterval=1separator=truemarkup=pangolabel=command=if [ $button ]; then xdg-open "$(cat /path/to/polybar-news/current_article_url.txt)"; else $HOME/.config/i3/i3blocks/scroll path/to/polybar-news/print_current_article.sh; fi
  5. Text Scrolling (Optional)

    Polybar

    1. Installzscroll

    2. Modify thenews-display module in your Polybar configuration file to use thescroll_current_article.sh script:

      [module/news-display]...exec = /path/to/polybar-news/scroll_current_article.sh...

    i3blocks

    1. Download thescroll script:

      curl -o~/.config/i3blocks/scroll https://raw.githubusercontent.com/Anachron/i3blocks/master/blocks/scroll
    2. Make thescroll script executable:

      chmod +x~/.config/i3blocks/scroll
    3. Modify thenews-display module in your i3blocks configuration file to use thescroll script andprint_current_article.sh script:

      [news-display]command=~/.config/i3blocks/scroll /path/to/polybar-news/print_current_article.shinterval=1separator=truemarkup=pangolabel=command=if [ $button ]; then xdg-open "$(cat /path/to/polybar-news/current_article_url.txt)"; else $HOME/.config/i3/i3blocks/scroll path/to/polybar-news/print_current_article.sh; fi

Contributing

Contributions are always welcome! Feel free to open a pull request to contribute code, or create an issue to report a bug or suggest a new feature.

License

This project is licensed under the MIT License - see theLICENSE file for details.

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp