Last active
August 23, 2016 07:54
-
-
Save SergKolo/c362a2dac3fca17ab520c8dd077d3400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import subprocess | |
import time | |
import os | |
def run_cmd(cmdlist): | |
""" Reusable function for running external commands """ | |
new_env = dict( os.environ ) | |
new_env['LC_ALL'] = 'C' | |
try: | |
stdout = subprocess.check_output(cmdlist,env=new_env) | |
except subprocess.CalledProcessError: | |
pass | |
else: | |
if stdout: | |
return stdout | |
if __name__ == '__main__': | |
user_home = os.path.expanduser('~') | |
config_file = '.config/fcitx/data/QuickPhrase.mb' | |
config_full_path = os.path.join(user_home,config_file) | |
found = None | |
while True: | |
lines = [] | |
time.sleep(1) | |
with open(config_full_path) as f: | |
for line in f: | |
lines.append(line.strip()) | |
if line.startswith('time_now'): | |
found = True | |
# print(lines) | |
if found: | |
with open(config_full_path,'w') as f: | |
for line in lines: | |
if line.startswith('time_now'): | |
time_now = run_cmd(['date', | |
'+%Y-%m-%d %I:%M' | |
]).decode().strip() | |
line = 'time_now ' + time_now + '\n' | |
else: | |
line = line + '\n' | |
f.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment