HexChat update breaks favourite channels + script to fix it

Ok I've been very lazy blog-wise .. I shall try to better myself .. ;)

So to start with something useful: I just upgraded my HexChat and had the problem that the update messes up my Auto-join channels or favourites or whatever you want to call them. So since I'm lazy - and a programmer here's some python code for this:

#!/usr/bin/env python

import sys

CONFIGFILENAME="/home/lordvan/.config/hexchat/servlist.conf"
DEBUG = False

# old format: J=#chan1,#chan2,#chan3 key1,,key3
#new format: J=#chan,key  -- one per line

myconf = None
myLines = None
mynewLines = None

try:
    myconf = open(CONFIGFILENAME, 'r')
except Exception as e:
    print("Error opening file: %s", e)
    sys.exit(1)

try:
    myLines = myconf.readlines()
except Exception as e:
    print ("Error reading file: %s", e)
    myLines.close()
    sys.exit(1)
    
if not myLines:
    print ("config file empty")
    sys.exit(0)

myNewLines = []

for line in myLines:
    if line[0:2] != 'J=':
        myNewLines.append(line)
    else:
        # we got a channel list check if it contains more than one
        if DEBUG:
            print(line)
        chans = None
        keys = None
        if line.find(' ') > -1:
            # found channels and keys
            splitline = line[2:].strip().split(' ')
            if DEBUG:
                print (splitline)
            chans =(line[2:].strip().split(' '))[0].split(',')
            if DEBUG:
                print(chans)
            keys = (line[2:].strip().split(' '))[1].split(',')
            if DEBUG:
                print(keys)
        else:
            # just channels here
            chans = line[2:].strip().split(',')
        if len(chans) < 2:
            myNewLines.append(line)
        else:
            idx = 0
            for chan in chans:
                newLine = 'J=%s' % chan
                if keys and keys[idx]:
                    newLine += ',%s' %(keys[idx])
                newLine += '\n'
                if DEBUG:
                    print(newLine)
                myNewLines.append(newLine)
                idx += 1
                

#print( myNewLines)
outp = open(CONFIGFILENAME + 'converted', 'w+')
outp.writelines(myNewLines)
outp.close()

you'd obviously have to fix the path to the file ;)