def merge(localPath, remotePath): items = {} key_order = [] changes = {} for path in [localPath, remotePath]: for (li, tvdb_id, sep, alias_list, line) in parse_data(get_text(path)): if not validate_tvdb_id(tvdb_id): continue if not items.has_key(tvdb_id): items[tvdb_id] = [] key_order.append(tvdb_id) for alias in alias_list: alias = alias.strip().replace("'", "\\'") if not find_match(alias, items[tvdb_id]): items[tvdb_id].append(alias) # track remote changes if path == remotePath: if not changes.has_key(tvdb_id): changes[tvdb_id] = [] changes[tvdb_id].append(alias) print "----------------------------------------------------------" print "New Shows" print "----------------------------------------------------------" for ck, added in changes.items(): if items[ck] == added: print str(ck) + '\tnew\t\t' + str(added) print "----------------------------------------------------------" print "New Aliases" print "----------------------------------------------------------" for ck, added in changes.items(): if items[ck] != added: print str(ck) + '\tadd\t\t' + str(added) print '=============\t', items[ck] print return dict_to_data(items, key_order)
def remove_duplicates(path): items = {} key_order = [] changes = {} for (li, tvdb_id, sep, alias_list, line) in parse_data(get_text(path)): if not validate_tvdb_id(tvdb_id): continue if not items.has_key(tvdb_id): items[tvdb_id] = [] key_order.append(tvdb_id) for alias in alias_list: alias = alias.strip().replace("'", "\\'") if not find_match(alias, items[tvdb_id]): items[tvdb_id].append(alias) return dict_to_data(items, key_order)