Last active
January 29, 2020 15:56
-
-
Save jose-almir/7e7dadc6c7b21da141aeadb9e3236ff3 to your computer and use it in GitHub Desktop.
A over engine that reloads the web page whenever your files change, useful for web dev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
HOW TO USE => | |
1. DOWNLOAD FIREFOX DRIVE: GECKODRIVER | |
2. INSTALL SELENIUM AND WATCHDOG LIBS | |
3. USE PYTHON3 | |
4. SPECIFY MAIN HTML FILE FOR RELOAD WHENEVER THE PATH CHANGES | |
5. SPECIFY THE PATH OF YOUR PROJECT | |
ENJOY | |
EXAMPLE: | |
python3 refresh4me.py teste01.html ~/DESIGNWEB/ | |
CTRL+C to cancel and close all resources | |
""" | |
import sys | |
import os | |
import time | |
from watchdog.observers import Observer | |
from watchdog.events import FileSystemEventHandler | |
from selenium.webdriver import Firefox | |
driver = Firefox() | |
full_path = os.path.expanduser(sys.argv[2]) | |
url_file = os.path.join(full_path, sys.argv[1]) | |
driver.get(f'file:{url_file}') | |
class PathHandler(FileSystemEventHandler): | |
def __init__(self, path): | |
self.path = path | |
def on_modified(self, event): | |
driver.refresh() | |
def main(): | |
path = full_path | |
events = PathHandler(path) | |
obs = Observer() | |
obs.schedule(events, path) | |
obs.start() | |
try: | |
while 1: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
obs.stop() | |
obs.join() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment