43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import os
|
|
from configparser import ConfigParser
|
|
from xdg.BaseDirectory import xdg_data_home, xdg_config_home
|
|
|
|
|
|
class Config:
|
|
def __init__(self):
|
|
self.config = ConfigParser()
|
|
self.config_dir = os.path.join(xdg_config_home, 'lonestar.fm')
|
|
self.config_file = os.path.join(self.config_dir, 'scrobbler.ini')
|
|
self.check_config_dir_exists()
|
|
|
|
def check_config_dir_exists(self):
|
|
if os.path.exists(self.config_dir):
|
|
return True
|
|
else:
|
|
os.makedirs(self.config_dir)
|
|
return True
|
|
|
|
def check_config_file_exists(self):
|
|
if os.path.exists(self.config_file):
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def create_config_file(self, api_key, api_secret, username, password):
|
|
self.config['API'] = {
|
|
'api_key': api_key,
|
|
'api_secret': api_secret,
|
|
'username': username,
|
|
'password': password
|
|
}
|
|
with open(self.config_file, 'w') as configfile:
|
|
self.config.write(configfile)
|
|
|
|
def get_config_values(self):
|
|
self.config.read(self.config_file)
|
|
api_key = self.config['API']['api_key']
|
|
api_secret = self.config['API']['api_secret']
|
|
username = self.config['API']['username']
|
|
password = self.config['API']['password']
|
|
return api_key, api_secret, username, password
|