Exemplo n.º 1
0
def get_client():
    login = os.environ.get('ETNA_USER')
    password = os.environ.get('ETNA_PASS')
    etna = EtnaWrapper(login=login, password=password)
    infos = etna.get_infos()
    logger.info(
        'logged as {} at {}'.format(infos['login'], infos['login_date'])
    )
    return etna
Exemplo n.º 2
0
def setup_api():
    ini = configparser.ConfigParser()
    ini.read('config.ini')

    etna_id = ini['ETNA']['etna_id']
    etna_passwd = ini['ETNA']['etna_password']
    creds = EtnaWrapper(login=etna_id, password=etna_passwd)

    return creds
Exemplo n.º 3
0
 def authenticate(self, request, username=None, password=None):
     """Make a request to the API and check for the return code."""
     client = EtnaWrapper(login=username, password=password)
     try:
         infos = client.get_user_info()
         # TODO: Use proper exception handling
     except Exception as err:
         print(f'{username}: {err}')
         return None
     username = infos['login']
     try:
         user = User.objects.get(username=username)
     except User.DoesNotExist:  # pylint: disable=no-member
         # Create a new user. There's no need to set a password
         # because only the password from settings.py is checked.
         user = User(pk=infos['id'],
                     username=username,
                     email=infos['email'])
         user.is_staff = True
         user.is_superuser = True
         user.save()
     return user
Exemplo n.º 4
0
def get_wrapper():
    login = os.environ.get('ETNA_USER')
    password = os.environ.get('ETNA_PASS')
    wrapper = EtnaWrapper(login, password)
    return wrapper
Exemplo n.º 5
0
Arquivo: shout.py Projeto: tbobm/shout
def get_wrapper():
    """Instantiate the APIWrapper."""
    # TODO: Config-based credential management ?
    login = os.environ.get("ETNA_USER")
    return EtnaWrapper(login=login, password=os.environ.get("ETNA_PASS"))
Exemplo n.º 6
0
		count += 1

	if count != 0 :
		with open(message_id, 'w') as f:
			f.write(str(data[0]["id"]))
	return count

if __name__ == '__main__':
	ini = configparser.ConfigParser()
	ini.read('config.ini')

	etna_id = ini['ETNA']['etna_id']
	etna_passwd = ini['ETNA']['etna_password']

	wrapper = EtnaWrapper(login=etna_id, password=etna_passwd)

	# grab notifications and write to file	.json
	with open("file.json", 'w') as file :
		file.write(json.dumps(wrapper.get_notifications(), indent=4))

	with open("file.json", 'r') as f:
		json_data = json.load(f)

		cnt = grab_latests_messages(json_data)

	# log part
	now = str(datetime.datetime.now())
	now = now.split('.')[0]

	with open("twitna.log", 'a') as log: