From 994747c0b41b904081826394bd688ac4b1127a2a Mon Sep 17 00:00:00 2001 From: Sebastian Robinson Date: Mon, 16 Mar 2020 00:44:30 +0000 Subject: [PATCH 1/3] Add --keep argument to download torrent files to local directory --- PDMameUpdate.py | 12 ++++++++++++ README.md | 7 ++++--- config.template.json | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index 415a992..1cc25cd 100755 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -224,6 +224,10 @@ def update_torrents(): config['mame-directory'], torrent['remote-name'] ) + new_torrent = os.path.join( + config['torrent-directory'], + torrent['remote-name']+'.torrent' + ) client.torrent.remove(torrent['transmission-id']) os.rename(old_name, new_name) @@ -234,6 +238,9 @@ def update_torrents(): paused=False ) + if args.keep: + t = requests.get(torrent['remote-link'], verify=False) + open(new_torrent, 'wb').write(t.content) if __name__ == '__main__': logging.basicConfig( @@ -253,6 +260,11 @@ if __name__ == '__main__': action='store_true', help='Display debugging messages' ) + parser.add_argument( + '-k', '--keep', + action='store_true', + help='Keep torrent files localy' + ) parser.add_argument( '-c', '--countdown', action='store_true', diff --git a/README.md b/README.md index 2cf3ae5..436ca6b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PDMameUpdate -Checks available MAME Torrents on PleasureDome -and updates the local versions if more recent +Checks available MAME Torrents on PleasureDome +and updates the local versions if more recent versions are detected ![Sample output](https://djib.fr/djib/PDMameUpdate/raw/branch/master/screenshot.png) @@ -20,7 +20,7 @@ pipenv run python3 PDMameUpdate.py ## Usage ```shell -usage: PDMameUpdate.py [-h] [-l] [-d] [-c] +usage: PDMameUpdate.py [-h] [-l] [-d] [-k] [-c] Update PleasureDome MAME Torrents @@ -28,5 +28,6 @@ optional arguments: -h, --help show this help message and exit -l, --log Display more log messages -d, --debug Display debugging messages + -k, --keep Keep torrent files localy -c, --countdown Start with a 5 second countdown ``` diff --git a/config.template.json b/config.template.json index b02c56d..6198946 100644 --- a/config.template.json +++ b/config.template.json @@ -1,8 +1,9 @@ { - "mame-directory":"/path/to/your/locol/mame/torrent/target/folders", + "mame-directory":"/path/to/your/local/mame/files/target/folder", + "torrent-directory":"/path/to/your/local/mame/torrent/target/folder", "transmission-user":"user", "transmission-password":"pass", "pleasuredome-user":"user", "pleasuredome-password":"pass", "transmission-port":8080 -} \ No newline at end of file +} From e1c7c9dde5b4cbae29d64e45026c6e912229cee7 Mon Sep 17 00:00:00 2001 From: Sebastian Robinson Date: Mon, 16 Mar 2020 20:52:25 +0000 Subject: [PATCH 2/3] search for config file --- PDMameUpdate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index 1cc25cd..e7ab545 100755 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -48,6 +48,7 @@ import os import re import requests import time +import pathlib from clutch.core import Client from tabulate import tabulate from collections import defaultdict @@ -58,8 +59,16 @@ from urllib.parse import quote def open_config_file(): """Reads configuration from config.json file""" - logging.info('Opening config file: config.json') - with open('config.json') as config_file: + for loc in os.environ.get("PDMAMEUPDATE_CONF"), "/etc", os.path.expanduser("~"), os.curdir: + if loc is not None: + config_path = loc + '/config.json' + if pathlib.Path(config_path).is_file(): + config_file_loc = config_path + break + + logging.info('Opening config file: '+config_file_loc) + config_file = None; + with open(config_file_loc, 'r') as config_file: config = json.load(config_file) return config From f6313968096397b3fbdc9ae0740fbeb7acc329f7 Mon Sep 17 00:00:00 2001 From: Sebastian Robinson Date: Tue, 31 Mar 2020 19:52:21 +0100 Subject: [PATCH 3/3] Change config file name --- PDMameUpdate.py | 6 +++--- config.template.json => PDMameUpdate.template.json | 0 README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename config.template.json => PDMameUpdate.template.json (100%) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index e7ab545..c2310e5 100755 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -20,7 +20,7 @@ Work in progress… Requirements: * Transmission for Bitorrent * A PleasureDome account - * A proper config.json file (see config.template.json) + * A proper PDMameUpdate.json file (see PDMameUpdate.template.json) * Python3 with the libraries below - feedparser - transmission-clutch @@ -57,11 +57,11 @@ from urllib.parse import quote def open_config_file(): - """Reads configuration from config.json file""" + """Reads configuration from PDMameUpdate.json file""" for loc in os.environ.get("PDMAMEUPDATE_CONF"), "/etc", os.path.expanduser("~"), os.curdir: if loc is not None: - config_path = loc + '/config.json' + config_path = loc + '/PDMameUpdate.json' if pathlib.Path(config_path).is_file(): config_file_loc = config_path break diff --git a/config.template.json b/PDMameUpdate.template.json similarity index 100% rename from config.template.json rename to PDMameUpdate.template.json diff --git a/README.md b/README.md index 436ca6b..6277ea2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ versions are detected ![Sample output](https://djib.fr/djib/PDMameUpdate/raw/branch/master/screenshot.png) ## Installation -You need to rename `config.template.json` to `config.json` and modify it with the proper information. +You need to rename `PDMameUpdate.template.json` to `PDMameUpdate.json` and modify it with the proper information. You should have Python3 and a few libraries installed (see header in source code).