Skip to content

Instantly share code, notes, and snippets.

@tronje
Last active May 19, 2018 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tronje/21c4c1ecf7a9afb133f1814336ac3d48 to your computer and use it in GitHub Desktop.
Save tronje/21c4c1ecf7a9afb133f1814336ac3d48 to your computer and use it in GitHub Desktop.
wttr.in conky color replacement
#!/usr/bin/env python
"""The script replaces colors contained in output from
`curl -s wttr.in/$Location` with conky-compatible color codes.
Use it like this:
```
conky.text = [[
${execpi 1800 curl -s wttr.in/Hamburg | head -7 | tail -5 | /path/to/run.py}
]]
```
Obviously, replace `Hamburg` with your location, and `1800` with your desired
interval.
"""
import sys
WHITE = "${color white}"
LIGHTGREY = "${color lightgrey}"
GREY = "${color grey}"
TEAL = "${color teal}"
LIGHTBLUE = "${color lightblue}"
BLUE = "${color blue}"
LIGHTGREEN = "${color lightgreen}"
GREEN = "${color green}"
YELLOW = "${color yellow}"
ORANGE = "${color orange}"
RED = "${color red}"
color_mapping = {
# color reset
"": "$color",
# white
"": WHITE,
# lightgrey
"": LIGHTGREY,
"": LIGHTGREY,
"": LIGHTGREY,
# grey
"": GREY,
"": GREY,
# multiple teal shades
"": TEAL,
"": TEAL,
# light blue
"": LIGHTBLUE,
"": LIGHTBLUE,
"": LIGHTBLUE,
"": LIGHTBLUE,
"": LIGHTBLUE,
"": LIGHTBLUE,
# blue
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
"": BLUE,
# light green
"": LIGHTGREEN,
"": LIGHTGREEN, # more like a teal-green
"": LIGHTGREEN,
"": LIGHTGREEN,
"": LIGHTGREEN,
"": LIGHTGREEN,
# green
"": GREEN,
"": GREEN,
"": GREEN,
"": GREEN,
"": GREEN,
# yellow
"": YELLOW,
"": YELLOW,
"": YELLOW,
"": YELLOW,
"": YELLOW,
# orange
"": ORANGE,
"": ORANGE,
"": ORANGE,
"": ORANGE,
"": ORANGE,
"": ORANGE,
# red
"": RED,
"": RED,
"": RED,
"": RED,
# bold is not supported; so no color reset
# is broken, we just replace it with white
"": WHITE,
}
if __name__ == "__main__":
lines = sys.stdin.readlines()
output = []
for line in lines:
output_line = line
for color in color_mapping.keys():
output_line = output_line.replace(color, color_mapping[color])
output.append(output_line)
print("".join(output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment