I decided to tweet the schedule on python's tweet, and I created the following batch file using sys.argv so that I can call the py file and text it in it.
set/p Tweet="Tweet:"
set/p Time = "Time:"
Scheduler_Tweet.py%Tweet%%Time%
This works fine when I tweet only one line, but when I wanted to tweet multiple lines, I tried to break the line with \n, but it was just tweeted as a letter.
Please let me know if there is any way to reflect a new line.
Thank you for your cooperation.
By the way, inside Scheduler_Tweet.py, you can find
auth=tweepy.OAuthHandler(CK,CS)
auth.set_access_token(AT,AS)
api=tweepy.API(auth)
def job():
api.update_status(status=(sys.argv[1]))
defmain():
schedule.every().day.at(sys.argv[2])) .do(job)
while True:
schedule.run_pending()
time.sleep(1)
main()
That's it.
python windows cmd
For example, if you create a minimal script like this and run it in a batch file instead of Scheduler_Tweet.py
, you'll see what gets passed.
The \n
you entered is displayed as it is.
import sys
print(sys.argv[1])
print(sys.argv[2])
And I think the article around here will be a countermeasure.
Returns the string escaped by Python
Notes on how to unescape (?) a string escaped by python
How to un-escape a backslash-escaped string?
However, simple application will disguise characters outside the ASCII range (full-width characters and half-width characters), so .encode()
will apply the answers to the above English article.
If you apply it to the above script, it will look like this:
import sys
print(sys.argv[1].encode('latin1', errors='backslashreplace').decode('unicode-escape')))
print(sys.argv[2].encode('latin1', errors='backslashreplace').decode('unicode-escape')))
Scheduler_Tweet.py
Try the appropriate part of the script that retrieves the command line parameter string as described above.
If you pass \n
as an argument for a command prompt, the string \n ("\\n"
or r"\n"
notation) is passed instead of the new line code \n
.
You can reflect a new line by sending a new line code to tweepy.API.update_status
.
sample.py
import sys
print(sys.argv[1])
print(sys.argv[1].replace("\\n", "\n")))
python.\sample.py baldness The results of running are as follows:
browing\nbrowing\nbrowning\nbrowing _yomi
bark
however
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.