File size: 808 Bytes
5f58fdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pandas as pd
import requests
import os
from PIL import Image
from io import BytesIO

df = pd.read_table("../stock_each_shot_code.csv")

category_count = {}
for record in df.to_records():
    url = record[2]
    category = record[3]
    if category not in os.listdir():
        os.mkdir(category)
    if category not in category_count:
        category_count[category] = 1
    image_name = str(category_count[category]) + ".jpg"
    if image_name not in os.listdir(category):
        try:
            response = requests.get(url)
            img = Image.open(BytesIO(response.content)).convert('RGB')
            img.save(category + "/" + image_name)
            category_count[category] += 1
        except Exception:
            print("----------")
            print(category)
            print(url)