From 04bc2d263cc9714709e182353ad49b952ed4f8d1 Mon Sep 17 00:00:00 2001 From: djib Date: Wed, 16 Oct 2019 10:05:20 +0200 Subject: [PATCH] Make the program easier to use (auto configuration for the authentication token) --- FreeboxMoviePlanner.py | 17 +++++++++++++++++ Readme.md | 35 +++++++++++++++++------------------ config.template.json | 10 +++++----- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py index 60cf776..dcf8092 100755 --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -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