From dd6268403980d9f15f5aded34f3255a959d84247 Mon Sep 17 00:00:00 2001 From: _Wr_ <45558679+AlanYe-Dev@users.noreply.github.com> Date: Sun, 20 Aug 2023 15:28:59 +0800 Subject: [PATCH] new: Create conf.yml.exmaple if does not exist --- README.md | 12 +++++++++--- conf.yml.example | 3 ++- src/main.py | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 835f9da..0520ccf 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,15 @@ Also, this requires ```$wgAllowCopyUploads = true;``` in the wiki's local settin 1. Download the latest build version from [here](https://github.com/AlanYe-Dev/mediawiki-file-import-utility/actions/workflows/pyinstaller-windows.yml). 2. Duplicate ```conf.yml.example```, rename it to ```conf.yml```. -3. Fill in the Bot credentials previous fetched. -4. Optional: Prepare a list of import filename to ```import.txt```. -5. Run **main.exe**. +3. Fill in the Bot credentials previous fetched. Example: +``` +bot: + username: xxx@xxx + password: 7aCTEJJM6eitNpJqmfsaPfERZmsQcawh +``` + +1. Optional: Prepare a list of import filename to ```import.txt```. +2. Run **main.exe**. ### Development diff --git a/conf.yml.example b/conf.yml.example index e7564a9..c1e4127 100644 --- a/conf.yml.example +++ b/conf.yml.example @@ -1,5 +1,6 @@ # Please enter the credentials from Special:BotPasswords -# Do not share this file for privacy reasons. +# DO NOT share this file for security reasons. +# For more information, see https://github.com/AlanYe-Dev/mediawiki-file-import-utility#readme bot: username: password: \ No newline at end of file diff --git a/src/main.py b/src/main.py index 259475d..fdb1c36 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ """ MediaWiki Import File Utility Author: _Wr_ + Version: 0.3 Foundations: - MediaWiki API Demos (MIT license) @@ -42,11 +43,12 @@ def extract_filename(url_or_text): return filename # Startup message -print ("MediaWiki Import File Utility (by _Wr_)\nVersion: 0.2\n") +print ("MediaWiki Import File Utility (by _Wr_)\nVersion: 0.3\n") # Read config file #conf = yaml.load(open('./conf.yml')) file_name = 'conf.yml' +eg_file_name = 'conf.yml.exmaple' # Check if config file exists if os.path.isfile(file_name): @@ -54,9 +56,15 @@ def extract_filename(url_or_text): with open('conf.yml', 'r') as config_file: conf = yaml.safe_load(config_file) else: - print(f"[ERROR] Did not detect config file '{file_name}'.\nPlease rename 'conf.yml.example' to 'conf.yml' and fill in the required fields.") - input ("Press Enter to exit...") - exit() + print(f"[WARNING] Did not detect config file '{file_name}'.\n[WARNING] Please rename 'conf.yml.example' to 'conf.yml' and fill in the required fields.\n[WARNING] For more information, see https://github.com/AlanYe-Dev/mediawiki-file-import-utility#readme") + if os.path.isfile(eg_file_name): + input ("Press Enter to exit...") + exit() + else: + with open("conf.yml.exmaple","w") as file: + file.write("# Please enter the credentials from Special:BotPasswords\n# DO NOT share this file for security reasons.\n# For more information, see https://github.com/AlanYe-Dev/mediawiki-file-import-utility#readme\nbot:\n username: \n password: ") + input ("Press Enter to exit...") + exit()