-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkyu_jp_final.py
675 lines (616 loc) · 36.8 KB
/
kyu_jp_final.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# Inner modules
import pip, site, importlib
import os, csv
import sys
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
import time
# Downloaded modules
print("\nChecking modules requirments. It will install module not exists automatically.")
try:
from selenium import webdriver, common
print("Module [selenium] found")
except ImportError:
print("Module [selenium] not found")
pip.main(['install', 'selenium'])
importlib.reload(site)
from selenium import webdriver, common
try:
import chromedriver_binary
print("Module [chromedriver_binary] found")
except ImportError:
print("Module [chromedriver_binary] not found")
pip.main(['install', 'chromedriver_binary'])
importlib.reload(site)
import chromedriver_binary
try:
import requests
print("Module [requests] found")
except ImportError:
print("Module [requests] not found")
pip.main(['install', 'requests'])
importlib.reload(site)
import requests
try:
import pandas as pd
print("Module [pandas] found")
except ImportError:
print("Module [pandas] not found")
pip.main(['install', 'pandas'])
importlib.reload(site)
import pandas as pd
try:
import bs4
print("Module [beautifulsoup4] found")
except ImportError:
print("Module [beautifulsoup4] not found")
pip.main(['install', 'beautifulsoup4'])
importlib.reload(site)
import bs4
try:
import urllib3
print("Module [urllib3] found")
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
except ImportError:
print("Module [urllib3] not found")
pip.main(['install', 'urllib3'])
importlib.reload(site)
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
print("All modules are ready.\n")
def page_edit(driver, data):
new_page_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/div[2]/form/input")
new_page_btn.click()
time.sleep(0.5)
new_file = driver.find_element_by_name("cts_filepath")
new_title = driver.find_element_by_name("cts_title")
new_inschool = driver.find_element_by_name("cts_inplaceflag")
new_hidtop = driver.find_element_by_name("cts_hidetoplistflag")
new_hidtag = driver.find_element_by_name("cts_hidesearchtagflag")
new_hidtext = driver.find_element_by_name("cts_hideindexflag")
new_main_src = driver.find_element_by_xpath("//*[@id=\"cke_14\"]")
new_main_img = driver.find_element_by_xpath("//*[@id=\"cke_51\"]")
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
upload_thumb = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[9]/td/input[2]")
if data['datatype'] == "picture":
if os.path.getsize(os.getcwd() + f"\\kyu_img\\{data['media'].split('/')[-1]}") > 3000000:
upload_thumb.send_keys(os.getcwd() + f"/kyu_img/{data['media'].split('/')[-1]}"[:-4] + "_resized.jpg")
time.sleep(1.0)
else:
upload_thumb.send_keys(os.getcwd() + f"/kyu_img/{data['media'].split('/')[-1]}")
time.sleep(1.0)
elif data['datatype'] == "movie":
upload_thumb.send_keys(os.getcwd() + f"/kyu_img/{data['code']}" + ".jpg")
time.sleep(0.5)
new_file.send_keys(data['code'])
new_title.send_keys(data['title'])
new_inschool.click()
new_hidtop.click()
new_hidtag.click()
new_hidtext.click()
if data['datatype'] == 'picture':
new_main_img.click()
time.sleep(0.5)
new_main_img_upload = driver.find_element_by_id("cke_Upload_136")
driver.execute_script("arguments[0].click();", new_main_img_upload)
iframe = driver.find_element_by_xpath('//*[@id="cke_131_fileInput"]')
driver.switch_to.frame(iframe)
new_main_img_select = driver.find_element_by_xpath("//*[@id=\"cke_131_fileInput_input\"]")
new_main_img_select.send_keys(os.getcwd() + f"\\kyu_img\\{data['media'].split('/')[-1]}")
time.sleep(0.5)
driver.switch_to.default_content()
new_main_img_confirm = driver.find_element_by_id("cke_133_label")
new_main_img_confirm.click()
if os.path.getsize(os.getcwd() + f"\\kyu_img\\{data['media'].split('/')[-1]}") > 3000000:
time.sleep(60)
else:
time.sleep(20)
new_main_img_information = driver.find_element_by_id("cke_info_129")
new_main_img_information.click()
time.sleep(1.0)
new_main_img_infotext = driver.find_element_by_id("cke_95_textInput")
img_link = new_main_img_infotext.get_attribute('value')
new_main_img_back = driver.find_element_by_id("cke_140_label")
new_main_img_back.click()
driver.switch_to.alert.accept()
driver.switch_to.default_content()
index = 1
tag_options = []
tag_1 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li/select")
select_tag_1 = webdriver.support.select.Select(tag_1)
select_tag_1.select_by_visible_text('フリー')
time.sleep(0.5)
tag_2 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[1]/select[2]")
select_tag_2 = webdriver.support.select.Select(tag_2)
select_tag_2.select_by_visible_text('キューチューブバイオ')
time.sleep(0.5)
if data['datatype'] == 'picture':
tag_3 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[1]/select[3]")
select_tag_3 = webdriver.support.select.Select(tag_3)
all_available_options = select_tag_3.options
for item in all_available_options:
tag_options.append(item.text)
select_tag_3.select_by_visible_text('媒体種類 静止画')
else:
tag_3 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[1]/select[3]")
select_tag_3 = webdriver.support.select.Select(tag_3)
all_available_options = select_tag_3.options
for item in all_available_options:
tag_options.append(item.text)
select_tag_3.select_by_visible_text('媒体種類 動画')
index += 1
set_tag(driver, data, 'group1', tag_options, index)
index += 1
set_tag(driver, data, 'group2', tag_options, index)
index += 1
set_tag(driver, data, 'loc', tag_options, index)
try:
index += 1
set_tag(driver, data, 'tag', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'name', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'copy', tag_options, index)
except:
pass
try:
if data['jp name'] != '---':
index += 1
set_tag(driver, data, 'Division', tag_options, index)
index += 1
set_tag(driver, data, 'Class', tag_options, index)
except:
pass
new_main_src.click()
time.sleep(0.5)
new_main_textbox = driver.find_element_by_xpath("//*[@id=\"cke_1_contents\"]/textarea")
try:
comment = data['comment']
except:
comment = ""
codes = data['link'].split('/')[-1].upper()
if data['datatype'] == 'picture':
if data['en name'] != '---':
if data['loc'][-1] == '県' or data['loc'][-1] == '道' or data['loc'][-1] == '都' or data['loc'][-1] == '府':
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><img alt=\"\" src=\"{img_link}\" /> <p>{comment}</p><h4>{data['jp name']}</h4> \
<h3>{data['en name']}</h3><p><strong>門</strong><br />{data['Division']}<br /><strong>綱</strong><br />{data['Class']}</p><br /> <table align=\"center\"> \
<tbody><tr><th>都道府県</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><img alt=\"\" src=\"{img_link}\" /> <p>{comment}</p><h4>{data['jp name']}</h4> \
<h3>{data['en name']}</h3><p><strong>門</strong><br />{data['Division']}<br /><strong>綱</strong><br />{data['Class']}</p><br /> <table align=\"center\"> \
<tbody><tr><th>国</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
if data['loc'][-1] == '県' or data['loc'][-1] == '道' or data['loc'][-1] == '都' or data['loc'][-1] == '府':
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><img alt=\"\" src=\"{img_link}\" /> <p>{comment}</p><br /><table align=\"center\"> \
<tbody><tr><th>都道府県</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><img alt=\"\" src=\"{img_link}\" /> <p>{comment}</p><br /><table align=\"center\"> \
<tbody><tr><th>国</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
elif data['datatype'] == 'movie':
if data['en name'] != '---':
if data['loc'][-1] == '県' or data['loc'][-1] == '道' or data['loc'][-1] == '都' or data['loc'][-1] == '府':
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><div class=\"kaltura\"><iframe frameborder=\"0\" height=\"544\" id=\"kaltura_player\" \
src=\"{data['media']}\" title=\"Kaltura Player\" width=\"912\"></iframe></div> <p>{comment}</p><h4>{data['jp name']}</h4> \
<h3>{data['en name']}</h3><p><strong>門</strong><br />{data['Division']}<br /><strong>綱</strong><br />{data['Class']}</p><br /> <table align=\"center\"> \
<tbody><tr><th>都道府県</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><div class=\"kaltura\"><iframe frameborder=\"0\" height=\"544\" id=\"kaltura_player\" \
src=\"{data['media']}\" title=\"Kaltura Player\" width=\"912\"></iframe></div> <p>{comment}</p><h4>{data['jp name']}</h4> \
<h3>{data['en name']}</h3><p><strong>門</strong><br />{data['Division']}<br /><strong>綱</strong><br />{data['Class']}</p><br /> <table align=\"center\"> \
<tbody><tr><th>国</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
if data['loc'][-1] == '県' or data['loc'][-1] == '道' or data['loc'][-1] == '都' or data['loc'][-1] == '府':
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><div class=\"kaltura\"><iframe frameborder=\"0\" height=\"544\" id=\"kaltura_player\" \
src=\"{data['media']}\" title=\"Kaltura Player\" width=\"912\"></iframe></div> <p>{comment}</p><br /><table align=\"center\"> \
<tbody><tr><th>都道府県</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2><div class=\"kaltura\"><iframe frameborder=\"0\" height=\"544\" id=\"kaltura_player\" \
src=\"{data['media']}\" title=\"Kaltura Player\" width=\"912\"></iframe></div> <p>{comment}</p><br /><table align=\"center\"> \
<tbody><tr><th>国</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
new_main_src.click()
time.sleep(1.0)
try:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[3]")
new_confirm.click()
time.sleep(1.0)
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
time.sleep(2.0)
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
time.sleep(1.0)
except:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm.click()
time.sleep(1.0)
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
time.sleep(2.0)
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
time.sleep(1.0)
def many_page_edit(driver, data):
new_page_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/div[2]/form/input")
new_page_btn.click()
time.sleep(0.5)
new_file = driver.find_element_by_name("cts_filepath")
new_title = driver.find_element_by_name("cts_title")
new_inschool = driver.find_element_by_name("cts_inplaceflag")
new_hidtop = driver.find_element_by_name("cts_hidetoplistflag")
new_hidtag = driver.find_element_by_name("cts_hidesearchtagflag")
new_hidtext = driver.find_element_by_name("cts_hideindexflag")
new_main_img = driver.find_element_by_xpath("//*[@id=\"cke_51\"]")
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
data_path = f"\\kyu_img\\{data.upper()}"+".jpg"
upload_thumb = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[9]/td/input[2]")
if os.path.getsize(os.getcwd() + data_path) > 3000000:
upload_thumb.send_keys(os.getcwd() + f"\\kyu_img\\{data.upper()}" + "_resized.jpg")
time.sleep(7)
else:
upload_thumb.send_keys(os.getcwd() + data_path)
time.sleep(5)
new_file.send_keys(data)
new_title.send_keys(data.upper())
new_inschool.click()
new_hidtop.click()
new_hidtag.click()
new_hidtext.click()
new_main_img.click()
time.sleep(0.5)
new_main_img_upload = driver.find_element_by_id("cke_Upload_136")
driver.execute_script("arguments[0].click();", new_main_img_upload)
iframe = driver.find_element_by_xpath('//*[@id="cke_131_fileInput"]')
driver.switch_to.frame(iframe)
new_main_img_select = driver.find_element_by_xpath("//*[@id=\"cke_131_fileInput_input\"]")
new_main_img_select.send_keys(os.getcwd() + data_path)
time.sleep(0.5)
driver.switch_to.default_content()
new_main_img_confirm = driver.find_element_by_id("cke_133_label")
new_main_img_confirm.click()
if os.path.getsize(os.getcwd() + data_path) > 3000000:
time.sleep(60)
else:
time.sleep(20)
new_main_img_confirm_confirm = driver.find_element_by_id("cke_138_label")
new_main_img_confirm_confirm.click()
time.sleep(1.0)
try:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[3]")
new_confirm.click()
time.sleep(1.0)
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
time.sleep(2.0)
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
time.sleep(1.0)
except:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm.click()
time.sleep(1.0)
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
time.sleep(2.0)
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
time.sleep(1.0)
def folder_edit(driver, data):
new_page_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/div[2]/form/input")
new_page_btn.click()
codes = data['link'].split('/')[-1].upper().replace('-',',')
time.sleep(0.5)
isfolder = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[1]/td/label[2]/input")
isfolder.click()
new_file = driver.find_element_by_name("cts_filepath")
new_title = driver.find_element_by_name("cts_title")
new_inschool = driver.find_element_by_name("cts_inplaceflag")
new_hidtop = driver.find_element_by_name("cts_hidetoplistflag")
new_hidtag = driver.find_element_by_name("cts_hidesearchtagflag")
new_hidtext = driver.find_element_by_name("cts_hideindexflag")
new_main_src = driver.find_element_by_xpath("//*[@id=\"cke_14\"]")
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_file.send_keys(data['link'].split('/')[-1].split('-')[0]+'-'+data['link'].split('/')[-1].split('-')[-1])
new_title.send_keys(data['title'])
new_inschool.click()
new_hidtop.click()
new_hidtag.click()
new_hidtext.click()
index = 1
tag_options = []
tag_1 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li/select")
select_tag_1 = webdriver.support.select.Select(tag_1)
select_tag_1.select_by_visible_text('フリー')
time.sleep(0.5)
tag_2 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[1]/select[2]")
select_tag_2 = webdriver.support.select.Select(tag_2)
select_tag_2.select_by_visible_text('キューチューブバイオ')
time.sleep(0.5)
if data['datatype'] == 'picture':
tag_3 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[1]/select[3]")
select_tag_3 = webdriver.support.select.Select(tag_3)
all_available_options = select_tag_3.options
for item in all_available_options:
tag_options.append(item.text)
select_tag_3.select_by_visible_text('媒体種類 静止画')
else:
tag_3 = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[1]/select[3]")
select_tag_3 = webdriver.support.select.Select(tag_3)
all_available_options = select_tag_3.options
for item in all_available_options:
tag_options.append(item.text)
select_tag_3.select_by_visible_text('媒体種類 動画')
try:
index += 1
set_tag(driver, data, 'group1', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'group2', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'loc', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'tag', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'name', tag_options, index)
except:
pass
try:
index += 1
set_tag(driver, data, 'copy', tag_options, index)
except:
pass
try:
if data['jp name'] != '---':
index += 1
set_tag(driver, data, 'Division', tag_options, index)
index += 1
set_tag(driver, data, 'Class', tag_options, index)
except:
pass
new_main_src.click()
time.sleep(0.5)
new_main_textbox = driver.find_element_by_xpath("//*[@id=\"cke_1_contents\"]/textarea")
try:
comment = data['comment']
except:
comment = ""
codes = data['link'].split('/')[-1].upper()
if data['en name'] != '---':
if data['loc'][-1] == '県' or data['loc'][-1] == '道' or data['loc'][-1] == '都' or data['loc'][-1] == '府':
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2> <p>{comment}</p> <h4>{data['jp name']}</h4> \
<h3>{data['en name']}</h3><p><strong>門</strong><br />{data['Division']}<br /><strong>綱</strong><br />{data['Class']}</p><br /> <table align=\"center\"> \
<tbody><tr><th>都道府県</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2> <p>{comment}</p> <h4>{data['jp name']}</h4> \
<h3>{data['en name']}</h3><p><strong>門</strong><br />{data['Division']}<br /><strong>綱</strong><br />{data['Class']}</p><br /> <table align=\"center\"> \
<tbody><tr><th>国</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
if data['loc'][-1] == '県' or data['loc'][-1] == '道' or data['loc'][-1] == '都' or data['loc'][-1] == '府':
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2> <p>{comment}</p> <br /><table align=\"center\"> \
<tbody><tr><th>都道府県</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
else:
new_main_textbox.send_keys(f"<h2>{data['group1']} {data['group2']} {codes}</h2> <p>{comment}</p> <br /><table align=\"center\"> \
<tbody><tr><th>国</th><td>{data['loc']}</td><th>顕微鏡の利用</th><td>{data['microscope']}</td></tr> \
<tr><th>地域</th><td>{data['region']}</td><th>自動撮影装置の利用</th><td>{data['automatic']}</td></tr> \
<tr><th>撮影日</th><td>{data['date']}</td><th>赤外線</th><td>{data['ultraviolet']}</td></tr> \
<tr><th>撮影時刻</th><td>{data['time']}</td><th>蛍光プローブ</th><td>{data['probe']}</td></tr> \
<tr><th>撮影者</th><td>{data['name']}</td><th>時間間隔 (秒)</th><td>{data['interval']}</td></tr> \
<tr><th>著作権者</th><td>{data['copy']}</td><th>速度</th><td>{data['speed']}</td></tr></tbody></table><br />\
<a href=\"http://www.sci.kyoto-u.ac.jp/en/research/kyutubebio/{page_index}/{data['code']}.html\">in English</a>")
new_main_src.click()
time.sleep(1.0)
try:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[3]")
new_confirm.click()
time.sleep(1.0)
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
time.sleep(2.0)
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
time.sleep(1.0)
except:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm.click()
time.sleep(1.0)
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
time.sleep(2.0)
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
time.sleep(1.0)
def set_tag(driver, data, tag_name, options, index):
tag_1 = driver.find_element_by_xpath(f"//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[{index}]/select")
select_tag_1 = webdriver.support.select.Select(tag_1)
select_tag_1.select_by_visible_text('フリー')
time.sleep(0.5)
tag_2 = driver.find_element_by_xpath(f"//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[{index}]/select[2]")
select_tag_2 = webdriver.support.select.Select(tag_2)
select_tag_2.select_by_visible_text('キューチューブバイオ')
time.sleep(0.5)
tag_3 = driver.find_element_by_xpath(f"//*[@id=\"container\"]/form/table[1]/tbody/tr[11]/td/ul/li[{index}]/select[3]")
select_tag_3 = webdriver.support.select.Select(tag_3)
for tag in options:
if tag_name == 'name':
if (data[tag_name] in tag) and ('撮影者' in tag):
select_tag_3.select_by_visible_text(tag)
elif tag_name == 'copy':
if (data[tag_name] in tag) and ('著作権者' in tag):
select_tag_3.select_by_visible_text(tag)
else:
if data[tag_name] in tag:
select_tag_3.select_by_visible_text(tag)
def read_data():
col = ['title', 'code', 'datatype', 'group1', 'group2', 'media', 'comment', 'jp name', 'en name', 'Division', 'Class', 'loc', 'region', 'date', 'time', 'name', 'copy', 'microscope', 'automatic', 'ultraviolet', 'probe', 'interval', 'speed', 'link', 'tag']
d = pd.read_csv("./data_jp_final.csv", names=col, encoding='utf-8')
print(d)
return d
def check_data(title, data):
data_mask = data['link'].str.contains(title[:6])
filtered_data = data[~data_mask]
return filtered_data
def login(driver, userid, userpw):
sci_admin_id = driver.find_element_by_name("act_id")
sci_admin_pw = driver.find_element_by_name("act_passwd")
sci_admin_id.send_keys(userid)
sci_admin_pw.send_keys(userpw)
sci_admin_login = driver.find_element_by_xpath("/html/body/form/div/input")
sci_admin_login.click()
if __name__ == "__main__":
data = read_data()
userid = "lee"
userpw = "Mv3qKTUH"
#userid = input("Enter your admin id: ")
#userpw = input("Enter your admin password: ")
driver = webdriver.Chrome()
driver.get("https://www.sci.kyoto-u.ac.jp/ja/admin/")
login(driver, userid, userpw)
time.sleep(0.5)
research_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/table/tbody/tr[4]/td[7]/input[2]")
research_btn.click()
time.sleep(0.5)
kyutube_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/table/tbody/tr[15]/td[7]/input[2]")
kyutube_btn.click()
time.sleep(0.5)
total_page = 0
while True:
print("\nKyU Tube Bio List INDEX")
print("3\t構造生理学\t\t4\tゲノム情報発現学\t5\t神経生物学")
print("6\t理論生物物理学\t\t7\t分子生体情報学\t\t8\t分子発生学")
print("9\t植物生理学\t\t10\t形態統御学\t\t11\t植物分子細胞生物学")
print("12\t植物分子遺伝学\t\t13\t植物系統分類学\t\t14\t動物系統学")
print("15\t動物行動学\t\t16\t動物生態学\t\t17\t動物発生学")
print("18\t環境応答遺伝子科学\t19\t自然人類学\t\t20\t人類進化論")
i = int(input("Choose INDEX number : "))
global page_index
page_index = 2889 + i
title = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{i}]/td[3]")
title_text = title.text
data_mask = data['group2'] == title_text
filtered_data = data[data_mask]
len_first = len(filtered_data)
print("Searching element in title : " + title_text)
title_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{i}]/td[7]/input[2]")
title_btn.click()
time.sleep(0.5)
title_sib_list = driver.find_elements_by_class_name("ctlr-line")
cur_url = driver.current_url
title_list = driver.find_elements_by_class_name("ctlr-line")
for i, (j, d) in enumerate(filtered_data.iterrows()):
i = i
if i != 3:
continue
link = d['link']
ty = d['media']
code = link.split('/')[-1]
codelen = len(code)
if len(code) > 6:
codes = code.split('-')
folder_edit(driver, d)
if i > 24:
ii = i%25
pp = int(i/25)
pp_url = f"https://www.sci.kyoto-u.ac.jp/ja/admin/contents/?pageno={pp+1}&parentcode=7500"
driver.get(pp_url)
btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{2+ii}]/td[7]/input[2]")
btn.click()
for c in codes:
many_page_edit(driver, c)
else:
btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{11+i}]/td[7]/input[2]")
btn.click()
for c in codes:
many_page_edit(driver, c)
else:
page_edit(driver, d)
driver.get(cur_url)
back = driver.find_element_by_xpath("//*[@id=\"container\"]/div[1]/span[3]/a")
back.click()
time.sleep(0.5)
a = input("Do MORE?(y/n) : ")
if a == "n":
driver.quit()
break