mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-22 17:09:20 +02:00
Fix: create auth file if no exists
This commit is contained in:
parent
9181923e52
commit
3ea5a1fcb9
|
@ -1,9 +1,27 @@
|
|||
from src.mpv_control import set_http_header
|
||||
import requests, json, time
|
||||
import os
|
||||
from loguru import logger
|
||||
|
||||
with open('.auth.json', 'rt') as f:
|
||||
auth = json.loads(f.read())
|
||||
auth_file = '.auth.json'
|
||||
if os.path.exists(auth_file):
|
||||
with open('.auth.json', 'rt') as f:
|
||||
auth = json.loads(f.read())
|
||||
else:
|
||||
# The default umask is 0o22 which turns off write permission of group and others
|
||||
os.umask(0)
|
||||
|
||||
descriptor = os.open(
|
||||
path=auth_file,
|
||||
flags=(
|
||||
os.O_WRONLY # access mode: write only
|
||||
| os.O_CREAT # create if not exists
|
||||
| os.O_TRUNC # truncate the file to zero
|
||||
),
|
||||
mode=0o600)
|
||||
with open(descriptor, 'wt') as f:
|
||||
f.write('{}')
|
||||
auth = {}
|
||||
|
||||
s = requests.Session()
|
||||
instance = 'fw.ponychord.rocks'
|
||||
|
@ -24,7 +42,7 @@ else:
|
|||
def select_instance(new_instance=None):
|
||||
global instance
|
||||
instance = new_instance
|
||||
with open('.auth.json', 'rt') as f:
|
||||
with open(auth_file, 'rt') as f:
|
||||
auth = json.loads(f.read())
|
||||
new_token = auth.get(instance)
|
||||
s.headers.update({"Authorization": None,
|
||||
|
|
Loading…
Reference in New Issue