예제 #1
0
    def execute(site, action):
        """ Execute the action for a site
            Steps:
                1) download
                2) convert
                3) test
                4) create_db
                5) download_images
                6) delete
            :param site: the site
            :param action: the action
        """

        # check actions
        if not Sites.valid_action(action):
            print ERROR_ACTION_INVALID
            return

        if not Sites.is_valid_site(site):
            print ERROR_SITE
            return

        if site == "blueapron":
            from websites.blueapron import BlueApron

            __classmap__["blueapron"] = BlueApron

        if action == ACTION_DOWNLOAD:
            from lib.DownloadSite import DownloadSite
            download = DownloadSite(site, DEBUG)
            download.download()

        elif action == ACTION_CONVERT:
            from lib.Convert import Convert
            convert = Convert(site, DEBUG)
            convert.convert_html()

        elif action == ACTION_TEST:
            from lib.Testing import Testing
            testing = Testing(site, DEBUG)
            testing.test_json()

        elif action == ACTION_DOWNLOAD_IMAGE:
            from lib.DownloadSite import DownloadSite
            download = DownloadSite(site, DEBUG)
            download.download_images()

        elif action == ACTION_CREATE_DB:
            from lib.DB import DB
            database = DB(site, DEBUG)
            database.create()

        elif action == ACTION_DELETE:
            from lib.Cache import Cache
            cache = Cache(site, DEBUG)
            cache.delete_cache()