Make the program easier to use (auto configuration for the authentication token)
This commit is contained in:
@ -9,6 +9,7 @@ import json
|
||||
import logging
|
||||
import re
|
||||
import requests
|
||||
import socket
|
||||
import textwrap
|
||||
import tmdbsimple
|
||||
from pyfbx.pyfbx import Fbx
|
||||
@ -135,6 +136,8 @@ class FreeboxMoviePlanner:
|
||||
logging.debug('Opening config file: config.json')
|
||||
with open('config.json') as config_file:
|
||||
self.config = json.load(config_file)
|
||||
if(len(self.config['freebox-session-token']) != 64):
|
||||
self.createAuthenticationToken()
|
||||
tmdbsimple.API_KEY = self.config['tmdb-api']
|
||||
self.movies = movies
|
||||
|
||||
@ -154,6 +157,20 @@ class FreeboxMoviePlanner:
|
||||
self.programMovies()
|
||||
self.checkForConflicts()
|
||||
|
||||
def createAuthenticationToken(self):
|
||||
logging.info('Creating authentication token')
|
||||
self.freebox = Fbx(nomdns=True)
|
||||
hostname = socket.gethostname()
|
||||
print("You don't seem to have an authentication token.")
|
||||
print("I will now atempt to create one.")
|
||||
print("Please go to your Freebox and accept the authentication.")
|
||||
token = self.freebox.register(
|
||||
"FreeboxMoviePlanner", "FreeboxMoviePlanner", hostname
|
||||
)
|
||||
self.config['freebox-session-token'] = token
|
||||
with open('config.json', 'w') as outfile:
|
||||
json.dump(self.config, outfile, indent=4, sort_keys=True)
|
||||
|
||||
def __repr__(self):
|
||||
result = 'FreeboxMoviePlanner <Movies:\n'
|
||||
for movie in self.movies:
|
||||
|
Reference in New Issue
Block a user