import asyncio
import logging
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
from aiogram import Bot, Dispatcher, MemoryStorage
from config import config
import Handlers
from sqlFile import db, sql, create_sql
class MyHandler(PatternMatchingEventHandler):
patterns = ["*.txt", "*.jpg"]
def process(self, event):
out = str(event.src_path)
with open(out, "r") as t1:
text = t1.read()
print(out)
print(text)
def on_modified(self, event):
self.process(event)
def on_created(self, event):
self.process(event)
async def observer_run():
args = 'C:\\ForTest'
observer = Observer()
observer.schedule(MyHandler(), path=args if args else '.')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
async def main():
bot = Bot(token=config['token'], parse_mode="HTML")
storage = MemoryStorage()
dp = Dispatcher(storage=storage)
logging.basicConfig(level=logging.INFO)
create_sql()
dp.include_router(Handlers.user_router)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(asyncio.gather(main(), observer_run()))
C:\Users\ashab\PycharmProjects\pdfhelper\venv\Scripts\python.exe
# до активации venv
C:\Users\ashab>python -V
Python 3.7.9
C:\Users\ashab>C:\Users\ashab\PycharmProjects\pdfhelper\venv\Scripts\activate
# после активации venv
(venv) C:\Users\ashab>python -V
Python 3.9.6
python "D:\PyProjects\Test\Literal2.py"
cd C:\my_project\
.venv\bin\python3.exe main.py
$ python -m venv venv
(win).$ .\venv\scripts\activate
.$ main.py
$ .\venv\scripts\activate
$ deactivate
.$ python main.py