<commit_before>#!/usr/bin/env python

import sys
import os
from subprocess import call

def puaq(): # print usage and quit
    print("Usage: %s path_with_playlists string_to_find string_to_replace_with" % os.path.basename(__file__))
    sys.exit(1)

def proc(plfile, str_find, str_rep):

    str_find = str_find.replace("/", "\\/")
    str_rep = str_rep.replace("/", "\\/")
    sed_opts = "s/%s/%s/g" % (str_find, str_rep)
    the_cmd = ["sed", "-i", sed_opts, plfile]

    call(the_cmd)

if __name__ == "__main__":
    if len(sys.argv) < 4:
        puaq()

    path_playlists = os.path.abspath(sys.argv[1])
    if not os.path.exists(path_playlists):
        print("%s does not exist." % path_playlists)
        sys.exit(1)
    str_find = sys.argv[2]
    str_rep = sys.argv[3]
    
    playlists = os.listdir(path_playlists)
    for p in playlists:
        proc(os.path.join(path_playlists, p), str_find, str_rep)
 
<commit_msg>adding broken/midway into a refactor clementine playlist rebase<commit_after>#!/usr/bin/env python

import sys
import os
from subprocess import call
import filteredfilelister

def puaq(): # print usage and quit
    print("Usage: %s path_with_playlists string_to_find string_to_replace_with" % os.path.basename(__file__))
    sys.exit(1)

def proc(plfile, str_find, str_rep):

    str_find = str_find.replace("/", "\\/")
    str_rep = str_rep.replace("/", "\\/")
    sed_opts = "s/%s/%s/g" % (str_find, str_rep)
    the_cmd = ["sed", "-i", sed_opts, plfile]

    call(the_cmd)

if __name__ == "__main__":
    if len(sys.argv) < 4:
        puaq()

    path_playlists = os.path.abspath(sys.argv[1])
    if not os.path.exists(path_playlists):
        print("%s does not exist." % path_playlists)
        sys.exit(1)
    str_find = sys.argv[2]
    str_rep = sys.argv[3]
    
    playlists = filteredfilelister.makefiledictlist(path_playlists, "xspf", False)
    # mvtodo: cant assumme there will be results in the returning dict. check if its not empty before trying to access "xspf"
    for p in playlists["xspf"]:
        print("Processing %s..." % p)
        proc(os.path.join(path_playlists, p), str_find, str_rep)
 

{'fraction_non_alphanumeric': 0.14039179104477612, 'fraction_numerical': 0.005597014925373134, 'mean_word_length': 3.26441351888668, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '229568', 'n_tokens_mistral': 802, 'n_tokens_neox': 785, 'n_words': 181}