Skip to content

Instantly share code, notes, and snippets.

@perplexa
Created January 9, 2020 13:20
Show Gist options
  • Save perplexa/52594d15a4f747d498729cba06da29ea to your computer and use it in GitHub Desktop.
Save perplexa/52594d15a4f747d498729cba06da29ea to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import re
import sys
import urllib.request
headers = {'User-Agent': 'curl/7.54.0'}
req = urllib.request.Request('http://wttr.in/' + (sys.argv[1] if len(sys.argv) > 1 else ''))
req.add_header('User-Agent', 'curl/7.54.0')
fp = urllib.request.urlopen(req)
dat = fp.read().decode("utf8")
fp.close()
def crep(match):
cols = [52, 94, 100, 58, 22, 29, 23, 24, 17, 54, 53, 89, 88, 130, \
142, 64, 28, 35, 30, 25, 18, 91, 90, 125, 124, 166, 184, \
106, 34, 49, 37, 33, 19, 129, 127, 161, 196, 208, 226, 154, \
46, 86, 51, 75, 21, 171, 201, 198, 203, 215, 227, 191, 83, \
122, 87, 111, 63, 177, 207, 205, 217, 223, 229, 193, 157, \
158, 159, 153, 147, 183, 219, 212, 16]
col = match.group(1)
bright = match.group(2)
try:
mirccol = cols.index(int(col))
except:
mirccol = 4
return "\003%s" % (mirccol + 16)
srch = r'\033\[38;5;(\d+)(?:;(\d+))?m'
newdat = re.sub(srch, crep, dat)
newdat.replace('\033\[0m', '\x0F')
newdat = '\n'.join([line for line in newdat.split('\n') if 'wttr' not in line])
print(newdat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment