Advertisement
Guest User

Python link changer

a guest
Oct 12th, 2017
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import re
  2.  
  3. def ProcessLine(pattern, line):
  4.     match = re.search(pattern, line)
  5.     if match is None:
  6.         return line + "------------------------------------------------------------------------------\n"
  7.     else:
  8.         words = match.group(1).replace("-", " ")
  9.         # This return formats in the reddit style
  10.         #return f'* [{words}]({line[:-1]})\n'
  11.         # This one formats in html anchor tags
  12.         #return f'<a href="{line[:-1]}">{words}</a>\n'
  13.         # This one simply puts a line between text and link so pastebin can use it
  14.         return f'{words}\n\t\t{line}\n'
  15.  
  16. # www.udemy.com/applewatchcourse/?couponCode=EnrollFREE
  17. if __name__ == '__main__':
  18.     pattern = re.compile(r'^www\.udemy\.com[/]([^/]+)[/]')
  19.     # pattern = re.compile(r'^www\.udemy\.com')
  20.     with open('links.txt', 'r') as read:
  21.         with open('fixedlinks.txt', 'w' ) as write:
  22.             for line in read:
  23.                 write.write(f'{ProcessLine(pattern, line)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement