123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
-
-
-
-
-
-
-
-
-
-
-
- import sys
- from openpyxl import load_workbook
- from openpyxl_image_loader import SheetImageLoader
-
- if __name__ != "__main__":
- raise RuntimeError("Please run this file directly")
-
- if len(sys.argv) < 2:
- raise RuntimeError("Please pass input file as argument")
-
- wb = load_workbook(filename = sys.argv[1])
- ws = wb.active
- image_loader = SheetImageLoader(ws)
-
- data = []
-
- for row in ws:
- try:
- id = int(row[0].value)
- except:
- continue
-
- text = str(row[1].value)
-
-
- if not image_loader.image_in(row[2].coordinate):
- print("No image found for ID {}".format(id))
- image = None
- else:
- image = image_loader.get(row[2].coordinate)
-
- data.append((
- id, text, image
- ))
-
- print("Found {} IDs:".format(len(data)))
- print()
-
- print(" self.descriptions = [")
- for d in data:
- if d[2] != None:
- img_name = "weather_icon_{}.png".format(d[0])
- d[2].save(img_name)
- img_name = "'" + img_name + "'"
- else:
- img_name = "None"
- print(" ({}, '{}', {}),".format(d[0], d[1], img_name))
- print(" ]")
- print()
|