Skip to content

Commit a4cc89a

Browse files
authored
Merge pull request #10 from Ch1hiro/9-apply-lint
9 Lintの実行
2 parents 1aabfc5 + af7f6b1 commit a4cc89a

6 files changed

Lines changed: 106 additions & 77 deletions

File tree

.github/workflows/pylint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
run: |
1919
python -m pip install --upgrade pip
2020
pip install pylint
21+
pip install -r requirements.txt
2122
- name: Analysing the code with pylint
2223
run: |
2324
pylint $(git ls-files '*.py')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

theta_capture.py

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,75 @@
1-
import requests
1+
"""Script for controlling RICOH THETA camera."""
2+
23
import time
34
import datetime
45

6+
import requests
7+
8+
# pylint: disable=duplicate-code
9+
510
# カメラIP
611
THETA_IP = "192.168.1.1"
712
EXECUTE_URL = f"http://{THETA_IP}/osc/commands/execute"
813
STATUS_URL = f"http://{THETA_IP}/osc/commands/status"
914

1015
HEADERS = {"Content-Type": "application/json;charset=utf-8"}
1116

12-
# 撮影設定リスト (ISO, ShutterSpeed, ColorTemperature)
17+
# 撮影設定リスト (ISO, shutter_speed, ColorTemperature)
1318
settings_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+
4452
def 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+
5060
def 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+
5973
def 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+
7590
def 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

102122
if __name__ == "__main__":
103123
schedule_shoots()

theta_init.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1+
"""Script for controlling RICOH THETA camera."""
2+
13
import requests
24

3-
url = "http://192.168.1.1/osc/commands/execute"
4-
headers = {"Content-Type": "application/json;charset=utf-8"}
5+
# pylint: disable=duplicate-code
6+
7+
URL = "http://192.168.1.1/osc/commands/execute"
8+
HEADERS = {"Content-Type": "application/json;charset=utf-8"}
59

610
payload = {
711
"name": "camera.setOptions",
8-
"parameters": {
9-
"options": {
10-
"captureMode":"image"
11-
}
12-
}
12+
"parameters": {"options": {"captureMode": "image"}},
1313
}
1414

15-
resp = requests.post(url, json=payload, headers=headers)
15+
resp = requests.post(URL, json=payload, headers=HEADERS, timeout=10)
1616
print(resp.json())
1717

1818
payload = {
1919
"name": "camera.setOptions",
20-
"parameters": {
21-
"options": {
22-
"exposureProgram":1
23-
}
24-
}
20+
"parameters": {"options": {"exposureProgram": 1}},
2521
}
2622

27-
resp = requests.post(url, json=payload, headers=headers)
28-
print(resp.json())
23+
resp = requests.post(URL, json=payload, headers=HEADERS, timeout=10)
24+
print(resp.json())

theta_status.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
"""Script for controlling RICOH THETA camera."""
2+
13
import requests
24

3-
url = "http://192.168.1.1/osc/commands/execute"
4-
headers = {"Content-Type": "application/json;charset=utf-8"}
5+
# pylint: disable=duplicate-code
6+
7+
URL = "http://192.168.1.1/osc/commands/execute"
8+
HEADERS = {"Content-Type": "application/json;charset=utf-8"}
59

610
# 確認したいオプションを parameters に必ず入れる
711
payload = {
812
"name": "camera.getOptions",
913
"parameters": {
10-
"optionNames": [
11-
"iso",
12-
"shutterSpeed",
13-
"aperture",
14-
"_colorTemperature"
15-
]
16-
}
14+
"optionNames": ["iso", "shutterSpeed", "aperture", "_colorTemperature"]
15+
},
1716
}
1817

19-
resp = requests.post(url, json=payload, headers=headers)
18+
resp = requests.post(URL, json=payload, headers=HEADERS, timeout=10)
2019
print(resp.json())

theta_test_capture.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,82 @@
1-
import requests
1+
"""Script for controlling RICOH THETA camera."""
2+
23
import time
34

5+
import requests
6+
7+
# pylint: disable=duplicate-code
8+
49
# カメラIP
510
THETA_IP = "192.168.1.1"
611
EXECUTE_URL = f"http://{THETA_IP}/osc/commands/execute"
712
STATUS_URL = f"http://{THETA_IP}/osc/commands/status"
813

9-
HEADERS = {
10-
"Content-Type": "application/json;charset=utf-8"
11-
}
14+
HEADERS = {"Content-Type": "application/json;charset=utf-8"}
1215

13-
# 撮影設定リスト (ISO, ShutterSpeed, f, ColorTemperature)
16+
# 撮影設定リスト (ISO, shutter_speed, f, ColorTemperature)
1417
settings_list = [
15-
{"iso": 100, "shutterSpeed": 0.00004, "whiteBalance": 5200},
16-
{"iso": 100, "shutterSpeed": 0.00008, "whiteBalance": 5200},
17-
{"iso": 100, "shutterSpeed": 0.0003125, "whiteBalance": 5200},
18-
{"iso": 100, "shutterSpeed": 0.000625, "whiteBalance": 5200},
19-
{"iso": 100, "shutterSpeed": 0.0025, "whiteBalance": 5200},
20-
{"iso": 100, "shutterSpeed": 0.005, "whiteBalance": 5200},
21-
{"iso": 100, "shutterSpeed": 0.02, "whiteBalance": 5200},
22-
{"iso": 100, "shutterSpeed": 0.04, "whiteBalance": 5200},
23-
{"iso": 100, "shutterSpeed": 0.16666666, "whiteBalance": 5200},
24-
{"iso": 100, "shutterSpeed": 0.33333333, "whiteBalance": 5200},
25-
{"iso": 100, "shutterSpeed": 0.625, "whiteBalance": 5200},
26-
{"iso": 100, "shutterSpeed": 3.2, "whiteBalance": 5200},
18+
{"iso": 100, "shutter_speed": 0.00004, "white_balance": 5200},
19+
{"iso": 100, "shutter_speed": 0.00008, "white_balance": 5200},
20+
{"iso": 100, "shutter_speed": 0.0003125, "white_balance": 5200},
21+
{"iso": 100, "shutter_speed": 0.000625, "white_balance": 5200},
22+
{"iso": 100, "shutter_speed": 0.0025, "white_balance": 5200},
23+
{"iso": 100, "shutter_speed": 0.005, "white_balance": 5200},
24+
{"iso": 100, "shutter_speed": 0.02, "white_balance": 5200},
25+
{"iso": 100, "shutter_speed": 0.04, "white_balance": 5200},
26+
{"iso": 100, "shutter_speed": 0.16666666, "white_balance": 5200},
27+
{"iso": 100, "shutter_speed": 0.33333333, "white_balance": 5200},
28+
{"iso": 100, "shutter_speed": 0.625, "white_balance": 5200},
29+
{"iso": 100, "shutter_speed": 3.2, "white_balance": 5200},
2730
]
2831

29-
def set_options(iso, shutterSpeed, whiteBalance):
32+
33+
def set_options(iso, shutter_speed, white_balance):
34+
"""オプションを設定"""
3035
options_command = {
3136
"name": "camera.setOptions",
3237
"parameters": {
3338
"options": {
3439
"iso": iso,
35-
"shutterSpeed": shutterSpeed,
36-
"_colorTemperature": whiteBalance
40+
"shutterSpeed": shutter_speed,
41+
"_colorTemperature": white_balance,
3742
}
38-
}
43+
},
3944
}
40-
resp = requests.post(EXECUTE_URL, json=options_command, headers=HEADERS)
45+
resp = requests.post(EXECUTE_URL, json=options_command, headers=HEADERS, timeout=10)
4146
resp.raise_for_status()
4247
return resp.json()
4348

49+
4450
def take_picture():
51+
"""Take a picture using the Theta API"""
4552
take_command = {"name": "camera.takePicture"}
46-
resp = requests.post(EXECUTE_URL, json=take_command, headers=HEADERS)
53+
resp = requests.post(EXECUTE_URL, json=take_command, headers=HEADERS, timeout=10)
4754
resp.raise_for_status()
4855
return resp.json()
4956

57+
5058
def wait_for_completion(command_id):
59+
"""Wait a few seconds to complete"""
5160
while True:
52-
status_resp = requests.post(STATUS_URL, json={"id": command_id}, headers=HEADERS)
61+
status_resp = requests.post(
62+
STATUS_URL, json={"id": command_id}, headers=HEADERS, timeout=10
63+
)
5364
status_resp.raise_for_status()
5465
status = status_resp.json()
5566
if status.get("state") == "done":
5667
return status.get("results")
5768
time.sleep(0.5)
5869

70+
5971
# 連続撮影
6072
for idx, s in enumerate(settings_list, start=1):
6173
print(f"\n=== 撮影 {idx}/12 ===")
6274
set_options(**s)
6375
print("設定完了:", s)
64-
76+
6577
result = take_picture()
6678
print("撮影コマンド送信:", result)
67-
79+
6880
if "id" in result:
6981
pic_result = wait_for_completion(result["id"])
7082
print("撮影完了:", pic_result)

0 commit comments

Comments
 (0)