script.py 1010 B

12345678910111213141516171819202122232425262728293031
  1. import re, os
  2. wiki_dir = "C:\\Coding\\python\\dropbox-pictures-regex\\wiki\\"
  3. # koment
  4. regex = r"(?:(?:https?)+\:\/\/+[a-zA-Z0-9\/\._-]{1,})+(?:(?:jpe?g|png))"
  5. for path, dirs, files in os.walk(wiki_dir):
  6. for file in files:
  7. if file.endswith('.md'):
  8. file_path = os.path.join(path, file)
  9. with open(file_path, 'r', encoding='utf8') as f:
  10. text = f.read()
  11. matches = re.findall(regex, text)
  12. for match in matches:
  13. print(f"Soubor: {file_path}\nobrazek: {match}")
  14. # match.split("/")[-1]
  15. # posledni vec za lomitkem
  16. # import requests
  17. #
  18. # match
  19. # 'https://paper-attachments.dropboxusercontent.com/s_24178BD4A5DAB9E5982E958D5E436EA3EE292ED76CE0CE756BCC4AC8A6171443_1711543972132_image.png'
  20. # resp = requests.get(match)
  21. # match.split("/")[-1]
  22. # 's_24178BD4A5DAB9E5982E958D5E436EA3EE292ED76CE0CE756BCC4AC8A6171443_1711543972132_image.png'
  23. # with open(match.split("/")[-1], "wb") as fp:
  24. # fp.write(resp.content)