lenard68 commited on
Commit
5f58fdd
1 Parent(s): b2896fc

upload test

Browse files
Files changed (1) hide show
  1. downloader.py +27 -0
downloader.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import requests
3
+ import os
4
+ from PIL import Image
5
+ from io import BytesIO
6
+
7
+ df = pd.read_table("../stock_each_shot_code.csv")
8
+
9
+ category_count = {}
10
+ for record in df.to_records():
11
+ url = record[2]
12
+ category = record[3]
13
+ if category not in os.listdir():
14
+ os.mkdir(category)
15
+ if category not in category_count:
16
+ category_count[category] = 1
17
+ image_name = str(category_count[category]) + ".jpg"
18
+ if image_name not in os.listdir(category):
19
+ try:
20
+ response = requests.get(url)
21
+ img = Image.open(BytesIO(response.content)).convert('RGB')
22
+ img.save(category + "/" + image_name)
23
+ category_count[category] += 1
24
+ except Exception:
25
+ print("----------")
26
+ print(category)
27
+ print(url)