forked from djib/PDMameUpdate
Add clean disconnect and count down timer
This commit is contained in:
@ -43,6 +43,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
import time
|
||||||
from clutch.core import Client
|
from clutch.core import Client
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
@ -98,7 +99,7 @@ def prompt_for_update():
|
|||||||
"""Ask for user confirmation before updating"""
|
"""Ask for user confirmation before updating"""
|
||||||
|
|
||||||
if len(torrents) > 0:
|
if len(torrents) > 0:
|
||||||
for torrent, data in torrents:
|
for torrent, data in torrents.items():
|
||||||
print('Torrent {}: {} -> {}'.format(
|
print('Torrent {}: {} -> {}'.format(
|
||||||
torrent,
|
torrent,
|
||||||
data['local-version'],
|
data['local-version'],
|
||||||
@ -128,6 +129,8 @@ def get_cookies_from_pleasuredome():
|
|||||||
r = requests.post('http://www.pleasuredome.org.uk/login2.php', data=data)
|
r = requests.post('http://www.pleasuredome.org.uk/login2.php', data=data)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
logging.info('Connected to PleasureDome')
|
logging.info('Connected to PleasureDome')
|
||||||
|
logging.info('Logging out')
|
||||||
|
requests.get('http://www.pleasuredome.org.uk/logout.php')
|
||||||
else:
|
else:
|
||||||
logging.error(
|
logging.error(
|
||||||
'Connection to PleasureDome failed with status %s',
|
'Connection to PleasureDome failed with status %s',
|
||||||
@ -176,15 +179,22 @@ def update_torrents():
|
|||||||
client.torrent.add(
|
client.torrent.add(
|
||||||
filename=torrent['remote-link'],
|
filename=torrent['remote-link'],
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
paused=True
|
paused=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format=' %(asctime)s - %(levelname)s - %(message)s'
|
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+) (.*)')
|
re_mame_version = re.compile('MAME 0.(\d+) (.*)')
|
||||||
config = open_config_file()
|
config = open_config_file()
|
||||||
torrents = defaultdict(dict)
|
torrents = defaultdict(dict)
|
||||||
|
Reference in New Issue
Block a user