Advertisement
Jexal

d6f76b16-ba4b-4ee1-97b1-f313fcd58fb2

Jan 21st, 2025 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. def clean_line(line):
  2.     # Remove the 'pocket-cli add --url ' part
  3.     line = line.replace('pocket-cli add --url ', '')
  4.     # Remove the leading and trailing double quotes
  5.     line = line.replace('"', '')
  6.    
  7.     # Split the URL from the tags
  8.     parts = line.split(' --tags ')
  9.    
  10.     # Join the tags with a comma and space
  11.     url = parts[0]
  12.     tags = ', '.join(parts[1:])
  13.    
  14.     return f"{url} {tags}"
  15.  
  16. def process_file(input_file, output_file):
  17.     with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
  18.         for line in infile:
  19.             # Remove newline characters from the line
  20.             line = line.strip()
  21.             # Clean the line
  22.             clean = clean_line(line)
  23.             # Write the cleaned line to the output file
  24.             outfile.write(clean + '\n')
  25.    
  26.     # Open the output text file
  27.     os.startfile(output_file)
  28.  
  29. # Replace 'input.txt' with your input file name and 'output.txt' with your desired output file name
  30. process_file('input.txt', 'output.txt')
  31.  
  32. """Here’s a breakdown of how this script works:
  33.  
  34. 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.
  35.  
  36. 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.
  37.  
  38. 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