Skip to content

Commit

Permalink
good changes :)
Browse files Browse the repository at this point in the history
  • Loading branch information
SheaSilverman committed Mar 19, 2015
1 parent 2c707a4 commit 404c243
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
17 changes: 17 additions & 0 deletions file_watcher/.gitattributes
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
9 changes: 9 additions & 0 deletions file_watcher/README.md
@@ -0,0 +1,9 @@
# file_watcher
-sudo pip install watchdog

-python watch /home/pi/pimame/roms

program will watch roms folder. When a new file is created or deleted,
the program will add that folder to the scrape list. If the scrape list
contains changes, then it will run the scraper automatically every 60
seconds.
47 changes: 47 additions & 0 deletions file_watcher/watch.py
@@ -0,0 +1,47 @@
import sys
import time
import os
import logging
import sqlite3
from watchdog.observers import Observer
#from watchdog.events import LoggingEventHandler
from watchdog.events import PatternMatchingEventHandler
import argparse

parser = argparse.ArgumentParser(description='PiScraper')
parser.add_argument("--delay", default=60, metavar="60", help="How long to wait before running scraper", type=int)
parser.add_argument("--path", default='.', metavar="/path/to/watch", help="folder to monitor", type=str)

args = parser.parse_args()


class EventHandler(PatternMatchingEventHandler):
info = []
def on_any_event(self, event):

if not event.is_directory:
self.conn = sqlite3.connect('/home/pi/pimame/pimame-menu/database/config.db')
self.c = self.conn.cursor()
if event.event_type == 'created':
self.info.append(self.c.execute('SELECT id FROM menu_items WHERE rom_path LIKE "{0}%"'.format(os.path.dirname(event.src_path))).fetchone()[0])
print 'new file found:', event.src_path
if event.event_type == 'deleted':
self.info.append(self.c.execute('SELECT id FROM menu_items WHERE rom_path LIKE "{0}%"'.format(os.path.dirname(event.src_path))).fetchone()[0])
print 'file deleted:', event.src_path
else: print

if __name__ == "__main__":
path = args.path
event_handler = EventHandler(ignore_patterns=['*.jpg', '*.png', '*.gif', '*.gitkeep'], case_sensitive=False)
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(args.delay)
if event_handler.info: os.system('python /home/pi/pimame/pimame-menu/scraper/scrape_script.py --platform {0}'.format(str(set(event_handler.info))[5:-2].replace(' ','')))
event_handler.info = []
except KeyboardInterrupt:
observer.stop()
observer.join()

2 changes: 1 addition & 1 deletion pimame-menu

0 comments on commit 404c243

Please sign in to comment.