Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import os
  2. import sys
  3. import re
  4. homedir = os.path.dirname(os.path.realpath(__file__))+"/files" #FILES-nazwa folderu z plikami
  5. command=sys.argv[1].upper() #zawsze duze litery czy wpsize kk KK kK
  6.  
  7. if command==('KK'):
  8. list_of_replace=[["dupa","kk"], \
  9. ["xd","KK"], \
  10. ["mam na", "kk"]]
  11. list_of_regex=[["([`\.])(Arial Baltic|Arial CE|Arial CYR|Arial TUR|Arial Greek|Batang)('|\1)","\1Arial\3"]]
  12.  
  13. elif command=="VI":
  14. list_of_replace=[["dupa","odbyt"], \
  15. ["xd","lol"]]
  16. else:
  17. print ("dodaj argument w wierszu polecen glupku")
  18.  
  19. #Mam na imie dupa i lubie sobie robic xd xd xd.
  20.  
  21. #wrzucanie naz plikow do listy
  22. list_of_files=[]
  23. for file in os.listdir("%s" % homedir):
  24. list_of_files.append(file)
  25.  
  26. for file in list_of_files:
  27. #otwiera plik
  28. with open("{}/{}".format(homedir, file), "r+") as f:
  29. old = f.read()
  30. #zamienai stringi
  31. for string_to_find in list_of_replace:
  32. old=old.replace(string_to_find[0], string_to_find[1])
  33. #zamiena regexy
  34. for regex_to_find in list_of_regex:
  35. old=re.sub(regex_to_find[0], regex_to_find[1], old)
  36.  
  37.  
  38. #nadpisuje plik
  39. f.seek(0)
  40. #print (old)
  41. f.write(old)
  42. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement