def state_update(text, fname): """ Write text to file atomically. Text may contain unicode. """ block = [{ "full_text": "{}: {}".format(SYMB_REDDIT, text), "color": COLORS.green }] with aw.open(fname, "w") as fobj: json.dump(block, fobj) wake_i3status()