From 9c88b90639d3148f30ffe094b36cc2ac14a827be Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Thu, 16 Nov 2017 11:14:40 -0800 Subject: [PATCH 1/3] add social posting for adding a single user --- ttadmin/common/social.py | 5 +++++ ttadmin/users/models.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ttadmin/common/social.py b/ttadmin/common/social.py index 72966d8..66ea320 100644 --- a/ttadmin/common/social.py +++ b/ttadmin/common/social.py @@ -64,3 +64,8 @@ def post_users_to_social(qs): post_to_mastodon(message) post_to_twitter(message) +def post_single_user_social(username): + message = 'Welcome new user ~{}!'.format(username) + post_to_mastodon(message) + post_to_twitter(message) + diff --git a/ttadmin/users/models.py b/ttadmin/users/models.py index 213a95b..5538e84 100644 --- a/ttadmin/users/models.py +++ b/ttadmin/users/models.py @@ -12,6 +12,7 @@ from django.db.models import TextField, BooleanField, CharField, ForeignKey from django.template.loader import get_template from common.mailing import send_email +from common.social import post_single_user_social from help.models import Ticket logger = logging.getLogger() @@ -154,6 +155,7 @@ def on_townie_pre_save(sender, instance, **kwargs): if not existing[0].reviewed and instance.reviewed == True: instance.create_on_disk() instance.send_welcome_email() + post_single_user_social(instance.username) def _guarded_run(cmd_args, **run_args): try: From 1b67b030120121c77202922d617556323d7ded88 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Thu, 16 Nov 2017 11:17:30 -0800 Subject: [PATCH 2/3] increase twitter length --- ttadmin/common/social.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttadmin/common/social.py b/ttadmin/common/social.py index 66ea320..0406692 100644 --- a/ttadmin/common/social.py +++ b/ttadmin/common/social.py @@ -43,7 +43,7 @@ def post_to_mastodon(message): def post_to_twitter(message): - posts = split_posts_by_length(message, 140) + posts = split_posts_by_length(message, 280) status_info = None for post in posts: if status_info: From 8d92367fe36ddc5d635f55b2419bbf4841fdae8a Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Fri, 17 Nov 2017 11:34:01 -0800 Subject: [PATCH 3/3] fix order of operations in split_posts_by_length --- ttadmin/common/social.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttadmin/common/social.py b/ttadmin/common/social.py index 0406692..cdad0f4 100644 --- a/ttadmin/common/social.py +++ b/ttadmin/common/social.py @@ -17,7 +17,7 @@ tw_auth.set_access_token(settings.TWITTER_TOKEN, settings.TWITTER_TOKEN_SECRET) twitter = tweepy.API(tw_auth) def split_posts_by_length(text, length): - pattern = '.{,%d}(?:\s|$)' % length - 1 + pattern = '.{,%d}(?:\s|$)' % (length - 1) chunks = re.findall(pattern, text) posts = [] post = ''