I'm new to programming.
This is my first time to ask a question, so I'm sorry if the question is bad.
windows10 Pro ver.1909
・ I want to achieve
When the computer starts up
"Always monitor the folder and send an email when an xlsx file is created"
Run the program.
Using Python watchdog, I am writing a program that constantly monitors the specified folder and sends gmail when an xlsx file is created in that folder.
If i run the program in the IDE or command prompt, the result will be as intended.
However, I wanted the program to run automatically when the computer started, but it didn't work and I asked a question here.
Corresponding source code
What I tried
import time import os import smtplib from email.mime.text import MIMEText from email.utils import formatdate from watchdog.events import FileSystemEventHandler from watchdog.observers.polling import PollingObserver FROM_ADDRESS ='****@gmail.com' MY_PASSWORD ='****' TO_ADDRESS ='**** @ ****' BCC ='' SUBJECT ='****' BODY ='****' def create_message (from_addr, to_addr, bcc_addrs, subject, body): msg = MIMEText (body) msg ['Subject'] = subject msg ['From'] = from_addr msg ['To'] = to_addr msg ['Bcc'] = bcc_addrs msg ['Date'] = formatdate () return msg def send (from_addr, to_addrs, msg): smtpobj = smtplib.SMTP_SSL ('smtp.gmail.com', 465, timeout = 10) smtpobj.login (FROM_ADDRESS, MY_PASSWORD) smtpobj.sendmail (from_addr, to_addrs, msg.as_string ()) smtpobj.close () BASEDIR = "C: \\ sample" def getext (filename): return os.path.splitext (filename) [-1] .lower () class ChangeHandler (FileSystemEventHandler): def on_created (self, event): if event.is_directory: return if getext (event.src_path) in ('.xlsx'): if __name__ =='__main__': to_addr = TO_ADDRESS subject = SUBJECT body = BODY msg = create_message (FROM_ADDRESS, to_addr, BCC, subject, body) send (FROM_ADDRESS, to_addr, msg) if __name__ in'__main__': while 1: event_handler = ChangeHandler () observer = PollingObserver () observer.schedule (event_handler, BASEDIR, recursive = True) observer.start () try: try: while True: time.sleep (1) except KeyboardInterrupt: observer.stop () observer.join ()
1. I put the program in the startup folder (shell: startup) but it didn't run.
2. I set the task start trigger of the task scheduler to "at startup", but the task is completed and I cannot always monitor the file.
Answer # 1
In task scheduler
The contents of temp11119.bat will not work if it is Python code
Inside the bat is the location of the python file and the target file name.py
Example: python c: \ py \ pg.py
- python program cannot be executed
- python - create a program to automatically take a screenshot of the kindle screen and save it
- python - the py file cannot be executed in the task scheduler 0x2 error
- please tell me how to write a program to end when the result is executed 5 times [python]
- get gogole search screen automatically with python
- how to automatically open a tool written in python when maya (2016) starts
- python - background program by sharley method
- how to write a python program for the fibonacci sequence
- python - i don't see the error in the face cropping program with opencv
- python - a code that automatically selects the features used in machine learning
- [python] i don't understand why the code can't be executed
- python - a program that converts ordinal data to paired comparison data (i want to create a winning/losing matrix by turning a d
- python 3x - the program only works on the first line
- python 3x - i want to be able to run a scraping program created in python on a website
- python - please tell me how to automatically update the temperature, humidity and barometric pressure display using bme280 on ra
- in the python if statement, the process is not executed even though the condition is satisfied
- python 3x - it will not be executed if it is a py file
- program hangs without error in python
- python - i want to automatically enter the value of the text box before the transition in the text box after the screen transiti
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory