credential helper function + cleaning/typo fixes

This commit is contained in:
Alex Orid 2021-05-03 04:09:53 -04:00
parent bb002c7b0c
commit bc6a8c8bf7
3 changed files with 24 additions and 48 deletions

View File

@ -1,46 +0,0 @@
from main import user_module_init
import config as config
import db
import user_module
import commands.loader as command_loader
from commands.command_base import AbstractCommand
import credentials
class Command_Management_Module():
def __init__(self):
super().__init__()
self.dbCredential: credentials.DB_Credential
def main_test(self):
print("[TEST Module]> test")
tempModule = user_module.User_Module()
#tempModule.commands = command_loader.load_commands_new(AbstractCommand.CommandType.Praxis)
print(self.getCommandsList(tempModule.commands))
def getCommandsList(self, targetModuleCommands):
print(type(targetModuleCommands))
commandsList = "\n"
for cmd in targetModuleCommands:
targetCommand = targetModuleCommands[cmd]
print(targetCommand.command)
print(targetCommand.isCommandEnabled)
return commandsList
def getUserPermission():
pass
if __name__ == "__main__":
testModule = Command_Management_Module()
credentials_manager = credentials.Credentials_Module()
credentials_manager.load_credentials()
testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
testModule.main_test()

View File

@ -77,7 +77,7 @@ class Cooldown_Module:
targetCD.actionList.append(newAction)
if __name__ == "__main__":
testCD = Cooldowns_Module()
testCD = Cooldown_Module()
cdName = "test"
testCD.setupCooldown(cdName, 20, 2)

View File

@ -10,6 +10,9 @@ from twitchAPI.oauth import UserAuthenticator
from pprint import pprint
from uuid import UUID
import json
import utilities_script as utility
import os
class Twitch_Credential_Maker():
def __init__(self):
@ -32,6 +35,21 @@ class Twitch_Credential_Maker():
print("")
return token, refresh_token
def updateCredentialsFile(self, token, refreshToken):
dir = utility.get_dir("credentials")
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
relative_path = "credentials/twitch.json"
real_file_path = os.path.join(script_dir, relative_path)
with open(real_file_path, 'r') as cred_r:
data = json.load(cred_r)
data['pubsub_AccessToken'] = token
data['pubsub_RefreshToken'] = refreshToken
os.remove(real_file_path)
with open(real_file_path, 'w') as cred_w:
json.dump(data, cred_w, indent=2)
@ -44,6 +62,10 @@ if __name__ == "__main__":
testModule.twitch = Twitch(testModule.credential.pubsub_client_id, testModule.credential.pubsub_secret)
#pprint(testModule.twitch.get_users(logins=['thecuriousnerd']))
testModule.get_tokens()
token, refreshToken = testModule.get_tokens()
print("Update credentials file? (y/n)")
response = input()
if "y" in response.lower():
testModule.updateCredentialsFile(token, refreshToken)
print("Ready to close")
input()