diff --git a/examples/feed-generator-from-redis/fromredis.py b/examples/feed-generator-from-redis/fromredis.py index 26b2ee6..47dd20f 100755 --- a/examples/feed-generator-from-redis/fromredis.py +++ b/examples/feed-generator-from-redis/fromredis.py @@ -1,15 +1,15 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import sys -import json import argparse import datetime +import json +import sys import time + import redis import settings - from generator import FeedGenerator @@ -60,7 +60,10 @@ class RedisToMISPFeed: except Exception as error: self.save_error_to_redis(error, data) - beautyful_sleep(5, self.format_last_action()) + try: + beautyful_sleep(5, self.format_last_action()) + except KeyboardInterrupt: + sys.exit(130) def pop(self, key): popped = self.serv.rpop(key) diff --git a/examples/feed-generator-from-redis/generator.py b/examples/feed-generator-from-redis/generator.py index 38a9d54..558de21 100755 --- a/examples/feed-generator-from-redis/generator.py +++ b/examples/feed-generator-from-redis/generator.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 -import sys +import datetime +import hashlib import json import os -import hashlib -import datetime +import sys import time import uuid @@ -142,9 +142,24 @@ class FeedGenerator: # Manifest def _init_manifest(self): + # check if outputdir exists and try to create it if not + if not os.path.exists(settings.outputdir): + try: + os.makedirs(settings.outputdir) + except PermissionError as error: + print(error) + print("Please fix the above error and try again.") + sys.exit(126) + # create an empty manifest - with open(os.path.join(settings.outputdir, 'manifest.json'), 'w'): - pass + try: + with open(os.path.join(settings.outputdir, 'manifest.json'), 'w'): + pass + except PermissionError as error: + print(error) + print("Please fix the above error and try again.") + sys.exit(126) + # create new event and save manifest self.create_daily_event()