'Grab lines from txt files and paste them converted into a batch file to run it as a command
I am using a RSS program which uses tags, ignores and blacklists. I need to run python main.py -w [my webhook] -t [my tags] -i [my ignored users] -b [blacklisted tags] I simply saved that in a batch file so that I don't need to type it everytime in a terminal. After using it for like 1h I noticed that I gotta adjust everything till the RSS sends only that what I want, so I came up with a Idea to save the my tags etc. in seperate text files so that the batchscript reads the files and runs the command with my adjustments included. All the adjustments are seperated with commas (f.e. background,sky,rain). It would be even better if the program reads all the text files (tags are saved line by line in the text files so that every line has one tag because it gives me a better overview) and converts the ⏎ (enter) into a , before using it for the command. It would be nice of someone teaches me how to do that and explains their steps.
Update:
I found a batchscript and modified it so that it works for my scenario. The only problem is that the script doesn't send/grab the text if one text file contains any japanese characters (I changed the text file to ANSI because it would send otherwise only question marks). In my case it sends only python main.py -w [my webhook] -t ~1 -i [my ignored users] -b [blacklisted tags]. Instead of actually sending my tags from the tag list it sends just ~1. Does anyone know how to fix this and are there any unnecessary commands in my script or can I make it better?
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "tags="
for /F "usebackq delims=" %%T in ("Tag.txt") do set "tags=!tags!,%%T"
rem Remove comma at beginning of the tags value.
set "tags=!tags:~1!"
set "ignore="
for /F "usebackq delims=" %%I in ("Ignore.txt") do set "ignores=!ignores!,%%I"
rem Remove comma at beginning of the ignores value.
set "ignores=!ignores:~1!"
set "banned="
for /F "usebackq delims=" %%B in ("Banned.txt") do set "banned=!banned!,%%B"
rem Remove comma at beginning of the banned value.
set "banned=!banned:~1!"
python main.py -s [my sessionid] -w [my webhook] -t !tags! -i '!ignores!' -b '!banned!'
endlocal
pause
Solution 1:[1]
You should be able to import system from os and send the command through that. That way you can just write a separate python script around it that you can setup to run as you please. Assuming you're on windows, I'm not sure if this works on another os.
Using the following and replacing the variables with your arguments.
from os import system
webhook = ''
tags = ''
ignored_users = ''
blacklisted_tags = ''
system(f'python main.py -w {webhook} -t {tags} -i {ignored_users} -b {blacklisted_tags}')
I wasn't completely clear on what you were asking for so I hope this helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jackson V |
