Format code to PEP8 standards

This commit is contained in:
2019-10-23 20:58:15 +02:00
parent 7b5196fb11
commit 769d4b116c

View File

@ -50,6 +50,7 @@ from clutch.core import Client
from collections import defaultdict
from pprint import pformat
def open_config_file():
"""Reads configuration from config.json file"""
@ -68,7 +69,7 @@ def fetch_local_torrents():
match = re_mame_version.match(directory)
if match:
torrents[match.group(2)]['local-version'] = int(match.group(1))
torrents[match.group(2)]['local-name'] = directory
torrents[match.group(2)]['local-name'] = directory
logging.debug('Found the local torrent versions: %s', pformat(torrents))
@ -81,8 +82,8 @@ def fetch_remote_terrents():
match = re_mame_version.match(post.title)
if match:
torrents[match.group(2)]['remote-version'] = int(match.group(1))
torrents[match.group(2)]['remote-link'] = post.link
torrents[match.group(2)]['remote-name'] = post.title
torrents[match.group(2)]['remote-link'] = post.link
torrents[match.group(2)]['remote-name'] = post.title
logging.debug('Found the remote torrent versions: %s', pformat(torrents))
@ -90,11 +91,16 @@ def filter_updatable_torrents():
"""Checks if newer versions are available and prompt for update"""
for torrent, data in list(torrents.items()):
keys_to_check = {'local-version','remote-version','transmission-id'}
if not ( keys_to_check.issubset(data.keys())
and data['local-version'] < data['remote-version']):
keys_to_check = {'local-version', 'remote-version', 'transmission-id'}
if not (
keys_to_check.issubset(data.keys())
and
data['local-version'] < data['remote-version']
):
del torrents[torrent]
logging.info('The following torrents can be updated: %s', pformat(torrents))
logging.info(
'The following torrents can be updated: %s', pformat(torrents)
)
def prompt_for_update():
@ -125,8 +131,8 @@ def get_cookies_from_pleasuredome():
logging.info('Logging in PleasureDome')
data = {
'uid':config['pleasuredome-user'],
'pwd':config['pleasuredome-password']
'uid': config['pleasuredome-user'],
'pwd': config['pleasuredome-password']
}
r = requests.post('http://www.pleasuredome.org.uk/login2.php', data=data)
if r.status_code == 200:
@ -139,7 +145,7 @@ def get_cookies_from_pleasuredome():
r.status_code
)
exit(1)
return {k: r.cookies[k] for k in ('uid','pass')}
return {k: r.cookies[k] for k in ('uid', 'pass')}
def connect_to_transmission():
@ -173,10 +179,16 @@ def update_torrents():
"""
logging.info('Updating torrents')
for torrent in torrents.values():
old_name = os.path.join(config['mame-directory'], torrent['local-name'])
new_name = os.path.join(config['mame-directory'], torrent['remote-name'])
old_name = os.path.join(
config['mame-directory'],
torrent['local-name']
)
new_name = os.path.join(
config['mame-directory'],
torrent['remote-name']
)
client.torrent.remove(torrent['transmission-id']);
client.torrent.remove(torrent['transmission-id'])
os.rename(old_name, new_name)
client.torrent.add(
filename=torrent['remote-link'],
@ -194,11 +206,11 @@ if __name__ == '__main__':
print('PDMameUpdate is about to start')
# Useful if you run this script when your machine boots
for i in range(5,0,-1):
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(r'MAME 0.(\d+) (.*)')
config = open_config_file()
torrents = defaultdict(dict)