Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def clean_line(line):
- # Remove the 'pocket-cli add --url ' part
- line = line.replace('pocket-cli add --url ', '')
- # Remove the leading and trailing double quotes
- line = line.replace('"', '')
- # Split the URL from the tags
- parts = line.split(' --tags ')
- # Join the tags with a comma and space
- url = parts[0]
- tags = ', '.join(parts[1:])
- return f"{url} {tags}"
- def process_file(input_file, output_file):
- with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
- for line in infile:
- # Remove newline characters from the line
- line = line.strip()
- # Clean the line
- clean = clean_line(line)
- # Write the cleaned line to the output file
- outfile.write(clean + '\n')
- # Open the output text file
- os.startfile(output_file)
- # Replace 'input.txt' with your input file name and 'output.txt' with your desired output file name
- process_file('input.txt', 'output.txt')
- """Here’s a breakdown of how this script works:
- 1. clean_line function: This function removes 'pocket-cli add --url ' and '"', then splits the line at ' --tags '. It joins the tags with a comma and space, combining them back with the URL.
- 2. process_file function: This function reads each line from the input text file, processes it using the clean_line function, and writes the cleaned line to the output text file. It also opens the output file after processing.
- Replace 'input.txt' and 'output.txt' with your actual file names. The script will read from 'input.txt', process each line, write the cleaned lines to 'output.txt', and then open 'output.txt'."""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement