Skip to content

Instantly share code, notes, and snippets.

@tronje tronje/run.py
Last active May 19, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.