Booting_Helper.exe

Hotaek Han·2022년 6월 21일
0

프로그램 소개와 개발 동기

본 프로그램은 컴퓨터 부팅 시 웹 브라우저를 실행시켜 자동으로 특정 웹 사이트에 접속하게 해주는 프로그램입니다.

채용 공고나 뉴스 등 항상 루틴으로 확인하고 싶은 웹페이지가 있는 경우 본 프로그램을 이용하여 등록해두면 편리합니다.

소스 코드


###
# booting helper Ver 1.0
# by Ryan Han, 2022-06-22
###
import os, glob
import webbrowser
import getpass
path = 'C:/Users/' + getpass.getuser() + '/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/'

def main():
    while(True):
        print("Auto Popup")
        print("===========================================")
        print("\t1. 신규 주소 등록")
        print("\t2. 기존 주소 목록 조회")
        print("\t3. 기존 주소 수정")
        print("\t4. 기존 주소 삭제")
        print("\t5. 경로 열기")
        print("\t6. 종료")
        print("===========================================")
        userInput = int(input())
        
        if (userInput == 1):
            fileName, url = get_info()
            set_url(fileName, url)

        elif (userInput == 2):
            load_files()

        elif (userInput == 3):
            fileName = input("수정할 파일의 이름을 입력해주세요.")

            if (isExist(fileName)):
                url = input("수정할 경로를 입력해주세요")
                set_url(fileName, url)
            else:
                ans = input("해당 파일이 존재하지 않습니다. 새로 만들까요? (Y / N")
                if (ans == 'Y' or ans == 'y'):
                    url = input("추가할 경로를 입력해주세요.")
                    set_url(fileName, url)
                else:
                    print("취소되었습니다.")

        elif (userInput == 4):
            fileName = input("삭제할 파일의 이름을 입력해주세요")
            remove_file(fileName)

        elif (userInput == 5):
            webbrowser.open(path)
        
        elif (userInput == 6):
            print("프로그램을 종료합니다.")
            break

def get_info():
    fileName = input("바로가기의 이름을 입력해주세요.")

    while(True):
        if (isExist(fileName)):
            print("이미 존재하는 URL 파일 이름입니다.")
            fileName = input("바로가기의 이름을 입력해주세요.")
        break

    url = input("추가할 주소를 입력해주세요.")

    return fileName, url

def set_url(fileName, url):
    
    with open(path+fileName+".txt", 'w') as f:
        f.write('[InternetShortcut]')
        f.write('\nURL=' + url)

    remove_file(fileName)
    os.renames(path + fileName + ".txt", path + fileName + ".url")
        
            
        
def load_files():
    fileList = os.listdir(path)
    fileUrlList = [file for file in fileList if file.endswith(".url")]
    
    for file in fileUrlList:
        print(file)


def isExist(fileName):
    return os.path.exists(path + fileName + '.url')

def remove_file(fileName):
    if (isExist(fileName)):
        os.remove(path + fileName + ".url")

main()

0개의 댓글