Skip to content

Commit

Permalink
Add experimental terminal version for status line
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-ceccato committed Feb 5, 2024
1 parent 40bb46f commit 1164cc0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions terminal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
9 changes: 9 additions & 0 deletions terminal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Example of i3-status-rust config:

'''
[[block]]
block = "custom"
command = "easyPomo/terminal/easypomo_term.py"
interval = 1

'''
37 changes: 37 additions & 0 deletions terminal/easypomo_term.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!.venv/bin/python

import requests
import json
import time
from datetime import timedelta

def get_online_step():
url = 'https://easypomo.duckdns.org:443/json-endpoint'

try:
response = requests.get(url)
response.raise_for_status() # Raise an HTTPError for bad responses
data = response.json()

pomo_count = data["pomoCount"]
curr_time = data["currTime"]
is_resting = data["isResting"]
is_long_resting = data["isLongResting"]

# Format currTime as MM:SS
formatted_time = str(timedelta(seconds=curr_time)).lstrip("0:") # Removing leading zeros and the hour field
# Check if less than 1 minute, then format as 00:SS
if curr_time < 60:
formatted_time = f"00:{formatted_time}"

status_icon = "⌛" if not is_resting else "☕" if is_long_resting else "☕"

print(f'{pomo_count+1}{status_icon} {formatted_time}')

except requests.exceptions.RequestException as e:
print(f'Request failed. Exception: {e}')

#while True:
# get_online_step()
# time.sleep(0.5)
get_online_step()

0 comments on commit 1164cc0

Please sign in to comment.