Guest User

Untitled

a guest
May 31st, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. from re import compile
  2.  
  3. def get_all_links(file_contents):
  4.   pattern = compile("<a class=\"entity-link\" data-entity=Actor data-id=.+ ><i class=\"fas fa-user\"></i>.+</a>")
  5.  
  6.   return pattern.findall(file_contents)
  7.  
  8. def fixed_link(link):
  9.   pattern = compile("<a class=\"entity-link\" data-entity=Actor data-id=(.+) ><i class=\"fas fa-user\"></i>(.+)</a>")
  10.  
  11.   match = pattern.findall(link)
  12.   the_id, name = match[0]
  13.  
  14.   return f"@Compendium[cos.actors.{the_id}]{{{name}}}"
  15.  
  16.  
  17. with open('data.txt', 'r') as d_file:
  18.   file_content = d_file.read()
  19.  
  20. links = get_all_links(file_content)
  21.  
  22. for link in links:
  23.   file_content = file_content.replace(link, fixed_link(link))
  24.  
  25.  
  26. with open('outfile.txt', 'w+') as outfile:
  27.   outfile.write(file_content)
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment