From 0bd20e4d631edc113d39cc09697ec5bce6540caf Mon Sep 17 00:00:00 2001 From: djib Date: Thu, 5 Sep 2019 23:21:43 +0200 Subject: [PATCH] List possible updates and prompt if the user wants to update --- PDMameUpdate.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index 09ad5c7..40ca53b 100644 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -32,23 +32,34 @@ if __name__ == '__main__': logging.info('Fetching current MAME versions') files = os.listdir(config['mame_directory']) - torrent_versions = {} + local_torrents = {} for file in files: match = re_mame_version.match(file) if match: - torrent_versions[match[2]] = match[1] - logging.info('Found the following Torrent version on disk: %s', torrent_versions) + local_torrents[match[2]] = int(match[1]) + logging.info('Found the following Torrent version on disk: %s', local_torrents) logging.info('Opening PleasureDome RSS feed') d = feedparser.parse('http://www.pleasuredome.org.uk/rss.xml') + remote_torrents = {} for post in d.entries: match = re_mame_version.match(post.title) if match: - print('Torrent {} is available with version {}.'.format(match[2], match[1])) - if match[2] in torrent_versions: - print('You have version {}'.format(torrent_versions[match[2]])) - - # TODO: use user input to decide whether the torrent should be updated + remote_torrents[match[2]] = int(match[1]) + logging.info('Found the following Torrent version on PleasureDome: %s', remote_torrents) + + for torrent, version in local_torrents.items(): + if torrent in remote_torrents: + if version < remote_torrents[torrent]: + print('Torrent {}: {} -> {}'.format(torrent, version, remote_torrents[torrent])) + + print('Should I update the torrents listed above? (y/N)') + answer = input() + if answer.lower() == 'y': + logging.info('Updating…') + else: + logging.info('Quitting: user cancelled update.') + # TODO: connect to PleasureDome # TODO: remove local torrent from Transmission # TODO: rename local folder