質問編集履歴
4
もう一つの問題への追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -152,4 +152,6 @@
|
|
152
152
|
</Relative>
|
153
153
|
</Earthquake>
|
154
154
|
</Root>
|
155
|
-
```
|
155
|
+
```
|
156
|
+
### 追記2
|
157
|
+
問題点としてはこのシステムを動かしているサーバが非同期処理をしないとすぐに固まってしまうため、非同期処理にしたいと思っています。
|
3
元XMLファイルURLの削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
```python
|
11
11
|
def e():
|
12
12
|
eews = ''
|
13
|
-
xml_data_module = requests.get('https://
|
13
|
+
xml_data_module = requests.get('https://URL/data1.xml')
|
14
14
|
xml_data_module.encoding = "Shift_JIS"
|
15
15
|
try:
|
16
16
|
root = ET.fromstring(xml_data_module.text)
|
@@ -49,7 +49,7 @@
|
|
49
49
|
```python
|
50
50
|
async def e():
|
51
51
|
async with aiohttp.ClientSession() as session:
|
52
|
-
async with session.get(url='https://
|
52
|
+
async with session.get(url='https://URL/file/data1.xml') as response:
|
53
53
|
xml_data = str(response)
|
54
54
|
try:
|
55
55
|
root = ET.fromstring(xml_data)
|
@@ -67,7 +67,7 @@
|
|
67
67
|
Epicenter = (Earthquake.attrib['Epicenter'])
|
68
68
|
Magnitude = (Earthquake.attrib['Magnitude'])
|
69
69
|
Depth = (Earthquake.attrib['Depth'])
|
70
|
-
map_url = 'https://
|
70
|
+
map_url = 'https://URL/'
|
71
71
|
count = 1
|
72
72
|
for Area in root.iter('Area'):
|
73
73
|
e_1 += '\n' + Area.attrib['Name']
|
@@ -83,4 +83,73 @@
|
|
83
83
|
return 'error'
|
84
84
|
except Exception:
|
85
85
|
return 'error'
|
86
|
+
```
|
87
|
+
### 追記1
|
88
|
+
data1.xml
|
89
|
+
```xml
|
90
|
+
<jishinReport>
|
91
|
+
<record date="2020年12月27日">
|
92
|
+
<item time="12時53分ごろ" shindo="1" url="https://URL/file/JSA0201227125306_20201227125546.xml">長野県南部</item>
|
93
|
+
<item time="04時09分ごろ" shindo="1" url="https://URL/file/JSA0201227040909_20201227041157.xml">茨城県沖</item>
|
94
|
+
</record>
|
95
|
+
<record date="2020年12月26日">
|
96
|
+
<item time="18時25分ごろ" shindo="1" url="https://URL/file/JSA0201226182534_20201226182816.xml">岐阜県美濃中西部</item>
|
97
|
+
<item time="06時32分ごろ" shindo="2" url="https://URL/file/JSA0201226063236_20201226063548.xml">岩手県沿岸北部</item>
|
98
|
+
<item time="00時13分ごろ" shindo="1" url="https://URL/file/JSA0201226001319_20201226001539.xml">北海道渡島地方東部</item>
|
99
|
+
</record>
|
100
|
+
<record date="2020年12月25日">
|
101
|
+
<item time="23時22分ごろ" shindo="1" url="https://URL/file/JSA0201225232200_20201225232434.xml">鹿児島湾</item>
|
102
|
+
<item time="13時12分ごろ" shindo="1" url="https://URL/file/JSA0201225131217_20201225131924.xml">熊本県熊本地方</item>
|
103
|
+
<item time="06時27分ごろ" shindo="2" url="https://URL/file/JSA0201225062739_20201225063052.xml">宮城県北部</item>
|
104
|
+
<item time="05時38分ごろ" shindo="2" url="https://URL/file/JSA0201225053846_20201225054236.xml">種子島近海</item>
|
105
|
+
<item time="05時35分ごろ" shindo="1" url="https://URL/file/JSA0201225053514_20201225053818.xml">長野県中部</item>
|
106
|
+
<item time="04時40分ごろ" shindo="2" url="https://URL/file/JSA0201225044015_20201225044331.xml">茨城県沖</item>
|
107
|
+
</record>
|
108
|
+
<record date="2020年12月24日">
|
109
|
+
<item time="21時58分ごろ" shindo="1" url="https://URL/file/JSA0201224215838_20201224220116.xml">岐阜県美濃中西部</item>
|
110
|
+
<item time="08時11分ごろ" shindo="2" url="https://URL/file/JSA0201224081149_20201224081451.xml">豊後水道</item>
|
111
|
+
<item time="03時18分ごろ" shindo="2" url="https://URL/file/JSA0201224031915_20201224032300.xml">京都府南部</item>
|
112
|
+
<item time="02時55分ごろ" shindo="3" url="https://URL/file/JSA0201224025558_20201224025946.xml">三重県南部</item>
|
113
|
+
</record>
|
114
|
+
<record date="2020年12月23日">
|
115
|
+
<item time="22時08分ごろ" shindo="1" url="https://URL/file/JSA0201223220844_20201223221144.xml">宮城県沖</item>
|
116
|
+
<item time="09時03分ごろ" shindo="1" url="https://URL/file/JSA0201223090306_20201223090609.xml">茨城県沖</item>
|
117
|
+
<item time="06時34分ごろ" shindo="1" url="https://URL/file/JSA0201223063447_20201223063756.xml">新島・神津島近海</item>
|
118
|
+
<item time="03時24分ごろ" shindo="1" url="https://URL/file/JSA0201223032445_20201223032817.xml">奄美大島北西沖</item>
|
119
|
+
<item time="02時04分ごろ" shindo="1" url="https://URL/file/JSA0201223020408_20201223020853.xml">福島県沖</item>
|
120
|
+
</record>
|
121
|
+
<record date="2020年12月22日">
|
122
|
+
<item time="16時30分ごろ" shindo="1" url="https://URL/file/JSA0201222163059_20201222163331.xml">新島・神津島近海</item>
|
123
|
+
<item time="11時52分ごろ" shindo="1" url="https://URL/file/JSA0201222115204_20201222115454.xml">岐阜県飛騨地方</item>
|
124
|
+
<item time="01時28分ごろ" shindo="1" url="https://URL/file/JSA0201222012850_20201222013130.xml">福島県浜通り</item>
|
125
|
+
<item time="00時41分ごろ" shindo="1" url="https://URL/file/JSA0201222004142_20201222004458.xml">栃木県北部</item>
|
126
|
+
</record>
|
127
|
+
<record date="2020年12月21日">
|
128
|
+
<item time="06時32分ごろ" shindo="1" url="https://URL/file/JSA0201221063214_20201221063512.xml">熊本県熊本地方</item>
|
129
|
+
<item time="02時23分ごろ" shindo="5-" url="https://URL/file/JSA0201221022252_20201221042011.xml">青森県東方沖</item>
|
130
|
+
<item time="02時04分ごろ" shindo="1" url="https://URL/file/JSA0201221020418_20201221020727.xml">新島・神津島近海</item>
|
131
|
+
<item time="01時25分ごろ" shindo="2" url="https://URL/file/JSA0201221012528_20201221012843.xml">北海道日高地方東部</item>
|
132
|
+
<item time="00時39分ごろ" shindo="3" url="https://URL/file/JSA0201221003912_20201221004231.xml">新島・神津島近海</item>
|
133
|
+
</record>
|
134
|
+
</jishinReport>
|
135
|
+
```
|
136
|
+
それぞれのURLの形式
|
137
|
+
```xml
|
138
|
+
<Root>
|
139
|
+
<Timestamp>2020/12/23 22:11:44</Timestamp>
|
140
|
+
<Earthquake Id="A0201223220844" Time="2020/12/23 22:08:00" Intensity="1" Epicenter="宮城県沖" Latitude="北緯 38.9度" Longitude="東経 142.6度" Magnitude="4.1" Depth="40km">
|
141
|
+
<Detail>data/JS00cwA0201223220844_20201223221144.jpg</Detail>
|
142
|
+
<Local>data/JS00cuA0201223220844_20201223221144.jpg</Local>
|
143
|
+
<Global>data/JS00clA0201223220844_20201223221144.jpg</Global>
|
144
|
+
<Relative>
|
145
|
+
<Group Intensity="1">
|
146
|
+
<Area Name="大船渡市"/>
|
147
|
+
<Area Name="一関市"/>
|
148
|
+
<Area Name="住田町"/>
|
149
|
+
<Area Name="気仙沼市"/>
|
150
|
+
<Area Name="南三陸町"/>
|
151
|
+
</Group>
|
152
|
+
</Relative>
|
153
|
+
</Earthquake>
|
154
|
+
</Root>
|
86
155
|
```
|
2
元々のコードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
count = count + 1
|
39
39
|
for Detail in root.iter('Detail'):
|
40
40
|
map = map_url + Detail.text
|
41
|
-
edic = {'time': time, 'epicenter': Epicenter, "intensity": Intensity, "depth": Depth, "magnitude": Magnitude, "map": map, "icon":
|
41
|
+
edic = {'time': time, 'epicenter': Epicenter, "intensity": Intensity, "depth": Depth, "magnitude": Magnitude, "map": map, "icon": eicon(Intensity), "color": eicolor(Intensity), 'e_1': e_1}
|
42
42
|
return edic
|
43
43
|
except Exception:
|
44
44
|
return 'error'
|
1
タイトルに質問のメインである「非同期処理」というワードを追加した
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
pythonでXMLを読み取りたい
|
1
|
+
pythonでXMLを非同期処理で読み取りたい
|
body
CHANGED
File without changes
|