boardgameimage.py 963 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. import requests
  3. import xml.etree.ElementTree as ET
  4. with open("Board Games.csv", encoding="utf8") as f:
  5. text = f.read()
  6. links = []
  7. for line in text.splitlines():
  8. links.append(line.split(",")[-1])
  9. print(links)
  10. working = []
  11. total = len(links)
  12. for num, link in enumerate(links):
  13. if link == "Image":
  14. working.append("Image")
  15. continue
  16. link = "https://"+link.split("/")[2]+"/xmlapi/"+'/'.join(link.split("/")[3:])
  17. data = requests.get(link).text
  18. myroot = ET.fromstring(data)
  19. for i in myroot.findall('boardgame'):
  20. image = i.find('image').text
  21. print(f"{image} ({num}/{total})")
  22. working.append(image)
  23. print(working)
  24. with open("urls.txt", "w") as f:
  25. f.write('\n'.join(working))
  26. finaletext = []
  27. for line, image in zip(text.splitlines(), working):
  28. finaletext.append(line+","+image)
  29. with open("finaleboardgame.csv", "w", encoding="utf8") as f:
  30. f.write('\n'.join(working))