1- import requests
1+ """Script for controlling RICOH THETA camera."""
2+
23import time
34import datetime
45
6+ import requests
7+
8+ # pylint: disable=duplicate-code
9+
510# カメラIP
611THETA_IP = "192.168.1.1"
712EXECUTE_URL = f"http://{ THETA_IP } /osc/commands/execute"
813STATUS_URL = f"http://{ THETA_IP } /osc/commands/status"
914
1015HEADERS = {"Content-Type" : "application/json;charset=utf-8" }
1116
12- # 撮影設定リスト (ISO, ShutterSpeed , ColorTemperature)
17+ # 撮影設定リスト (ISO, shutter_speed , ColorTemperature)
1318settings_list = [
14- {"iso" : 100 , "shutterSpeed " : 0.00004 , "whiteBalance " : 5200 },
15- {"iso" : 100 , "shutterSpeed " : 0.00008 , "whiteBalance " : 5200 },
16- {"iso" : 100 , "shutterSpeed " : 0.0003125 , "whiteBalance " : 5200 },
17- {"iso" : 100 , "shutterSpeed " : 0.000625 , "whiteBalance " : 5200 },
18- {"iso" : 100 , "shutterSpeed " : 0.0025 , "whiteBalance " : 5200 },
19- {"iso" : 100 , "shutterSpeed " : 0.005 , "whiteBalance " : 5200 },
20- {"iso" : 100 , "shutterSpeed " : 0.02 , "whiteBalance " : 5200 },
21- {"iso" : 100 , "shutterSpeed " : 0.04 , "whiteBalance " : 5200 },
22- {"iso" : 100 , "shutterSpeed " : 0.16666666 , "whiteBalance " : 5200 },
23- {"iso" : 100 , "shutterSpeed " : 0.33333333 , "whiteBalance " : 5200 },
24- {"iso" : 100 , "shutterSpeed " : 0.625 , "whiteBalance " : 5200 },
25- {"iso" : 100 , "shutterSpeed " : 3.2 , "whiteBalance " : 5200 },
19+ {"iso" : 100 , "shutter_speed " : 0.00004 , "white_balance " : 5200 },
20+ {"iso" : 100 , "shutter_speed " : 0.00008 , "white_balance " : 5200 },
21+ {"iso" : 100 , "shutter_speed " : 0.0003125 , "white_balance " : 5200 },
22+ {"iso" : 100 , "shutter_speed " : 0.000625 , "white_balance " : 5200 },
23+ {"iso" : 100 , "shutter_speed " : 0.0025 , "white_balance " : 5200 },
24+ {"iso" : 100 , "shutter_speed " : 0.005 , "white_balance " : 5200 },
25+ {"iso" : 100 , "shutter_speed " : 0.02 , "white_balance " : 5200 },
26+ {"iso" : 100 , "shutter_speed " : 0.04 , "white_balance " : 5200 },
27+ {"iso" : 100 , "shutter_speed " : 0.16666666 , "white_balance " : 5200 },
28+ {"iso" : 100 , "shutter_speed " : 0.33333333 , "white_balance " : 5200 },
29+ {"iso" : 100 , "shutter_speed " : 0.625 , "white_balance " : 5200 },
30+ {"iso" : 100 , "shutter_speed " : 3.2 , "white_balance " : 5200 },
2631]
2732
28- def set_options (iso , shutterSpeed , whiteBalance ):
33+
34+ def set_options (iso , shutter_speed , white_balance ):
35+ """オプションを設定"""
2936 options_command = {
3037 "name" : "camera.setOptions" ,
3138 "parameters" : {
3239 "options" : {
3340 "iso" : iso ,
34- "shutterSpeed" : shutterSpeed ,
41+ "shutterSpeed" : shutter_speed ,
3542 "whiteBalance" : "_colorTemperature" ,
36- "colorTemperature" : whiteBalance
43+ "colorTemperature" : white_balance ,
3744 }
38- }
45+ },
3946 }
40- resp = requests .post (EXECUTE_URL , json = options_command , headers = HEADERS )
47+ resp = requests .post (EXECUTE_URL , json = options_command , headers = HEADERS , timeout = 10 )
4148 resp .raise_for_status ()
4249 return resp .json ()
4350
51+
4452def take_picture ():
53+ """Theta Web APIを用いて撮影"""
4554 take_command = {"name" : "camera.takePicture" }
46- resp = requests .post (EXECUTE_URL , json = take_command , headers = HEADERS )
55+ resp = requests .post (EXECUTE_URL , json = take_command , headers = HEADERS , timeout = 10 )
4756 resp .raise_for_status ()
4857 return resp .json ()
4958
59+
5060def wait_for_completion (command_id ):
61+ """撮影完了まで処理を停止"""
5162 while True :
52- status_resp = requests .post (STATUS_URL , json = {"id" : command_id }, headers = HEADERS )
63+ status_resp = requests .post (
64+ STATUS_URL , json = {"id" : command_id }, headers = HEADERS , timeout = 10
65+ )
5366 status_resp .raise_for_status ()
5467 status = status_resp .json ()
5568 if status .get ("state" ) == "done" :
5669 return status .get ("results" )
5770 time .sleep (0.5 )
5871
72+
5973def capture_12 ():
6074 """設定リストに従って12枚連続撮影"""
6175 for idx , s in enumerate (settings_list , start = 1 ):
@@ -72,6 +86,7 @@ def capture_12():
7286 else :
7387 print ("即時撮影結果:" , result )
7488
89+
7590def schedule_shoots ():
7691 """午前6時~午後7時まで1時間おきに3回ずつ撮影"""
7792 while True :
@@ -89,15 +104,20 @@ def schedule_shoots():
89104 print (f"\n === { hour } 時の撮影完了 ===" )
90105
91106 # 次の「正時」まで待つ
92- next_hour = (now + datetime .timedelta (hours = 1 )).replace (minute = 0 , second = 0 , microsecond = 0 )
107+ next_hour = (now + datetime .timedelta (hours = 1 )).replace (
108+ minute = 0 , second = 0 , microsecond = 0
109+ )
93110 wait_sec = (next_hour - datetime .datetime .now ()).total_seconds ()
94111 if wait_sec < 0 :
95- next_hour = (now + datetime .timedelta (hours = 2 )).replace (minute = 0 , second = 0 , microsecond = 0 )
112+ next_hour = (now + datetime .timedelta (hours = 2 )).replace (
113+ minute = 0 , second = 0 , microsecond = 0
114+ )
96115 wait_sec = (next_hour - datetime .datetime .now ()).total_seconds ()
97116 print (f"{ wait_sec / 60 :.1f} 分後の { next_hour } に再開します…" )
98- for sleepCount in range (0 ,61 ):
99- print (f"残り{ wait_sec * (60 - sleepCount )/ 60 } 秒" )
100- time .sleep (wait_sec / 60 )
117+ for sleep_count in range (0 , 61 ):
118+ print (f"残り{ wait_sec * (60 - sleep_count )/ 60 } 秒" )
119+ time .sleep (wait_sec / 60 )
120+
101121
102122if __name__ == "__main__" :
103123 schedule_shoots ()
0 commit comments