Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptorum authored Nov 6, 2024
2 parents 16d3df0 + 708b402 commit df9bfb1
Show file tree
Hide file tree
Showing 30 changed files with 2,208 additions and 447 deletions.
2 changes: 1 addition & 1 deletion apps/airbnbcalendar/airbnb_calendar.star
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def listing(url, height):

dtstart_list = re.match(r"DTSTART;VALUE=DATE:(.{4})(.{2})(.{2})", ical)
dtend_list = re.match(r"DTEND;VALUE=DATE:(.{4})(.{2})(.{2})", ical)
summary_list = re.match(r"SUMMARY:(.+)", ical)
summary_list = re.match(r"SUMMARY:([^\r\n]+)", ical)
event_list = zip(dtstart_list, dtend_list, summary_list)
now = time.now()

Expand Down
151 changes: 125 additions & 26 deletions apps/apitext/api_text.star

Large diffs are not rendered by default.

215 changes: 215 additions & 0 deletions apps/aquarium/aquarium.star

Large diffs are not rendered by default.

Binary file added apps/aquarium/aquarium.webp
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/aquarium/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: aquarium
name: Aquarium
summary: Digital Aquarium
desc: A digital aquarium.
author: Robert Ison
7 changes: 7 additions & 0 deletions apps/aquarium/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Aquarium for Tidbyt

Created by: Robert Ison

Displays an aquarium scene that changes each time with different fish and color.

![Aquarium for Tidbyt](aquarium.webp)
224 changes: 224 additions & 0 deletions apps/breakingbad/breakingbad.star

Large diffs are not rendered by default.

Binary file added apps/breakingbad/breakingbad.webp
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/breakingbad/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: breakingbad
name: BreakingBad
summary: Breaking Bad title display
desc: Display text in Breaking Bad TV show format.
author: Robert Ison
5 changes: 5 additions & 0 deletions apps/breakingbad/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Breaking Bad for Tidbyt

Create your own Credit in the Breaking Bad format.

![Breaking Bad for Tidbyt](breakingbad.webp)
2 changes: 1 addition & 1 deletion apps/compactstocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Check out the official [Tidbyt documentation](https://tidbyt.dev/docs/) for inst

## Update frequency

The app fetches new data once an hour. This interval is chosen because the free tier of APIStocks allows 5000 requests per month. Considering that we are showing 5 stocks, that's 1000 requests per stock per month, which is about once an hour. If you have a paid subscription and can afford more frequent updates, you can change the interval by modifying the `ttl_seconds` variable.
The app fetches new data once an hour. This interval is chosen because the free tier of APIStocks allows 5000 requests per month. Considering that we are showing 5 stocks, that's 1000 requests per stock per month, which is about once an hour. If you have a paid subscription and can afford more frequent updates, you can change the interval by modifying the `TTL_SECONDS` variable.
Binary file modified apps/compactstocks/demo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 98 additions & 15 deletions apps/compactstocks/stocks.star
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ load("schema.star", "schema")
APISTOCKS_HOST = "apistocks.p.rapidapi.com"
APISTOCKS_URL = "https://apistocks.p.rapidapi.com/intraday"

TTL_SECONDS = 3600

def fetch_data(symbol, api_key):
rep = http.get(APISTOCKS_URL, headers = {
"x-rapidapi-host": APISTOCKS_HOST,
Expand All @@ -20,7 +22,7 @@ def fetch_data(symbol, api_key):
"symbol": symbol,
"interval": "5min",
"maxreturn": "144", # Get last 12 hours of data
}, ttl_seconds = 3600)
}, ttl_seconds = TTL_SECONDS)
if rep.status_code != 200:
print("Stock API request failed with status %d" % rep.status_code)
return None
Expand Down Expand Up @@ -51,17 +53,93 @@ def calculate_last_day_percentage(data):

return move_percentage

def render_entry(symbol, color, close_price, percentage):
# Format the price to 2 decimal places and pad to 7 characters.
def format_price(close_price):
price_value = int(close_price * 100 + 0.5) / 100.0
price_parts = str(price_value).split(".")
if len(price_parts) == 1:
price_str = price_parts[0] + ".00" # If there's no decimal part, add ".00"
elif len(price_parts[1]) == 1:
price_str = price_parts[0] + "." + price_parts[1] + "0" # If there's only 1 decimal digit, add a 0
else:
price_str = price_parts[0] + "." + price_parts[1][:2] # Limit to two decimal places

# Pad the price to 7 characters for alignment
if len(price_str) < 7:
price_str = " " * (7 - len(price_str)) + price_str
return price_str

# Format the percentage
def format_percentage(percentage):
percentage_abs = abs(percentage)
return render.Marquee(
width = 64,
child = render.Row(
children = [
render.Text("%s " % (symbol), font = "tom-thumb", color = color),
render.Text("%s " % (int(close_price * 100) / 100), font = "tom-thumb"),
render.Text("%s%%" % (int(percentage_abs * 10) / 10), font = "tom-thumb", color = "#f00" if percentage < 0 else "#0f0"),
],
),
percentage_value = int(percentage_abs * 10 + 0.5) / 10.0
if percentage_value >= 100:
# Remove decimal for values >= 100
percentage_str = str(int(percentage_value)) + "%"
else:
percentage_str = str(percentage_value) + "%"
if len(percentage_str) < 5:
percentage_str = " " * (5 - len(percentage_str)) + percentage_str
return percentage_str

# Pad or truncate the symbol to a fixed width of 4 characters.
def pad_symbol(symbol):
if len(symbol) < 4:
return symbol + " " * (4 - len(symbol))
return symbol[:4]

# Format the symbol, price, and percentage
def render_entry(symbol, color, close_price, percentage):
symbol_padded = pad_symbol(symbol)
price_str = format_price(close_price)
percentage_str = format_percentage(percentage)
percentage_color = "#f00" if percentage < 0 else "#0f0"

# Create the symbol column
symbol_column = render.Column(
cross_align = "start",
children = [
render.Text(
symbol_padded,
font = "tom-thumb",
color = color,
),
],
)

# Create the price column
price_column = render.Column(
cross_align = "end",
children = [
render.Text(
price_str,
font = "tom-thumb",
color = "#fff",
),
],
)

# Create the percentage column
percentage_column = render.Column(
cross_align = "end",
children = [
render.Text(
percentage_str,
font = "tom-thumb",
color = percentage_color,
),
],
)

# Create the main row with space between the columns
return render.Row(
main_align = "space_between",
expanded = True,
children = [
symbol_column,
price_column,
percentage_column,
],
)

def main(config):
Expand Down Expand Up @@ -95,14 +173,19 @@ def main(config):
symbol = data["Metadata"]["Symbol"]
latest = data["Results"][-1]
close_price = latest["Close"]
render_children.append(render_entry(symbol, color, close_price, calculate_last_day_percentage(data)))
percentage_change = calculate_last_day_percentage(data)
render_children.append(
render_entry(symbol, color, close_price, percentage_change),
)
else:
# Example data
render_children.append(render_entry("XMPL1", "#8ff", 114.5, 1.4) if symbol == "_EX1" else render_entry("XMPL2", "#f8f", 233.8, -6.6))
render_children.append(render_entry("XMP1", "#8ff", 114.5, 1.4) if symbol == "_EX1" else render_entry("XM2", "#f8f", 33.8, -6.6))

return render.Root(
render.Box(
child = render.Column(children = render_children),
render.Column(
children = render_children,
main_align = "center",
expanded = True,
),
)

Expand Down
Loading

0 comments on commit df9bfb1

Please sign in to comment.