def createAccount(username, isNsfw, subreddit): mastodon = Mastodon(client_id=settings.MASTODON['CLIENT_ID'], client_secret=settings.MASTODON['CLIENT_SECRET'], api_base_url=settings.MASTODON['BASE_URL']) email = "r_{}_bot@{}".format(username.lower(), settings.MASTODON['EMAIL_DOMAIN']), account = Account(username=username, email=email, password=settings.MASTODON['DEFAULT_PASSWORD'], subreddit=subreddit) account.save() try: mastodon.create_account(account.username, account.password, account.email, agreement=True, locale='en', scopes=['read', 'write'], to_file=path.join( "tokens", "{}.token".format(account.username))) baseUrl = settings.MASTODON['BASE_URL'].replace("https://", "").replace( "http://", "") postBody = "@{}@{} is now available to follow!".format( account.username, baseUrl) postToMainAccount(postBody, isNsfw) mastodon = Mastodon(client_id=settings.MASTODON['CLIENT_ID'], client_secret=settings.MASTODON['CLIENT_SECRET'], api_base_url=settings.MASTODON['BASE_URL']) mastodon.account_follow(account.username) except Exception as e: # Check if user already exists with the default password sessionHandle = _getMastodonHandle(account) statuses = sessionHandle.account_statuses( sessionHandle.account_verify_credentials()['id'], limit=1) if len(statuses) > 0: status = statuses[0] for post in subreddit.post_set.all().order_by('created'): if post.reddit_url in status.content: account.lastInserted = post.id account.save() break return account
def register(locale, instance): response.headers['Access-Control-Allow-Origin'] = '*' response.content_type = "application/json" username = request.forms.get("username") # pylint: disable=no-member email = request.forms.get("email") # pylint: disable=no-member password = request.forms.get("password") # pylint: disable=no-member agreement = True if debug: appname = "Nordcast (debug)" else: appname = "Nordcast" if not os.path.exists('clientcred.' + instance + '.secret'): Mastodon.create_app(appname, api_base_url='https://' + instance, to_file='clientcred.' + instance + '.secret') mastodon = Mastodon(client_id='clientcred.' + instance + '.secret', api_base_url='https://' + instance) mastodon.create_account(username, password, email, agreement, locale=locale) return "{\"action\": \"success\"}"
def test_app_account_create(): # This leaves behind stuff on the test server, which is unfortunate, but eh. suffix = str(time.time()).replace(".", "")[-5:] test_app = test_app = Mastodon.create_app( "mastodon.py generated test app", api_base_url="http://*****:*****@localhost" + suffix, agreement=True) assert test_token