2017-11-07 20:50:30 +00:00
|
|
|
from mastodon import Mastodon
|
|
|
|
import tweepy
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
mastodon = Mastodon(
|
|
|
|
client_id=settings.MASTO_CLIENT_ID,
|
|
|
|
client_secret=settings.MASTO_CLIENT_SECRET,
|
|
|
|
access_token=settings.MASTO_ACCESS_TOKEN,
|
|
|
|
api_base_url=settings.MASTO_BASE_URL
|
|
|
|
)
|
|
|
|
|
|
|
|
tw_auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
|
2017-11-08 00:11:22 +00:00
|
|
|
tw_auth.set_access_token(settings.TWITTER_TOKEN, settings.TWITTER_TOKEN_SECRET)
|
2017-11-07 20:50:30 +00:00
|
|
|
twitter = tweepy.API(tw_auth)
|
|
|
|
|
2017-11-08 00:11:22 +00:00
|
|
|
def post_to_mastodon(qs):
|
|
|
|
posts = []
|
|
|
|
if len(qs) > 1:
|
|
|
|
welcome = 'Welcome new user '
|
|
|
|
else:
|
|
|
|
welcome = 'Welcome new users!!!\n\n'
|
|
|
|
message = welcome
|
2017-11-07 20:50:30 +00:00
|
|
|
for townie in qs:
|
2017-11-08 00:11:22 +00:00
|
|
|
if len(message + townie.username) + 1 > 500:
|
|
|
|
posts.append(message.strip())
|
|
|
|
message = welcome + '~{}\n'.format(townie.username)
|
|
|
|
else:
|
|
|
|
message += '~{}\n'.format(townie.username)
|
|
|
|
posts.append(message.strip())
|
|
|
|
for post in posts:
|
|
|
|
mastodon.post(post)
|
|
|
|
|
|
|
|
def post_to_twitter(qs):
|
|
|
|
posts = []
|
|
|
|
if len(qs) > 1:
|
|
|
|
welcome = 'Welcome new user '
|
2017-11-07 20:50:30 +00:00
|
|
|
else:
|
2017-11-08 00:11:22 +00:00
|
|
|
welcome = 'Welcome new users!!!\n\n'
|
|
|
|
message = welcome
|
|
|
|
for townie in qs:
|
|
|
|
if len(message + townie.username) + 1 > 140:
|
|
|
|
posts.append(message.strip())
|
|
|
|
message = welcome + '~{}\n'.format(townie.username)
|
|
|
|
else:
|
|
|
|
message += '~{}\n'.format(townie.username)
|
2017-11-08 00:15:42 +00:00
|
|
|
posts.append(message.strip())
|
2017-11-08 00:11:22 +00:00
|
|
|
for post in posts:
|
|
|
|
twitter.update_status(post)
|
|
|
|
|
|
|
|
def post_to_social(qs):
|
|
|
|
post_to_twitter(qs)
|
|
|
|
post_to_mastodon(qs)
|
2017-11-07 20:50:30 +00:00
|
|
|
|