From e322f7edf61c287af5bfd14d9c93e92a8b04a0c4 Mon Sep 17 00:00:00 2001 From: Andy Tuba Date: Mon, 25 Jul 2016 21:52:36 -0700 Subject: [PATCH 1/4] Deploy to multiple subreddits If the `subreddit` environment variable is a comma-separated list of subreddits, eg. `pics+funny`, then deploy the stylesheet to both /r/pics and /r/funny. --- deploy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy.py b/deploy.py index ce5ac53..275d3f7 100644 --- a/deploy.py +++ b/deploy.py @@ -80,7 +80,8 @@ def deploy(force=ast.literal_eval(os.getenv('force_deploy', 'False'))): deploy_images(image_diff, r, force) if update_css or force: with open(stylesheet, 'r') as css: - r.set_stylesheet(os.getenv('subreddit'), css.read()) + for subreddit in os.getenv('subreddit').split('+'): + r.set_stylesheet(subreddit, css.read()) if __name__ == '__main__': deploy() From 7ceb578a58b073a00b6f6192e50803294038dcac Mon Sep 17 00:00:00 2001 From: Andy Tuba Date: Mon, 25 Jul 2016 21:56:11 -0700 Subject: [PATCH 2/4] only read stylesheet file once --- deploy.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deploy.py b/deploy.py index 275d3f7..ff36a5e 100644 --- a/deploy.py +++ b/deploy.py @@ -44,7 +44,7 @@ def open(name, *a, **kw): for image, exists in diff.items(): data = dict(deploy_data) with open(image) as image_file: - if exists: + if exists:' data['image_path'] = image else: data['name'] = os.path.splitext( @@ -79,9 +79,10 @@ def deploy(force=ast.literal_eval(os.getenv('force_deploy', 'False'))): if update_images or force: deploy_images(image_diff, r, force) if update_css or force: - with open(stylesheet, 'r') as css: + with open(stylesheet, 'r') as stylesheet_file: + css = stylesheet_file.read() for subreddit in os.getenv('subreddit').split('+'): - r.set_stylesheet(subreddit, css.read()) + r.set_stylesheet(subreddit, css) if __name__ == '__main__': deploy() From 254f0d8c618bc8aaf96c20fb3cca147669817f5b Mon Sep 17 00:00:00 2001 From: Andy Tuba Date: Mon, 25 Jul 2016 21:56:28 -0700 Subject: [PATCH 3/4] typo --- deploy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.py b/deploy.py index ff36a5e..47dde93 100644 --- a/deploy.py +++ b/deploy.py @@ -44,7 +44,7 @@ def open(name, *a, **kw): for image, exists in diff.items(): data = dict(deploy_data) with open(image) as image_file: - if exists:' + if exists: data['image_path'] = image else: data['name'] = os.path.splitext( From a4607acec31f03a1506af75f9a7f9d06eec30f9b Mon Sep 17 00:00:00 2001 From: Andy Tuba Date: Mon, 25 Jul 2016 21:57:00 -0700 Subject: [PATCH 4/4] deploy images to multiple subreddits --- deploy.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/deploy.py b/deploy.py index 47dde93..6e9bdda 100644 --- a/deploy.py +++ b/deploy.py @@ -40,20 +40,21 @@ def open(name, *a, **kw): diff.update({b: False for b in remove}) else: diff = {f: os.path.isfile(f) for f in diff} - deploy_data = {'subreddit': os.getenv('subreddit')} - for image, exists in diff.items(): - data = dict(deploy_data) - with open(image) as image_file: - if exists: - data['image_path'] = image - else: - data['name'] = os.path.splitext( - os.path.basename(image_file.name) - )[0] - getattr( - reddit, - "{0}_image".format("upload" if exists else "delete") - )(**data) + for subreddit in os.getenv('subreddit').split('+'): + deploy_data = {'subreddit': subreddit} + for image, exists in diff.items(): + data = dict(deploy_data) + with open(image) as image_file: + if exists: + data['image_path'] = image + else: + data['name'] = os.path.splitext( + os.path.basename(image_file.name) + )[0] + getattr( + reddit, + "{0}_image".format("upload" if exists else "delete") + )(**data) def deploy(force=ast.literal_eval(os.getenv('force_deploy', 'False'))):