回答編集履歴
4
編集上の修正
test
CHANGED
@@ -76,13 +76,13 @@
|
|
76
76
|
|
77
77
|
img = cv2.imread('/Users/username/banggood/u' + x)
|
78
78
|
|
79
|
-
print(img.shape)
|
79
|
+
# print(img.shape)
|
80
80
|
|
81
81
|
img2 = cv2.resize(img, dsize=None, fx=0.5, fy=0.5)
|
82
82
|
|
83
83
|
cv2.imwrite('/ Users/username/banggood/u' + x, img2)
|
84
84
|
|
85
|
-
print("保存(GIF以外) パス:",x)
|
85
|
+
print("保存(GIF以外) パス:",x, "shape",img.shape)
|
86
86
|
|
87
87
|
|
88
88
|
|
3
変更4回目
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
2回目+3回目(エラー通知の変更)
|
1
|
+
2回目+3回目(エラー通知の変更)+ 4回目(全条件のトレース)
|
2
2
|
|
3
3
|
---
|
4
4
|
|
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
for column_name, item in df.iteritems():
|
32
32
|
|
33
|
-
|
33
|
+
print("捜査中 カラム",column_name,"アイテム",item ,"...",end="")
|
34
34
|
|
35
35
|
if column_name == 'url' or '_1' or '_2' or '_3' or '_4' or '_5' or '_6' or '_7' or '_8' or '_9':
|
36
36
|
|
@@ -64,13 +64,13 @@
|
|
64
64
|
|
65
65
|
f.write(mem)
|
66
66
|
|
67
|
-
print(x)
|
67
|
+
# print(x)
|
68
68
|
|
69
69
|
|
70
70
|
|
71
71
|
if url_extension == ".gif":
|
72
72
|
|
73
|
-
print("
|
73
|
+
print("スキップ(GIF)")
|
74
74
|
|
75
75
|
else:
|
76
76
|
|
@@ -80,25 +80,23 @@
|
|
80
80
|
|
81
81
|
img2 = cv2.resize(img, dsize=None, fx=0.5, fy=0.5)
|
82
82
|
|
83
|
-
cv2.imwrite(
|
83
|
+
cv2.imwrite('/ Users/username/banggood/u' + x, img2)
|
84
84
|
|
85
|
-
|
85
|
+
print("保存(GIF以外) パス:",x)
|
86
86
|
|
87
87
|
|
88
88
|
|
89
89
|
except urllib.error.HTTPError:
|
90
90
|
|
91
|
-
|
91
|
+
print("スキップ(HTTPエラー)")
|
92
92
|
|
93
|
-
print("!!! HTTP エラー")
|
94
|
-
|
95
|
-
traceback.print_exc()
|
93
|
+
# traceback.print_exc()
|
96
94
|
|
97
95
|
except Exception as err:
|
98
96
|
|
99
|
-
print("
|
97
|
+
print("スキップ(HTTP以外のエラー)")
|
100
98
|
|
101
|
-
traceback.print_exc()
|
99
|
+
# traceback.print_exc()
|
102
100
|
|
103
101
|
time.sleep(1)
|
104
102
|
|
@@ -106,35 +104,21 @@
|
|
106
104
|
|
107
105
|
except Exception as err:
|
108
106
|
|
109
|
-
print("!!! URL 関連のエラー")
|
110
|
-
|
111
|
-
print("CSVに定義されている元の
|
107
|
+
print("スキップ(URLエラー) CSVに定義されている元のデータ[" + row[column_name] + ,url_extension + "]に問題があるようです。")
|
112
|
-
|
113
|
-
# print("ROW", row[column_name])
|
114
|
-
|
115
|
-
# print("EXT", url_extension )
|
116
108
|
|
117
109
|
|
118
110
|
|
119
|
-
# traceback.print_exc()
|
120
|
-
|
121
|
-
# except AttributeError as error:
|
122
|
-
|
123
|
-
# print()
|
124
|
-
|
125
|
-
# except ValueError as error:
|
126
|
-
|
127
|
-
# print()
|
128
|
-
|
129
111
|
else:
|
130
112
|
|
131
|
-
print()
|
113
|
+
print("スキップ 対象外のカラム名です。")
|
132
114
|
|
133
115
|
|
134
116
|
|
135
|
-
|
117
|
+
print("正常に終了しました。")
|
136
118
|
|
119
|
+
|
120
|
+
|
137
|
-
|
121
|
+
# f.close() # <---with ○○ as fのため不要
|
138
122
|
|
139
123
|
|
140
124
|
|
2
編集3回目エラー通知の変更
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
2回目
|
1
|
+
2回目+3回目(エラー通知の変更)
|
2
2
|
|
3
3
|
---
|
4
4
|
|
@@ -108,7 +108,15 @@
|
|
108
108
|
|
109
109
|
print("!!! URL 関連のエラー")
|
110
110
|
|
111
|
+
print("CSVに定義されている元のURL[" + row[column_name] + "]に問題があるようです。スキップします。")
|
112
|
+
|
113
|
+
# print("ROW", row[column_name])
|
114
|
+
|
115
|
+
# print("EXT", url_extension )
|
116
|
+
|
117
|
+
|
118
|
+
|
111
|
-
traceback.print_exc()
|
119
|
+
# traceback.print_exc()
|
112
120
|
|
113
121
|
# except AttributeError as error:
|
114
122
|
|
@@ -125,6 +133,10 @@
|
|
125
133
|
|
126
134
|
|
127
135
|
f.close()
|
136
|
+
|
137
|
+
print("正常に終了しました。")
|
138
|
+
|
139
|
+
|
128
140
|
|
129
141
|
```
|
130
142
|
|
1
修正案を提示
test
CHANGED
@@ -1,3 +1,141 @@
|
|
1
|
+
2回目
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
```Python
|
6
|
+
|
7
|
+
import sys
|
8
|
+
|
9
|
+
import time
|
10
|
+
|
11
|
+
import os
|
12
|
+
|
13
|
+
import pandas as pd
|
14
|
+
|
15
|
+
import cv2
|
16
|
+
|
17
|
+
import traceback # エラーが出た際にエラーが起きた旨の通知用に追加
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
df = pd.read_csv('/Users/username/banggood/img_ban.csv', encoding='cp932', dtype=object)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
headers = {
|
28
|
+
|
29
|
+
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0"}
|
30
|
+
|
31
|
+
for column_name, item in df.iteritems():
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
if column_name == 'url' or '_1' or '_2' or '_3' or '_4' or '_5' or '_6' or '_7' or '_8' or '_9':
|
36
|
+
|
37
|
+
for index, row in df.iterrows():
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
try:
|
42
|
+
|
43
|
+
url_separate = os.path.splitext(row[column_name])
|
44
|
+
|
45
|
+
url_extension = url_separate[1].replace('URL', '')
|
46
|
+
|
47
|
+
url_extension = url_extension.replace('#username', '')
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
request = urllib.request.Request(
|
52
|
+
|
53
|
+
row[column_name], headers=headers)
|
54
|
+
|
55
|
+
try:
|
56
|
+
|
57
|
+
mem = urllib.request.urlopen(request).read()
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
x = row['code'] + column_name.replace('URL', '') + ".jpeg"
|
62
|
+
|
63
|
+
with open('/Users/username/banggood/u/' + x, mode="wb") as f:
|
64
|
+
|
65
|
+
f.write(mem)
|
66
|
+
|
67
|
+
print(x)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
if url_extension == ".gif":
|
72
|
+
|
73
|
+
print("!!!gif!!!")
|
74
|
+
|
75
|
+
else:
|
76
|
+
|
77
|
+
img = cv2.imread('/Users/username/banggood/u' + x)
|
78
|
+
|
79
|
+
print(img.shape)
|
80
|
+
|
81
|
+
img2 = cv2.resize(img, dsize=None, fx=0.5, fy=0.5)
|
82
|
+
|
83
|
+
cv2.imwrite(
|
84
|
+
|
85
|
+
'/ Users/username/banggood/u' + x, img2)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
except urllib.error.HTTPError:
|
90
|
+
|
91
|
+
# print("エラー")
|
92
|
+
|
93
|
+
print("!!! HTTP エラー")
|
94
|
+
|
95
|
+
traceback.print_exc()
|
96
|
+
|
97
|
+
except Exception as err:
|
98
|
+
|
99
|
+
print("!!! HTTP エラー以外のエラー")
|
100
|
+
|
101
|
+
traceback.print_exc()
|
102
|
+
|
103
|
+
time.sleep(1)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
except Exception as err:
|
108
|
+
|
109
|
+
print("!!! URL 関連のエラー")
|
110
|
+
|
111
|
+
traceback.print_exc()
|
112
|
+
|
113
|
+
# except AttributeError as error:
|
114
|
+
|
115
|
+
# print()
|
116
|
+
|
117
|
+
# except ValueError as error:
|
118
|
+
|
119
|
+
# print()
|
120
|
+
|
121
|
+
else:
|
122
|
+
|
123
|
+
print()
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
f.close()
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
初回分
|
136
|
+
|
137
|
+
---
|
138
|
+
|
1
139
|
```Python
|
2
140
|
|
3
141
|
try:
|