def clear_url(url): cached_session = APP.setting("WEBCACHE") if cached_session.cache.has_url(url): cached_session.cache.delete_url(url) APP.output("Deleted url from webcache: %s" % url) else: APP.debug("Found no match for %s in webcache." % url)
def clear_webcache(movie): for provider_path in APP.setting("MOVIEDATA_PROVIDERS"): provider_module = import_module(provider_path) provider = provider_module.Provider() APP.debug("Clearing movie name (%s) from webcache" % movie["title"]) clear_url(provider.get_url({"name": movie["title"].lower()})) # Make sure we clear URLs with year too clear_url( provider.get_url({ "name": movie["title"].lower(), "year": movie["year"], })) for search_phrase in movie["search_phrases"]: APP.debug("Clearing movie search phrase (%s) from webcache" % search_phrase) clear_url(provider.get_url({ "name": search_phrase, })) # Make sure we clear URLs with year too clear_url( provider.get_url({ "name": search_phrase, "year": movie["year"], }))
def fetch_movie_data(self, movie): url = self.get_url(movie) APP.debug("Fetching url: %s" % url) data = self.parse_json(url) if not data or data["Response"] == "False": return {} return self.transform_data(data)
def fetch_movie_data(self, movie): url = self.get_url(movie) APP.debug("Fetching url: %s" % url) data = self.parse_json(url, path="data.movies") for hit in data: if hit and "releaseDate" in hit and hit["releaseDate"]: return self.transform_data(hit) return {}
def clear_webcache(movie): cached_session = APP.setting("WEBCACHE") for provider_path in APP.setting("MOVIEDATA_PROVIDERS"): provider_module = import_module(provider_path) provider = provider_module.Provider() url = provider.get_url(movie) if cached_session.cache.has_url(url): cached_session.cache.delete_url(url) APP.output("Deleted url from webcache: %s" % url)
def fetch_movie_data(self, movie): url = self.get_url(movie) APP.debug("Fetching url: %s" % url) data = self.parse_json(url, path="0.data.0.hits") data = self.find_movie_matching_year(data, movie["year"]) if not data: return {} return self.transform_data(data)
def mail(recipient, subject, message): with APPLICATION.app_context(): MAIL = Mail(APPLICATION) msg = Message(subject, recipients=[recipient]) msg.body = message MAIL.send(msg)
def _http_get(self, url, timeout=60, cache=True): base = self.session if not cache else APP.setting("WEBCACHE") response = base.get(url, timeout=timeout) # from pprint import pprint # print("REQUEST", url) # pprint(base.headers) # print("-" * 80) # print("RESPONSE", response.status_code, repr(response.text)) # pprint(response.headers) # print("=" * 80) return response.text
def clear_webcache(movie): for provider_path in APP.setting("MOVIEDATA_PROVIDERS"): provider_module = import_module(provider_path) provider = provider_module.Provider() APP.debug("Clearing movie name (%s) from webcache" % movie["title"]) clear_url(provider.get_url({ "name": movie["title"].lower() })) # Make sure we clear URLs with year too clear_url(provider.get_url({ "name": movie["title"].lower(), "year": movie["year"], })) for search_phrase in movie["search_phrases"]: APP.debug("Clearing movie search phrase (%s) from webcache" % search_phrase) clear_url(provider.get_url({ "name": search_phrase, })) # Make sure we clear URLs with year too clear_url(provider.get_url({ "name": search_phrase, "year": movie["year"], }))
def clear_cache(name): APP.debug("Clearing \"%s\" from movie db..." % name) movie = torrent_to_movie(name) record = APP.Movie.get_data(movie) if not record: APP.output("Could not find movie in db: %s" % name) return clear_webcache(record) APP.output("Deleted movie from database: %s" % record["title"]) APP.Movie.remove("id", record["id"])
def clear_cache(name): if platform.system() == 'Windows': name = name.decode("windows-1252") APP.debug("Clearing \"%s\" from movie db..." % name) movie = torrent_to_movie(name) clear_webcache(movie) record = APP.Movie.get_data(movie) if not record: APP.output("Could not find movie in db: %s" % name) return # Querying with and without year can give different URLs if not movie["year"] and record["year"]: movie["year"] = record["year"] clear_webcache(movie) APP.output("Deleted movie from database: %s" % record["title"]) APP.Movie.remove("id", record["id"])
def output(movie_data): provider_module = import_module(APP.setting("OUTPUT_PROVIDER")) provider = provider_module.Provider() APP.debug("Outputting data with %s" % provider_module.IDENTIFIER) provider.output(movie_data)
def get_filenames(directory): APP.debug("Loading movies from: %s" % directory) files = os.listdir(directory) files = [(filename, os.path.isdir(os.path.join(directory, filename))) for filename in files] movies = [filename for filename, is_directory in files if is_proper_movie_file(filename, is_directory)] return movies
import sys from backend import (admin, auth, channel, channels, message, search, user, users, standup) from backend.utility.storage import box from application import APPLICATION for module in [admin, auth, channel, channels, message, search, user, users, standup]: APPLICATION.register_blueprint(module.endpoints) if __name__ == '__main__': if len(sys.argv) < 2: sys.exit("Usage: python3 server.py backend_port frontend_port") backend_port = int(sys.argv[1]) box('url_base', 'http://localhost:' + str(backend_port)) APPLICATION.run(port=backend_port)
def _http_get(self, url, timeout=60, cache=True): base = requests if not cache else APP.setting("WEBCACHE") response = base.get(url, timeout=timeout) return get_unicode_from_response(response)
""" FLask development server """ from application import APPLICATION APPLICATION.run(host='0.0.0.0', port=8080, debug=True, threaded=True)
def get_popular(): APP.debug("Fetching popular movies...") provider_module = import_module(APP.setting("POPULARITY_PROVIDER")) provider = provider_module.Provider() APP.debug("Fetching from %s" % provider_module.IDENTIFIER) return provider.get_popular()
def output(movie_data, limit, filters): provider_module = import_module(APP.setting("OUTPUT_PROVIDER")) provider = provider_module.Provider() APP.debug("Outputting data with %s" % provider_module.IDENTIFIER) provider.output(movie_data, limit, filters)