Displaying Python Script Outputs on Conky Panels
In this post, I'll demonstrate a simple way to display data from API requests directly on desktop panels using Python and Conky.
Objective
The goal is to fetch information from an API and show it on a desktop panel. For this example, I'll use Python for the API requests and Conky to create the panels.
We’ll fetch the Bitcoin exchange rates in USD and BRL using the economia.awesomeapi.com.br API. Then, we’ll configure Conky to execute the Python script every hour and display the output on the panel. I’ve also added some basic styling to make the panel look better.
Python Script: btc_data.py
Below is the Python script that retrieves Bitcoin rates and formats the output for the Conky panel:
import requests API_URL = "https://economia.awesomeapi.com.br/json/last/BTC-USD,BTC-BRL" try: response = requests.get(API_URL) data = response.json() btc_usd = data.get("BTCUSD", {}) btc_brl = data.get("BTCBRL", {}) usd_alta = f"$${float(btc_usd.get('high', 'N/A')):,.2f}" usd_baixa = f"$${float(btc_usd.get('low', 'N/A')):,.2f}" brl_alta = f"R$${float(btc_brl.get('high', 'N/A')):,.2f}" brl_baixa = f"R$${float(btc_brl.get('low', 'N/A')):,.2f}" formatted_data = ( "\n\n${color white}BTC - USD\n${color}${color green} High: ${color}${color white}"+usd_alta+"\n${color red} Low: ${color}${color white}"+usd_baixa+"\n\n" "${color white}BTC - BRL\n${color}${color green} High: ${color}${color white}"+brl_alta+"\n${color red} Low: ${color}${color white}"+brl_baixa+"\n" ) print(formatted_data) except Exception as e: print(e)
Conky Configuration: btc_ck.conf
Here’s the configuration file for Conky. It runs the Python script every hour (3600 seconds) and displays the formatted output:
conky.config = { default_color = '#afafaf', own_window = true, own_window_type = 'normal', own_window_transparent = true, own_window_colour = '#000000', own_window_hints = 'undecorated, skip_taskbar', use_spacer = 'right', border_inner_margin = 20, alignment = 'middle_right', use_xft = true, double_buffer = true, font = 'Monospace:size=8:style=semibold', gap_x = 80, update_interval = 1.0, } conky.text = [[ ${image /home/.../bitcoin-btc-logo.png -n -p 50,1 -s 25x25} ${execpi 3600 python3 /home/.../btc_data.py} ]]
Key Points:
- API Data: Fetching Bitcoin’s high and low prices in both USD and BRL.
- Update Frequency: The panel updates every hour via the execpi function.
- Styling: Some basic customization is applied to improve the panel’s appearance.
Running the Project
- Save the Python script (btc_data.py) and the Conky configuration file (btc_ck.conf) in the desired directory.
- Update the file paths in btc_ck.conf as needed (e.g., Python script location, Bitcoin logo image).
- Start Conky with the configuration:
conky -c /path/to/btc_ck.conf
The above is the detailed content of Displaying Python Script Outputs on Conky Panels. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
