Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aethese authored Apr 30, 2021
1 parent 3e0c443 commit a6a3b05
Showing 1 changed file with 84 additions and 60 deletions.
144 changes: 84 additions & 60 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
try:
import time, json, requests, webbrowser, os, sys, colorama
import time, json, requests, webbrowser, os, sys, colorama, ctypes
from pypresence import Presence
from colorama import Fore, init
init(autoreset=True)
ctypes.windll.kernel32.SetConsoleTitleW('Switchence')
except Exception as error:
print('Couldn\'t import everything | {}'.format(error))
print(f'Couldn\'t import everything | {error}')

class log:
def error(text: str):
clear()
print(Fore.RED+'\n[Error] {}\nPlease report this error on the Switchence GitHub issue page if this error happens consistently'.format(text))
print(f'{Fore.RED}[Error]{Fore.RESET} {text}\nPlease report this error on the Switchence GitHub issue page if this error happens consistently')
time.sleep(5)
webbrowser.open('https://github.com/Aethese/Switchence/issues/', new=2, autoraise=True)
time.sleep(600)
sys.exit()

def info(text: str):
clear()
print('[Info] {}\nThis program will now close in 1 minute'.format(text))
print(f'{Fore.GREEN}[Info]{Fore.RESET} {text}\nThis program will now close in 1 minute')
time.sleep(60)
sys.exit()

def warning(text: str):
print(Fore.YELLOW+'\n[WARNING] {}\n'.format(text))
print(f'\n{Fore.YELLOW}[WARNING]{Fore.RESET} {text}\n')

def loading(text: str):
print(f'{Fore.LIGHTCYAN_EX}[Loading]{Fore.RESET} {text}')

def clear():
os.system('cls' if os.name =='nt' else 'clear')
Expand All @@ -40,30 +44,36 @@ def clear():
img = ''
fname = ''

log.loading('Checking for config file...')
if os.path.isfile('config.json') == True:
log.loading('Found config file, attempting to read contents...')
try:
with open('config.json', 'r') as jsonfile:
log.loading('Reading config file\'s content...')
jsonFile = json.load(jsonfile)
for details in jsonFile['config']:
sw = details['sw-code']
version = details['version']
updatenotifier = details['update-notifier']
configfname = details['fname']
showbutton = details['show-button']
log.loading('Loaded config settings!')
except Exception as error:
log.error('Couldn\'t load config file (1) | {}'.format(error))
log.error(f'Couldn\'t load config file (1) | {error}')
elif os.path.isfile('config.json') == False:
log.loading('Config file not found, attempting to create one...')
try:
configjson = {}
configjson['config'] = [{
"sw-code": "",
"version": "1.2.0",
"update-notifier": True,
"fname": False,
"show-button": True
'sw-code': '',
'version': '1.3.0',
'update-notifier': True,
'fname': False,
'show-button': True
}]
with open('config.json', 'w') as jsonfile:
json.dump(configjson, jsonfile, indent=4)
log.loading('Config file created!')
with open('config.json', 'r') as jsonfile: # actually get the info lol
jsonFile = json.load(jsonfile)
for details in jsonFile['config']:
Expand All @@ -73,94 +83,95 @@ def clear():
configfname = details['fname']
showbutton = details['show-button']
except Exception as error:
log.error('Couldn\'t load config file (2) | {}'.format(error))
log.error(f'Couldn\'t load config file (2) | {error}')
else:
log.error('Couldn\'t load config settings | {}'.format(error))
log.error('Couldn\'t load config settings')

log.loading('Attempting to load game list...')
try:
gamejson = requests.get('https://raw.githubusercontent.com/Aethese/Switchence/main/games.json') # auto update list :)
gamejsontext = gamejson.text
games = json.loads(gamejsontext)
log.loading('Game list loaded!')
except Exception as error:
log.error('Couldn\'t load game list | {}'.format(error))
log.error(f'Couldn\'t load game list | {error}')

oVersion = games['version']

print('''
.d8888b. d8b 888 888
d88P Y88b Y8P 888 888
Y88b. 888 888
"Y888b. 888 888 888 888 888888 .d8888b 88888b. .d88b. 88888b. .d8888b .d88b.
"Y88b. 888 888 888 888 888 d88P" 888 "88b d8P Y8b 888 "88b d88P" d8P Y8b
"888 888 888 888 888 888 888 888 888 88888888 888 888 888 88888888
Y88b d88P Y88b 888 d88P 888 Y88b. Y88b. 888 888 Y8b. 888 888 Y88b. Y8b.
"Y8888P" "Y8888888P" 888 "Y888 "Y8888P 888 888 "Y8888 888 888 "Y8888P "Y8888
Made by: Aethese#1337
''')

log.loading('Checking file version...')
if version == '' or version == None: # checks your version
log.loading('File version not found, attempting to create...')
try:
with open('config.json', 'r') as jsonfile:
jsonFile = json.load(jsonfile)
for details in jsonFile['config']:
details['version'] = oVersion
with open('config.json', 'w') as jsonfile:
json.dump(jsonFile, jsonfile, indent=4)
log.loading('Succesfully created file version!')
except Exception as error:
log.error('Couldn\'t write to the version file | {}'.format(error))
log.error(f'Couldn\'t write to the version file | {error}')
elif version != oVersion:
if updatenotifier == True:
print(Fore.RED+'Your current version of Switchence (v{}) is not up to date'.format(version))
print(Fore.RED+'You can update Switchence to the current version (v{}) on the official GitHub page or continue using the program as usual'.format(oVersion))
print(Fore.RED+'If you wish to turn off update notifications, type \'update notifier\' in the game selection input\n')
print(f'{Fore.RED}[INFO]{Fore.RESET} Your current version of Switchence {Fore.LIGHTRED_EX}v{version}{Fore.RESET} is not up to date')
print(f'{Fore.RED}[INFO]{Fore.RESET} You can update Switchence to the current version {Fore.LIGHTRED_EX}v{oVersion}{Fore.RESET} on the official GitHub page or continue using the program as usual')
print(f'{Fore.RED}[INFO]{Fore.RESET} If you wish to turn off update notifications, type \'update notifier\' in the game selection input\n')
print(f'{Fore.LIGHTYELLOW_EX}The program will return to normal in 5 seconds.')
time.sleep(2)
webbrowser.open('https://github.com/Aethese/Switchence', new=2, autoraise=True)
time.sleep(3)
else:
pass
time.sleep(5)

log.loading('Attempting to read game list info...')
try:
for details in games['games']:
gamenames.append(details['name'])
gamefnames.append(details['fname'])
log.loading('Succesfully read game list info!')
except Exception as error:
log.error('Couldn\'t load game names from list | {}'.format(error))
log.error(f'Couldn\'t load game names from list | {error}')

log.loading('Attempting to start Rich Presence...')
try:
RPC = Presence(id)
RPC.connect()
log.loading('Succesfully started Rich Presence!')
except Exception as error:
log.error('RPC couldn\'t connect | {}'.format(error))
log.error(f'RPC couldn\'t connect | {error}')

def changePresence(swStatus, pName, pImg, pFname):
start_time = time.time()
local = time.localtime()
string = time.strftime("%H:%M", local)
url = 'https://github.com/Aethese/Switchence/releases'
string = time.strftime('%H:%M', local)
if swStatus == False:
try:
if showbutton == True:
RPC.update(large_image=pImg, large_text=pFname, details=pFname, buttons=[{'label': 'Get this program here', 'url': url}], start=start_time)
print('Set game to {} at {}'.format(pFname, string))
RPC.update(large_image=pImg, large_text=pFname, small_image='switch_png', small_text='Switchence', details=pFname,
buttons=[{'label': 'Get this program here', 'url': 'https://github.com/Aethese/Switchence/releases'}], start=start_time)
print(f'Set game to {pFname} at {string}')
ctypes.windll.kernel32.SetConsoleTitleW(f'Switchence | Playing {pFname}')
elif showbutton == False:
RPC.update(large_image=pImg, large_text=pFname, details=pFname, start=start_time)
print('Set game to {} at {}'.format(pFname, string))
RPC.update(large_image=pImg, large_text=pFname, small_image='switch_png', small_text='Switchence', details=pFname, start=start_time)
print(f'Set game to {pFname} at {string}')
ctypes.windll.kernel32.SetConsoleTitleW(f'Switchence | Playing {pFname}')
else:
log.error('Couldn\'t get button info (1)')
except Exception as error:
log.error('Couldn\'t set RPC(1) to {} | {}'.format(pName, error))
log.error(f'Couldn\'t set RPC(1) to {pName} | {error}')
elif swStatus == True:
try:
if showbutton == True:
RPC.update(large_image=pImg, large_text=pFname, details=pFname, state='SW-{}'.format(sw), buttons=[{'label': 'Get this program here', 'url': url}], start=start_time)
print('Set game to {} at {} with friend code "SW-{}" showing'.format(pFname, string, sw))
RPC.update(large_image=pImg, large_text=pFname, small_image='switch_png', small_text='Switchence', details=pFname,
state=f'SW-{sw}', buttons=[{'label': 'Get this program here', 'url': 'https://github.com/Aethese/Switchence/releases'}], start=start_time)
print(f'Set game to {pFname} at {string} with friend code "SW-{sw}" showing')
ctypes.windll.kernel32.SetConsoleTitleW(f'Switchence | Playing {pFname}')
elif showbutton == False:
RPC.update(large_image=pImg, large_text=pFname, details=pFname, state='SW-{}'.format(sw), start=start_time)
print('Set game to {} at {} with friend code "SW-{}" showing'.format(pFname, string, sw))
RPC.update(large_image=pImg, large_text=pFname, small_image='switch_png', small_text='Switchence', details=pFname, state=f'SW-{sw}', start=start_time)
print(f'Set game to {pFname} at {string} with friend code "SW-{sw}" showing')
ctypes.windll.kernel32.SetConsoleTitleW(f'Switchence | Playing {pFname}')
else:
log.error('Couldn\'t get button info (2)')
except Exception as error:
log.error('Couldn\'t set RPC(2) to {} | {}'.format(pName, error))
log.error(f'Couldn\'t set RPC(2) to {pName} | {error}')
else:
log.error('Couldn\'t get friend code status')

Expand All @@ -176,8 +187,8 @@ def changeUpdateNotifier():
with open('config.json', 'w') as jsonfile:
json.dump(jsonFile, jsonfile, indent=4)
except Exception as error:
log.error('Couldn\'t change update-notifier setting | {}'.format(error))
log.info('Update notifier set to TRUE. Rerun the program to use it with the new settings')
log.error(f'Couldn\'t change update-notifier setting | {error}')
log.info('Update notifier set to {Fore.GREEN}TRUE{Fore.RESET}. Rerun the program to use it with the new settings')
elif picked == 'off' or picked == 'false' or picked == 'f':
try:
with open('config.json', 'r') as jsonfile: # very weird/hacky way to do this lol
Expand All @@ -187,8 +198,8 @@ def changeUpdateNotifier():
with open('config.json', 'w') as jsonfile:
json.dump(jsonFile, jsonfile, indent=4)
except Exception as error:
log.error('Couldn\'t change update-notifier setting | {}'.format(error))
log.info('Update notifier set to FALSE. Rerun the program to use it with the new settings')
log.error(f'Couldn\'t change update-notifier setting | {error}')
log.info('Update notifier set to {Fore.YELLOW}FALSE{Fore.RESET}. Rerun the program to use it with the new settings')

def changeFNameSetting():
if configfname == False:
Expand All @@ -198,7 +209,7 @@ def changeFNameSetting():
else:
log.error('Couldn\'t get config name setting')

k = input('Your current setting is set to: {}. What do you want to change it to ("full" for full game names, "short" for shortened game names)? '.format(l))
k = input(f'Your current setting is set to: {Fore.LIGHTGREEN_EX}{l}{Fore.RESET}. What do you want to change it to ("full" for full game names, "short" for shortened game names)? ')
if k == 'full' or k == 'f':
try:
with open('config.json', 'r') as jsonfile: # man i can use this anywhere lol
Expand All @@ -207,9 +218,9 @@ def changeFNameSetting():
details['fname'] = True
with open('config.json', 'w') as jsonfile:
json.dump(jsonFile, jsonfile, indent=4)
log.info('Set game name to "Full"')
log.info(f'Set game name to {Fore.YELLOW}Full{Fore.RESET}')
except Exception as error:
log.error('Couldn\'t change fname setting | {}'.format(error))
log.error(f'Couldn\'t change fname setting | {error}')
elif k == 'short' or k == 's':
try:
with open('config.json', 'r') as jsonfile:
Expand All @@ -218,9 +229,22 @@ def changeFNameSetting():
details['fname'] = False
with open('config.json', 'w') as jsonfile:
json.dump(jsonFile, jsonfile, indent=4)
log.info('Set game name to "Short"')
log.info(f'Set game name to {Fore.YELLOW}Short{Fore.RESET}')
except Exception as error:
log.error('Couldn\'t change fname setting | {}'.format(error))
log.error(f'Couldn\'t change fname setting | {error}')

clear()
print('''
.d8888b. d8b 888 888
d88P Y88b Y8P 888 888
Y88b. 888 888
"Y888b. 888 888 888 888 888888 .d8888b 88888b. .d88b. 88888b. .d8888b .d88b.
"Y88b. 888 888 888 888 888 d88P" 888 "88b d8P Y8b 888 "88b d88P" d8P Y8b
"888 888 888 888 888 888 888 888 888 88888888 888 888 888 88888888
Y88b d88P Y88b 888 d88P 888 Y88b. Y88b. 888 888 Y8b. 888 888 Y88b. Y8b.
"Y8888P" "Y8888888P" 888 "Y888 "Y8888P 888 888 "Y8888 888 888 "Y8888P "Y8888
Made by: Aethese#1337
''')

print('Here are the current games: ')
if configfname == False:
Expand Down Expand Up @@ -249,7 +273,7 @@ def changeFNameSetting():
elif x == 'change-name' or x =='change name' or x == 'c-n' or x == 'cn':
changeFNameSetting()

y = input('Do you want to show your friend code "SW-{}" (you can change this by typing "change")? '.format(sw))
y = input(f'Do you want to show your friend code "SW-{sw}" (you can change this by typing "change")? ')
y = y.lower()

if y == 'yes' or y == 'y':
Expand All @@ -271,7 +295,7 @@ def changeFNameSetting():
print('Friend code changed to SW-{}'.format(c))
y = 'yes'
except Exception as error:
log.error('Couldn\'t change sw-code | {}'.format(error))
log.error(f'Couldn\'t change sw-code | {error}')
else:
print('Friend code not changed')

Expand All @@ -288,7 +312,7 @@ def changeFNameSetting():
else:
log.info('The game you specified is not in the current game list')
except Exception as error:
log.error('Can\'t find the game ({}) the user specified (1) | {}'.format(x, error))
log.error(f'Can\'t find the game ({x}) the user specified (1) | {error}')

try:
for i in games['games']:
Expand All @@ -303,7 +327,7 @@ def changeFNameSetting():
changePresence(False, name, img, fname)
break
except Exception as error:
log.error('Can\'t find the game ({}) specified (2) | {}'.format(chosenOne, error))
log.error(f'Can\'t find the game ({chosenOne}) specified (2) | {error}')

while 1: # trust me, we need this
time.sleep(15)

0 comments on commit a6a3b05

Please sign in to comment.