diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd517c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +#Contains secret keys +*.pyc + +credentials.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f91f350 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "reddit"] + path = reddit + url = git@github.com:Reddit-Enhancement-Suite/redditbots diff --git a/aws-cloudflare/aws_s3.py b/aws-cloudflare/aws_s3.py new file mode 100644 index 0000000..e0d334d --- /dev/null +++ b/aws-cloudflare/aws_s3.py @@ -0,0 +1,13 @@ +import os +from tinys3 import Connection +from tinys3.request_factory import S3Request + +access_key = os.environ.get('AWS_ACCESS_KEY_ID') +secret = os.environ.get('AWS_ACCESS_KEY_SECRET') +region = os.environ.get('AWS_REGION') +bucket = os.environ.get('AWS_BUCKET') +if access_key is None or secret is None: + raise Exception('Amazon S3 credentials are not available') + + +conn = Connection(access_key,secret, default_bucket=bucket, tls=True) diff --git a/aws-cloudflare/cloudflare.py b/aws-cloudflare/cloudflare.py new file mode 100644 index 0000000..db8d492 --- /dev/null +++ b/aws-cloudflare/cloudflare.py @@ -0,0 +1,11 @@ +import os +from pyflare import PyflareClient + + +email = os.environ.get('CLOUDFLARE_EMAIL') +api_key = os.environ.get('CLOUDFLARE_API_KEY') +if email is None or api_key is None: + raise Exception('CloudFlare credentials are not available') + + +client = PyflareClient(email, api_key) diff --git a/aws-cloudflare/pushtohosting.py b/aws-cloudflare/pushtohosting.py new file mode 100644 index 0000000..7aee313 --- /dev/null +++ b/aws-cloudflare/pushtohosting.py @@ -0,0 +1,47 @@ +import argparse +import tinys3 +from cloudflare import client as cf_client +from aws_s3 import conn as aws_client +import os +import logging + +domain = 'cdn.redditenhancementsuite.com' +base_url = 'https://{domain}/{filename}' + +logging.basicConfig(level=logging.DEBUG) + +class AmazonS3_Cloudflare_Pusher(object): + def __init__(self, filenames): + super(self.__class__, self).__init__() + if isinstance(filenames, basestring): + self.filenames = [ filenames ] + else: + self.filenames = filenames + + def main(self): + + for filename in self.filenames: + self.push(filename) + + def push(self, filename): + with open(filename,'rb') as f: + logging.debug("{}:\n{}".format(filename, f)) + logging.info('Uploading {} to AWS'.format(filename)) + aws_client.upload(os.path.basename(filename),f) + url = base_url.format(domain=domain, filename=filename) + logging.info('Purging {} on Cloudflare'.format(filename)) + #cf_response = cf_client.zone_file_purge(z=domain, url=url) # Todo: catch ratelimit exception and wait + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("src_path", metavar="path", type=str, + help="Path to file") + + args = parser.parse_args() + filename = args.src_path + + logging.debug('Pushing to hosting: {}'.format(filename)) + bot = AmazonS3_Cloudflare_Pusher(filename) + bot.main() + diff --git a/RESUpdates.css b/css/RESUpdates.css similarity index 97% rename from RESUpdates.css rename to css/RESUpdates.css index a5de332..3d4d977 100644 --- a/RESUpdates.css +++ b/css/RESUpdates.css @@ -3,14 +3,14 @@ body.front-page.res-hide-tagline-frontpage .tagline { display: none; } .res-nightmode:not(.res-nightMode-coloredLinks) .thing .title { color: hsl(0,0%,87%); } -.res-nightmode:not(.res-nightMode-coloredLinks) .thing:not(.stickied) .title:visited, -.res-nightmode:not(.res-nightMode-coloredLinks) .thing.visited:not(.stickied) .title, -.res-nightmode:not(.res-nightMode-coloredLinks).combined-search-page .search-result a:visited, +.res-nightmode:not(.res-nightMode-coloredLinks) .thing:not(.stickied) .title:visited, +.res-nightmode:not(.res-nightMode-coloredLinks) .thing.visited:not(.stickied) .title, +.res-nightmode:not(.res-nightMode-coloredLinks).combined-search-page .search-result a:visited, .res-nightmode:not(.res-nightMode-coloredLinks).combined-search-page .search-result a:visited > mark { color: hsl(0,0%,65%); } -.new-comment .usertext-body { margin: 0; } +.res-v4-6-0 .new-comment .usertext-body { margin: 0; } .res-neverEndingReddit-hideFloatingPauseButton #NREPause { display: none; } @@ -37,7 +37,7 @@ res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #sr-header-area, .res-nig background-color: white; border: 1px solid rgb(160, 160, 160); border-bottom: 1px solid white; -} +} .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsEditContainer, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsSort, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsRight, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsLeft, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsAdd, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsTrash { background: rgb(68, 68, 68) !important; @@ -53,7 +53,7 @@ res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #sr-header-area, .res-nig } .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .thing:nth-of-type(4n+1) { - background: rgb(24, 24, 24); + background: rgb(24, 24, 24); } .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .midcol .score, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .moduleButton:not(.enabled) { @@ -69,8 +69,8 @@ res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #sr-header-area, .res-nig } .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .content { - background: rgb(17, 17, 17); - border-color: rgb(17, 17, 17); + background: rgb(17, 17, 17); + border-color: rgb(17, 17, 17); } .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .link .rank { @@ -101,9 +101,9 @@ res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #sr-header-area, .res-nig background-color: rgb(187, 187, 187); color: rgb(0, 0, 0); padding: 1px; -} +} -.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .titlebox form.toggle, +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .titlebox form.toggle, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .leavemoderator { background: #262626 none no-repeat scroll center left !important; } diff --git a/css/RESUpdatesTest.css b/css/RESUpdatesTest.css new file mode 100644 index 0000000..1c94d4d --- /dev/null +++ b/css/RESUpdatesTest.css @@ -0,0 +1,208 @@ +body.front-page.res-hide-tagline-frontpage .tagline { display: none; } + +.res-nightmode:not(.res-nightMode-coloredLinks) .thing .title { + color: hsl(0,0%,87%); +} +.res-nightmode:not(.res-nightMode-coloredLinks) .thing:not(.stickied) .title:visited, +.res-nightmode:not(.res-nightMode-coloredLinks) .thing.visited:not(.stickied) .title, +.res-nightmode:not(.res-nightMode-coloredLinks).combined-search-page .search-result a:visited, +.res-nightmode:not(.res-nightMode-coloredLinks).combined-search-page .search-result a:visited > mark { + color: hsl(0,0%,65%); +} + +.new-comment .usertext-body { margin: 0; } + +.res-neverEndingReddit-hideFloatingPauseButton #NREPause { display: none; } + + + +/* HEADER */ + +res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #sr-header-area, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #sr-more-link { + background-color: rgb(68, 68, 68) !important; + color: rgb(222, 222, 222) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #RESSubredditGroupDropdown a, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .RESNotificationContent, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .RESNotificationFooter, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .sr-bar a { + color: rgb(222, 222, 222) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke #header, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .liveupdate-home .content { + background-color: rgb(105, 105, 105); + border-bottom: 1px solid rgb(160, 160, 160) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .tabmenu li.selected a { + color: orangered; + background-color: white; + border: 1px solid rgb(160, 160, 160); + border-bottom: 1px solid white; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsEditContainer, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsSort, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsRight, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsLeft, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsAdd, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke div#RESShortcutsTrash { + background: rgb(68, 68, 68) !important; + color: rgb(140, 179, 217) !important; +} + +/* FRONTPAGE */ + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .thing { + padding: 7px; + margin: 0; + background-color: #222; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .thing:nth-of-type(4n+1) { + background: rgb(24, 24, 24); +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .midcol .score, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .moduleButton:not(.enabled) { + color: #c6c6c6 !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .rank .star, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .link .score.likes, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .linkcompressed .score.likes { + color: rgb(255, 69, 0) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .rank .star, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .link .score.dislikes, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .linkcompressed .score.dislikes { + color: rgb(140, 179, 217) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .content { + background: rgb(17, 17, 17); + border-color: rgb(17, 17, 17); +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .link .rank { + color: #c6c6c6 !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .domain a { + color: rgb(173, 216, 230) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .subreddit { + color: rgba(20, 150, 220, 0.8) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .author { + color: rgba(20, 150, 220, 0.8) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .live-timestamp { + color: #B3B375 !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .RES-keyNav-activeElement > .tagline, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .RES-keyNav-activeElement .md-container > .md, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .RES-keyNav-activeElement .md-container > .md p { + color: rgb(187, 187, 187) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .flair, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .linkflairlabel { + background-color: rgb(187, 187, 187); + color: rgb(0, 0, 0); + padding: 1px; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .titlebox form.toggle, +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .leavemoderator { + background: #262626 none no-repeat scroll center left !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke:not(.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke-coloredLinks) .thing:not(.stickied) .title:visited, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke:not(.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke-coloredLinks) .thing.visited:not(.stickied) .title, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke:not(.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke-coloredLinks).combined-search-page .search-result a:visited, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke:not(.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke-coloredLinks).combined-search-page .search-result a:visited>mark { + color: rgb(120, 120, 120); +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .md, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .content .sitetable .thing .md, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .RES-keyNav-activeElement .md-container > .md p { + color: rgb(222, 222, 222) !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .entry .buttons li a { + color: rgb(150, 150, 150) !important; +} + +/* BUTTONS */ + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .thing .expando-button, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .thing .expando-button:hover { + background-image: url(%%buttons-nightmodeClassic-u-RunTillYouPuke%%); + background-color: transparent; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video-muted.collapsed { + background-position: 0px -384px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video-muted.collapsed:hover { + background-position: 0px -408px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video-muted.expanded { + background-position: 0px -432px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video-muted.expanded:hover { + background-position: 0px -456px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.selftext.collapsed { + background-position: 0px -96px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.selftext.collapsed:hover{ + background-position: 0px -120px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.selftext.expanded { + background-position: 0px -144px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.selftext.expanded:hover { + background-position: 0px -168px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.image.gallery.collapsed { + background-position: 0px -288px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.image.gallery.collapsed:hover { + background-position: 0px -312px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.image.gallery.expanded { + background-position: 0px -336px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.image.gallery.expanded:hover { + background-position: 0px -360px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video.collapsed { + background-position: 0px -192px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video.collapsed:hover { + background-position: 0px -216px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video.expanded { + background-position: 0px -240px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .expando-button.video.expanded:hover { + background-position: 0px -264px !important; +} + +/* COMMENTS */ + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .flair, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke .linkflairlabel { + padding: 0px !important; +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment .comment .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment .comment .comment .comment .comment .comment { + background-color: rgb(24, 24, 24) !important; + +} + +.res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment .comment .comment .comment .comment, .res-nightmode.res-stylesheet-theme-nightModeClassic-u-RunTillYouPuke.res-commentBoxes .comment .comment .comment .comment .comment .comment .comment .comment .comment .comment { + background-color: rgb(34, 34, 34) !important; +} + diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..70a074b --- /dev/null +++ b/deploy.sh @@ -0,0 +1,38 @@ +CSS_FILE=${1:-'../css/RESUpdatesTest.css'} +echo $CSS_FILE + +set -e + +source credentials.sh + +#git pull + +if [ $(basename $(pwd)) == 'reddit' ]; then + pushd .. +else + if [ $(basename $(pwd)) == 'aws-cloudflare' ]; then + pushd .. + fi +fi + + +pushd aws-cloudflare +source ../setup-virtualenv.sh +source bin/activate +export PYTHONPATH=$(pwd):$PYTHONPATH +FILE=$CSS_FILE +python pushtohosting.py $FILE +popd + + + + +pushd reddit +source ../setup-virtualenv.sh +source bin/activate +export PYTHONPATH=$(pwd):$PYTHONPATH +FILE=$CSS_FILE +python updatesubreddit/stylesheets.py $FILE +popd + +popd #Back to original folder diff --git a/reddit b/reddit new file mode 160000 index 0000000..90f8621 --- /dev/null +++ b/reddit @@ -0,0 +1 @@ +Subproject commit 90f862173f63c0c32d78c8f2bb2c0e452d6ad159 diff --git a/setup-virtualenv.sh b/setup-virtualenv.sh new file mode 100644 index 0000000..e23abdc --- /dev/null +++ b/setup-virtualenv.sh @@ -0,0 +1,5 @@ +if [ ! -d bin ]; then + virtualenv . + source bin/activate + pip install -r requirements.txt +fi