Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacer_symbol config option for bar tickers #76

Merged
merged 6 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The information displayed can then be customised by editing the `config.ini` con
[general]
currency = eur
currency_symbol = €
spacer_symbol = |
display = price,percent_change_24h,percent_change_7d
api_key = your_coinmarketcap_api_key

Expand All @@ -91,6 +92,7 @@ volume_precision = 2

- **currency:** Any valid currency code should be accepted
- **currency_symbol:** A corresponding symbol of the currency you wish to display
- **spacer_symbol:** A string/character to use as a spacer between tickers. Comment out to disable.
- **api_key:** CoinmarketCap API key obtained from their [API Dashboard](https://coinmarketcap.com/api).
- **display:** A list of metrics you wish to display for each crypto currency. No spaces.
Valid options are:
Expand Down
18 changes: 15 additions & 3 deletions config.ini.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[general]
currency = eur
currency_symbol = €
# 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
display = price,percent_change_24h

# set the key here, or with env COINMARKETCAP_API_KEY
spacer_symbol = |
api_key = your_coinmarketcap_api_key

[btc]
Expand All @@ -16,6 +14,20 @@ volume_precision = 2

[eth]
icon = 
in_tooltip = false
price_precision = 2
change_precision = 2
volume_precision = 2

[avax]
icon = AVAX
in_tooltip = true
price_precision = 2
change_precision = 2
volume_precision = 2

[dot]
icon = DOT
in_tooltip = true
price_precision = 2
change_precision = 2
Expand Down
151 changes: 137 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[tool.poetry]
name = "waybar-crypto"
version = "v1.3.1"
version = "v1.4.0"
description = "A Waybar module for displaying cryptocurrency market information from CoinMarketCap."
authors = ["Ross <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"
requests = "^2.32.0"

[tool.poetry.group.dev.dependencies]
ruff = "^0.4.5"
bandit = "^1.7.8"
pytest = "^8.2.1"
pytest-cov = "^5.0.0"
pre-commit = "^3.7.1"

[tool.ruff]
line-length = 100
Expand Down
30 changes: 30 additions & 0 deletions tests/test_waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ def quotes_latest():
}
},
},
"AVAX": {
"quote": {
"EUR": {
"price": 34.15081432131667,
"volume_24h": 206005212.6801803,
"volume_change_24h": -21.5639,
"percent_change_1h": -0.1101364,
"percent_change_24h": -2.21628843,
"percent_change_7d": 2.46514204,
"percent_change_30d": 3.78312279,
"percent_change_60d": -30.74974196,
"percent_change_90d": -0.83220421,
}
},
},
"DOT": {
"quote": {
"EUR": {
"price": 6.9338115798384905,
"volume_24h": 145060142.27706677,
"volume_change_24h": 0.3964,
"percent_change_1h": 0.59467025,
"percent_change_24h": 3.37180336,
"percent_change_7d": 7.19067559,
"percent_change_30d": 8.73368475,
"percent_change_60d": -19.8413195,
"percent_change_90d": -2.24744556,
}
}
},
},
}

Expand Down
11 changes: 10 additions & 1 deletion waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
class ConfigGeneral(TypedDict):
currency: str
currency_symbol: str
spacer_symbol: str
display_options: list[str]
display_options_format: dict[str, str]
api_key: str
Expand Down Expand Up @@ -176,6 +177,10 @@ def __parse_config_path(self, config_path: str) -> Config:
currency = cfp.get("general", "currency").upper()
currency_symbol = cfp.get("general", "currency_symbol")

spacer_symbol = ""
if "spacer_symbol" in cfp["general"]:
spacer_symbol = cfp.get("general", "spacer_symbol")

# Get a list of the chosen display options
display_options: list[str] = cfp.get("general", "display").split(",")

Expand Down Expand Up @@ -205,6 +210,7 @@ def __parse_config_path(self, config_path: str) -> Config:
"general": {
"currency": currency,
"currency_symbol": currency_symbol,
"spacer_symbol": spacer_symbol,
"display_options": display_options,
"display_options_format": display_options_format,
"api_key": api_key,
Expand Down Expand Up @@ -258,6 +264,9 @@ def waybar_output(self, quotes_latest: ResponseQuotesLatest) -> WaybarOutput:
currency = self.config["general"]["currency"]
display_options = self.config["general"]["display_options"]
display_options_format = self.config["general"]["display_options_format"]
spacer = self.config["general"]["spacer_symbol"]
if spacer != "":
spacer = f" {spacer}"

output_obj: WaybarOutput = {
"text": "",
Expand Down Expand Up @@ -298,7 +307,7 @@ def waybar_output(self, quotes_latest: ResponseQuotesLatest) -> WaybarOutput:
output_obj["tooltip"] += output
else:
if output_obj["text"] != "":
output = f" {output}"
output = f"{spacer} {output}"
output_obj["text"] += output

return output_obj
Expand Down