Skip to content

Commit 4e5ee4e

Browse files
authored
spacer_symbol config option for bar tickers (#76)
* spacer_symbol config option for bar tickers * v1.4.0 * expand example config for tests * expand quotes test fixture * install pre-commit
1 parent ea6d883 commit 4e5ee4e

File tree

6 files changed

+197
-20
lines changed

6 files changed

+197
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ The information displayed can then be customised by editing the `config.ini` con
7171
[general]
7272
currency = eur
7373
currency_symbol = €
74+
spacer_symbol = |
7475
display = price,percent_change_24h,percent_change_7d
7576
api_key = your_coinmarketcap_api_key
7677

@@ -91,6 +92,7 @@ volume_precision = 2
9192

9293
- **currency:** Any valid currency code should be accepted
9394
- **currency_symbol:** A corresponding symbol of the currency you wish to display
95+
- **spacer_symbol:** A string/character to use as a spacer between tickers. Comment out to disable.
9496
- **api_key:** CoinmarketCap API key obtained from their [API Dashboard](https://coinmarketcap.com/api).
9597
- **display:** A list of metrics you wish to display for each crypto currency. No spaces.
9698
Valid options are:

config.ini.example

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
[general]
22
currency = eur
33
currency_symbol = €
4-
# display options: price,percent_change_1h,percent_change_24h,percent_change_7d,percent_change_30d,percent_change_60d,percent_change_90d,volume_24h,volume_change_24h
54
display = price,percent_change_24h
6-
7-
# set the key here, or with env COINMARKETCAP_API_KEY
5+
spacer_symbol = |
86
api_key = your_coinmarketcap_api_key
97

108
[btc]
@@ -16,6 +14,20 @@ volume_precision = 2
1614

1715
[eth]
1816
icon = 
17+
in_tooltip = false
18+
price_precision = 2
19+
change_precision = 2
20+
volume_precision = 2
21+
22+
[avax]
23+
icon = AVAX
24+
in_tooltip = true
25+
price_precision = 2
26+
change_precision = 2
27+
volume_precision = 2
28+
29+
[dot]
30+
icon = DOT
1931
in_tooltip = true
2032
price_precision = 2
2133
change_precision = 2

poetry.lock

Lines changed: 137 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
[tool.poetry]
22
name = "waybar-crypto"
3-
version = "v1.3.1"
3+
version = "v1.4.0"
44
description = "A Waybar module for displaying cryptocurrency market information from CoinMarketCap."
55
authors = ["Ross <git@ross.ch>"]
66
license = "MIT"
77

88
[tool.poetry.dependencies]
9-
python = "^3.8"
9+
python = "^3.9"
1010
requests = "^2.32.0"
1111

1212
[tool.poetry.group.dev.dependencies]
1313
ruff = "^0.4.5"
1414
bandit = "^1.7.8"
1515
pytest = "^8.2.1"
1616
pytest-cov = "^5.0.0"
17+
pre-commit = "^3.7.1"
1718

1819
[tool.ruff]
1920
line-length = 100

tests/test_waybar_crypto.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,36 @@ def quotes_latest():
5353
}
5454
},
5555
},
56+
"AVAX": {
57+
"quote": {
58+
"EUR": {
59+
"price": 34.15081432131667,
60+
"volume_24h": 206005212.6801803,
61+
"volume_change_24h": -21.5639,
62+
"percent_change_1h": -0.1101364,
63+
"percent_change_24h": -2.21628843,
64+
"percent_change_7d": 2.46514204,
65+
"percent_change_30d": 3.78312279,
66+
"percent_change_60d": -30.74974196,
67+
"percent_change_90d": -0.83220421,
68+
}
69+
},
70+
},
71+
"DOT": {
72+
"quote": {
73+
"EUR": {
74+
"price": 6.9338115798384905,
75+
"volume_24h": 145060142.27706677,
76+
"volume_change_24h": 0.3964,
77+
"percent_change_1h": 0.59467025,
78+
"percent_change_24h": 3.37180336,
79+
"percent_change_7d": 7.19067559,
80+
"percent_change_30d": 8.73368475,
81+
"percent_change_60d": -19.8413195,
82+
"percent_change_90d": -2.24744556,
83+
}
84+
}
85+
},
5686
},
5787
}
5888

waybar_crypto.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
class ConfigGeneral(TypedDict):
4747
currency: str
4848
currency_symbol: str
49+
spacer_symbol: str
4950
display_options: list[str]
5051
display_options_format: dict[str, str]
5152
api_key: str
@@ -176,6 +177,10 @@ def __parse_config_path(self, config_path: str) -> Config:
176177
currency = cfp.get("general", "currency").upper()
177178
currency_symbol = cfp.get("general", "currency_symbol")
178179

180+
spacer_symbol = ""
181+
if "spacer_symbol" in cfp["general"]:
182+
spacer_symbol = cfp.get("general", "spacer_symbol")
183+
179184
# Get a list of the chosen display options
180185
display_options: list[str] = cfp.get("general", "display").split(",")
181186

@@ -205,6 +210,7 @@ def __parse_config_path(self, config_path: str) -> Config:
205210
"general": {
206211
"currency": currency,
207212
"currency_symbol": currency_symbol,
213+
"spacer_symbol": spacer_symbol,
208214
"display_options": display_options,
209215
"display_options_format": display_options_format,
210216
"api_key": api_key,
@@ -258,6 +264,9 @@ def waybar_output(self, quotes_latest: ResponseQuotesLatest) -> WaybarOutput:
258264
currency = self.config["general"]["currency"]
259265
display_options = self.config["general"]["display_options"]
260266
display_options_format = self.config["general"]["display_options_format"]
267+
spacer = self.config["general"]["spacer_symbol"]
268+
if spacer != "":
269+
spacer = f" {spacer}"
261270

262271
output_obj: WaybarOutput = {
263272
"text": "",
@@ -298,7 +307,7 @@ def waybar_output(self, quotes_latest: ResponseQuotesLatest) -> WaybarOutput:
298307
output_obj["tooltip"] += output
299308
else:
300309
if output_obj["text"] != "":
301-
output = f" {output}"
310+
output = f"{spacer} {output}"
302311
output_obj["text"] += output
303312

304313
return output_obj

0 commit comments

Comments
 (0)