# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from getpass import getpass
from os import getcwd
from mastodon import Mastodon
from mastodon.Mastodon import MastodonIllegalArgumentError
import sys
print('\nThis app generates Mastodon app credentials needed by Feed2toot.\nfeed2toot_clientcred.txt and feed2toot_usercred.txt will be written in the current dir {cwd}.\nOne connection is initiated to create the app.\nYour password is *not* stored.\n'.format(cwd=getcwd()))
# get the instance
instance = input('Mastodon instance url (defaults to https://mastodon.social):')
if not instance:
instance = 'https://mastodon.social'
elif not instance.startswith('http'):
instance = ''.join(['https://', instance])
# get the username
userok = False
while not userok:
user = input('Mastodon login:')
if not user:
print('Your Mastodon username can not be empty')
userok = False
elif '@' not in user or '.' not in user:
print('Your Mastodon username should be an email')