forked from djib/PDMameUpdate
Format code to PEP8 standards
This commit is contained in:
@ -50,6 +50,7 @@ from clutch.core import Client
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
|
|
||||||
def open_config_file():
|
def open_config_file():
|
||||||
"""Reads configuration from config.json file"""
|
"""Reads configuration from config.json file"""
|
||||||
|
|
||||||
@ -90,11 +91,16 @@ def filter_updatable_torrents():
|
|||||||
"""Checks if newer versions are available and prompt for update"""
|
"""Checks if newer versions are available and prompt for update"""
|
||||||
|
|
||||||
for torrent, data in list(torrents.items()):
|
for torrent, data in list(torrents.items()):
|
||||||
keys_to_check = {'local-version','remote-version','transmission-id'}
|
keys_to_check = {'local-version', 'remote-version', 'transmission-id'}
|
||||||
if not ( keys_to_check.issubset(data.keys())
|
if not (
|
||||||
and data['local-version'] < data['remote-version']):
|
keys_to_check.issubset(data.keys())
|
||||||
|
and
|
||||||
|
data['local-version'] < data['remote-version']
|
||||||
|
):
|
||||||
del torrents[torrent]
|
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():
|
def prompt_for_update():
|
||||||
@ -125,8 +131,8 @@ def get_cookies_from_pleasuredome():
|
|||||||
|
|
||||||
logging.info('Logging in PleasureDome')
|
logging.info('Logging in PleasureDome')
|
||||||
data = {
|
data = {
|
||||||
'uid':config['pleasuredome-user'],
|
'uid': config['pleasuredome-user'],
|
||||||
'pwd':config['pleasuredome-password']
|
'pwd': config['pleasuredome-password']
|
||||||
}
|
}
|
||||||
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:
|
||||||
@ -139,7 +145,7 @@ def get_cookies_from_pleasuredome():
|
|||||||
r.status_code
|
r.status_code
|
||||||
)
|
)
|
||||||
exit(1)
|
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():
|
def connect_to_transmission():
|
||||||
@ -173,10 +179,16 @@ def update_torrents():
|
|||||||
"""
|
"""
|
||||||
logging.info('Updating torrents')
|
logging.info('Updating torrents')
|
||||||
for torrent in torrents.values():
|
for torrent in torrents.values():
|
||||||
old_name = os.path.join(config['mame-directory'], torrent['local-name'])
|
old_name = os.path.join(
|
||||||
new_name = os.path.join(config['mame-directory'], torrent['remote-name'])
|
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)
|
os.rename(old_name, new_name)
|
||||||
client.torrent.add(
|
client.torrent.add(
|
||||||
filename=torrent['remote-link'],
|
filename=torrent['remote-link'],
|
||||||
@ -194,11 +206,11 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print('PDMameUpdate is about to start')
|
print('PDMameUpdate is about to start')
|
||||||
# Useful if you run this script when your machine boots
|
# 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=''),
|
print('{}\r'.format(i), end=''),
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
re_mame_version = re.compile('MAME 0.(\d+) (.*)')
|
re_mame_version = re.compile(r'MAME 0.(\d+) (.*)')
|
||||||
config = open_config_file()
|
config = open_config_file()
|
||||||
torrents = defaultdict(dict)
|
torrents = defaultdict(dict)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user