Refactor code to improve readability
This commit is contained in:
@ -104,10 +104,10 @@ def fetch_local_torrents():
|
|||||||
directories = os.listdir(config['mame-directory'])
|
directories = os.listdir(config['mame-directory'])
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
for regexp in regexps:
|
for regexp in regexps:
|
||||||
match = regexp.match(directory)
|
match = regexp.search(directory)
|
||||||
if match:
|
if match:
|
||||||
version = match.group('version')
|
version = match.group(0)
|
||||||
name = match.group(0).replace(version, '#')
|
name = regexp.sub('#', directory)
|
||||||
torrents[name]['local-version'] = version
|
torrents[name]['local-version'] = version
|
||||||
torrents[name]['local-name'] = directory
|
torrents[name]['local-name'] = directory
|
||||||
logging.debug('Found the local torrent versions: %s', pformat(torrents))
|
logging.debug('Found the local torrent versions: %s', pformat(torrents))
|
||||||
@ -122,8 +122,8 @@ def fetch_remote_torrents():
|
|||||||
for regexp in regexps:
|
for regexp in regexps:
|
||||||
match = regexp.match(post.title)
|
match = regexp.match(post.title)
|
||||||
if match:
|
if match:
|
||||||
matched_version = match.group('version')
|
matched_version = match.group(0)
|
||||||
matched_torrent = torrents[match.group(0).replace(matched_version, '#')]
|
matched_torrent = regexp.sub('#', post.title)
|
||||||
if matched_version > matched_torrent.get('remote-version', ''):
|
if matched_version > matched_torrent.get('remote-version', ''):
|
||||||
matched_torrent['remote-version'] = matched_version
|
matched_torrent['remote-version'] = matched_version
|
||||||
matched_torrent['remote-link'] = post.link
|
matched_torrent['remote-link'] = post.link
|
||||||
@ -240,9 +240,10 @@ def fetch_transmission_torrents():
|
|||||||
logging.info('Listing Transmission torrents')
|
logging.info('Listing Transmission torrents')
|
||||||
for torrent in client.list().values():
|
for torrent in client.list().values():
|
||||||
for regexp in regexps:
|
for regexp in regexps:
|
||||||
match = regexp.match(torrent['name'])
|
match = regexp.search(torrent['name'])
|
||||||
if match:
|
if match:
|
||||||
torrents[match.group(0).replace(match.group('version'), '#')]['transmission-id'] = torrent['id']
|
name = regexp.sub('#', torrent['name'])
|
||||||
|
torrents[name]['transmission-id'] = torrent['id']
|
||||||
logging.debug('Found the Transmission torrent ids: %s', pformat(torrents))
|
logging.debug('Found the Transmission torrent ids: %s', pformat(torrents))
|
||||||
|
|
||||||
|
|
||||||
@ -328,8 +329,9 @@ if __name__ == '__main__':
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
regexps = [
|
regexps = [
|
||||||
re.compile(r'(?:HB)?MAME (?P<version>[\d.]+) .*'),
|
re.compile(r'(?<=MAME )[\d.]+'),
|
||||||
re.compile(r'No-Intro \((?P<version>[\d-]+)\) .*')
|
re.compile(r'(?<=HBMAME )[\d.]+'),
|
||||||
|
re.compile(r'(?<=No-Intro \()[\d-]+')
|
||||||
]
|
]
|
||||||
config = open_config_file()
|
config = open_config_file()
|
||||||
torrents = defaultdict(dict)
|
torrents = defaultdict(dict)
|
||||||
|
Reference in New Issue
Block a user