From 30f34e9353e1964a03502ec373e17c90adb3693b Mon Sep 17 00:00:00 2001 From: djib Date: Mon, 16 Sep 2019 15:45:24 +0200 Subject: [PATCH] Add clean disconnect and count down timer --- PDMameUpdate.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index ef3ba6e..28db4db 100644 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -43,6 +43,7 @@ import logging import os import re import requests +import time from clutch.core import Client from collections import defaultdict from pprint import pformat @@ -98,7 +99,7 @@ def prompt_for_update(): """Ask for user confirmation before updating""" if len(torrents) > 0: - for torrent, data in torrents: + for torrent, data in torrents.items(): print('Torrent {}: {} -> {}'.format( torrent, data['local-version'], @@ -128,6 +129,8 @@ def get_cookies_from_pleasuredome(): r = requests.post('http://www.pleasuredome.org.uk/login2.php', data=data) if r.status_code == 200: logging.info('Connected to PleasureDome') + logging.info('Logging out') + requests.get('http://www.pleasuredome.org.uk/logout.php') else: logging.error( 'Connection to PleasureDome failed with status %s', @@ -176,15 +179,22 @@ def update_torrents(): client.torrent.add( filename=torrent['remote-link'], cookies=cookies, - paused=True + paused=False ) + if __name__ == '__main__': logging.basicConfig( level=logging.INFO, format=' %(asctime)s - %(levelname)s - %(message)s' ) + print('PDMameUpdate is about to start') + # Useful if you run this script when your machine boots + for i in range(5,0,-1): + print('{}\r'.format(i), end=''), + time.sleep(1) + re_mame_version = re.compile('MAME 0.(\d+) (.*)') config = open_config_file() torrents = defaultdict(dict)