weechat- me personal weechat setup 🔵🟢 |
git clone git://git.acid.vegas/weechat.git |
Log | Files | Refs | Archive | README |
bufsave.py (1707B)
1 # -*- coding: utf-8 -*- 2 # bufsave script for weechat - developed by acidvegas (https://git.acid.vegas/weechat) 3 # usage: /bufsave saves current buffer to a $HOME/.weechats/logs/ 4 5 import time 6 import weechat 7 8 def cstrip(text): 9 return weechat.string_remove_color(text, '') 10 11 def bufsave_cmd(data, buffer, args): 12 filename = weechat.buffer_get_string(buffer, 'localvar_server') + '.' + weechat.buffer_get_string(buffer, 'localvar_channel') + '-' + time.strftime('%y_%m_%d-%I_%M_%S') + '.log' 13 filename = weechat.string_eval_path_home('%h/logs/' + filename, {}, {}, {}) 14 try: 15 fp = open(filename, 'w') 16 except: 17 weechat.prnt('', 'Error writing to target file!') 18 return weechat.WEECHAT_RC_OK 19 own_lines = weechat.hdata_pointer(weechat.hdata_get('buffer'), buffer, 'own_lines') 20 if own_lines: 21 line = weechat.hdata_pointer(weechat.hdata_get('lines'), own_lines, 'first_line') 22 hdata_line = weechat.hdata_get('line') 23 hdata_line_data = weechat.hdata_get('line_data') 24 while line: 25 data = weechat.hdata_pointer(hdata_line, line, 'data') 26 if data: 27 date = weechat.hdata_time(hdata_line_data, data, 'date') 28 if not isinstance(date, str): 29 date = time.strftime('%F %T', time.localtime(int(date))) 30 fp.write('{0} {1} {2}\n'.format(date, cstrip(weechat.hdata_string(hdata_line_data, data, 'prefix')), cstrip(weechat.hdata_string(hdata_line_data, data, 'message')))) 31 line = weechat.hdata_move(hdata_line, line, 1) 32 fp.close() 33 return weechat.WEECHAT_RC_OK 34 35 if weechat.register('bufsave', 'acidvegas', '1.0', 'ISC', 'save buffer to file', '', ''): 36 weechat.hook_command('bufsave', 'save current buffer to a file', '[filename]', 'filename: target file (must not exist)\n', '%f', 'bufsave_cmd', '')