Merge pull request #25 from tildetown/mh-single-user-social
Create function to post about adding a single userpull/27/head
commit
1b607fc9ed
|
@ -17,7 +17,7 @@ tw_auth.set_access_token(settings.TWITTER_TOKEN, settings.TWITTER_TOKEN_SECRET)
|
||||||
twitter = tweepy.API(tw_auth)
|
twitter = tweepy.API(tw_auth)
|
||||||
|
|
||||||
def split_posts_by_length(text, length):
|
def split_posts_by_length(text, length):
|
||||||
pattern = '.{,%d}(?:\s|$)' % length - 1
|
pattern = '.{,%d}(?:\s|$)' % (length - 1)
|
||||||
chunks = re.findall(pattern, text)
|
chunks = re.findall(pattern, text)
|
||||||
posts = []
|
posts = []
|
||||||
post = ''
|
post = ''
|
||||||
|
@ -43,7 +43,7 @@ def post_to_mastodon(message):
|
||||||
|
|
||||||
|
|
||||||
def post_to_twitter(message):
|
def post_to_twitter(message):
|
||||||
posts = split_posts_by_length(message, 140)
|
posts = split_posts_by_length(message, 280)
|
||||||
status_info = None
|
status_info = None
|
||||||
for post in posts:
|
for post in posts:
|
||||||
if status_info:
|
if status_info:
|
||||||
|
@ -64,3 +64,8 @@ def post_users_to_social(qs):
|
||||||
post_to_mastodon(message)
|
post_to_mastodon(message)
|
||||||
post_to_twitter(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)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ from django.db.models import TextField, BooleanField, CharField, ForeignKey
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
|
|
||||||
from common.mailing import send_email
|
from common.mailing import send_email
|
||||||
|
from common.social import post_single_user_social
|
||||||
from help.models import Ticket
|
from help.models import Ticket
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -154,6 +155,7 @@ def on_townie_pre_save(sender, instance, **kwargs):
|
||||||
if not existing[0].reviewed and instance.reviewed == True:
|
if not existing[0].reviewed and instance.reviewed == True:
|
||||||
instance.create_on_disk()
|
instance.create_on_disk()
|
||||||
instance.send_welcome_email()
|
instance.send_welcome_email()
|
||||||
|
post_single_user_social(instance.username)
|
||||||
|
|
||||||
def _guarded_run(cmd_args, **run_args):
|
def _guarded_run(cmd_args, **run_args):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue