element_music_bot

An element chatbot written in Python.
Log | Files | Refs | README

lastfm_init.py (804B)


      1 import os
      2 import sys
      3 import configparser
      4 import pylast
      5 
      6 config = configparser.ConfigParser()
      7 config.read('config.ini')
      8 
      9 credentials = config['lastfm']
     10 user = credentials['username']
     11 passw = credentials['password']
     12 api_key = credentials['api']
     13 api_secret = credentials['api_secret']
     14 
     15 try:
     16     API_KEY = os.environ["LASTFM_API_KEY"]
     17     API_SECRET = os.environ["LASTFM_API_SECRET"]
     18 except KeyError:
     19     API_KEY = api_key
     20     API_SECRET = api_secret
     21 
     22 try:
     23     lastfm_username = os.environ["LASTFM_USERNAME"]
     24     lastfm_password_hash = os.environ["LASTFM_PASSWORD_HASH"]
     25 except KeyError:
     26     lastfm_username = user
     27     lastfm_password_hash = passw
     28 
     29 lastfm_network = pylast.LastFMNetwork(
     30     api_key=API_KEY,
     31     api_secret=API_SECRET,
     32     username=lastfm_username,
     33     password_hash=lastfm_password_hash,
     34 )