Advertisement
DeaD_EyE

show pictures from SIEMENS components

Sep 17th, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import requests
  2. import io
  3. from bs4 import BeautifulSoup
  4. from PIL import Image
  5. from PIL.ImageDraw import ImageDraw
  6. from PIL.ImageFont import truetype
  7.  
  8.  
  9. BASE_URL = "https://mall.industry.siemens.com/mall/de/de/Catalog/Product/"
  10. PRODUCT = "3SU1050-0AA10-0AA0"
  11. UA = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"}
  12.  
  13. def get_picture(product):
  14.     resp = requests.get(BASE_URL + product, headers=UA)
  15.     bs = BeautifulSoup(resp.content, "lxml")
  16.     img = bs.find("img", {"class": "productPicture"})
  17.     if img:
  18.         return product, img["src"]
  19.  
  20.  
  21. def show_img(url, product):
  22.     fd = io.BytesIO(requests.get(url, headers=UA).content)
  23.     img = Image.open(fd)
  24.     drw = ImageDraw(img)
  25.     drw.text((0,0), product, fill=(255,40,40), font=truetype("OpenSans-Light.ttf", 22))
  26.     img.show()
  27.  
  28.  
  29. PRODUCTS = """
  30. 3SU1550-0AA10-0AA0
  31. 3SU1400-1AA10-1BA0
  32. 6XV1870-8AH10
  33. 3SU1400-1AA10-1CA0
  34. 3SU1052-2BF10-0AA0
  35. 3SU1051-6AA30-0AA0
  36. 3SU1051-6AA40-0AA0
  37. 3SU1051-6AA20-0AA0
  38. 3SU1050-4BF01-0AA0
  39. 3SU1050-1LB20-0AA0
  40. 3SU1051-0AB50-0AA0
  41. 3SU1401-1BB50-1AA0
  42. 3SU1401-1BB40-1AA0
  43. 3SU1401-1BB30-1AA0
  44. 3SU1401-1BB20-1AA0
  45. """.strip().splitlines()
  46.  
  47.  
  48. for p in PRODUCTS:
  49.      product, source = get_picture(p)
  50.      img = show_img(source, product)
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement