36 lines
769 B
Python
36 lines
769 B
Python
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
|
|
import urllib3
|
|
|
|
|
|
def open_door(host, username, password):
|
|
urllib3.PoolManager().request(
|
|
"GET",
|
|
f"http://{host}/local/Doorcom/door.cgi?r=1",
|
|
headers=urllib3.make_headers(basic_auth=f"{username}:{password}"),
|
|
)
|
|
|
|
|
|
def read_file_contents(file_name):
|
|
with open(file_name, "r", encoding="utf-8") as f:
|
|
return f.read()
|
|
|
|
|
|
def main():
|
|
with open(
|
|
"/etc/myintercom-doorbell/settings.json", "r", encoding="utf-8"
|
|
) as config_file:
|
|
config = json.load(config_file)
|
|
|
|
open_door(
|
|
host=config["host"],
|
|
username=config["username"],
|
|
password=read_file_contents(config["passwordFile"]),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|