diff --git a/apis/plex.py b/apis/plex.py index f5d47dd..b8535a4 100644 --- a/apis/plex.py +++ b/apis/plex.py @@ -3,6 +3,16 @@ from config import token, url +try: + from config import use_short_names +except: + print("⚠ Please set use_short_names in your config.py") + use_short_names = False +try: + from config import only_show_yes +except: + print("⚠ Please set only_show_yes in your config.py") + only_show_yes = False ## DEFINE STATIC URLS FOR API get_libaries = "{base}/library/sections?X-Plex-Token={token}&X-Plex-Language=en".format(token=token, base=url) @@ -39,9 +49,19 @@ def write_data(movie): desc_cut = movie['desc'].split("\r\n\r\ndoesthedogdie: \r\n\r\n")[0] statuses = [] - for status in movie['statuses']: - statuses.append(status[0]) - ddtd_status = '\r\n'.join(statuses) + if len(movie['statuses']) == 0: + ddtd_status = "No content warnings could be retrieved for this film\nThis means either this film is fine, or it isn't present on DTDD" + else: + for status in movie['statuses']: + if not(only_show_yes) or status[1] == "Yes": + if use_short_names: + statuses.append(status[2]) + else: + statuses.append(status[0]) + if use_short_names: + ddtd_status = "This may contain: {}".format(', '.join(statuses)) + else: + ddtd_status = '\r\n'.join(statuses) movie['desc'] = "{}\r\n\r\ndoesthedogdie: \r\n\r\n{}".format(desc_cut, ddtd_status) movie['id']=movie['key'].strip('/library/metadata/') diff --git a/build_json.py b/build_json.py index 1ba7871..4eaacb0 100644 --- a/build_json.py +++ b/build_json.py @@ -26,6 +26,13 @@ print("⚠ Please set use_dtdd_web_api in your config.py") use_dtdd_web_api = False +try: + from config import use_short_names +except: + print("⚠ Please set use_short_names in your config.py") + use_short_names = False + + def yes_or_no_formatter(topic): action = "Unsure" @@ -33,7 +40,7 @@ def yes_or_no_formatter(topic): action = "Yes" elif topic['no_votes'] > topic['yes_votes']: action = "No" - return "{topic} : {action} (Yes: {yes_votes} | No : {no_votes})".format(topic=topic['topic'], yes_votes=topic['yes_votes'], no_votes=topic['no_votes'], action=action), action + return "{topic} : {action} (Yes: {yes_votes} | No : {no_votes})\n".format(topic=topic['topic'], yes_votes=topic['yes_votes'], no_votes=topic['no_votes'], action=action), action, topic['topic_short'] def main(): print("⬇ Getting movies from Plex") @@ -46,7 +53,7 @@ def main(): print("🐶 Getting data from DoesTheDogDie.com") if not use_memcache: print("⚠ You aren't using a memcache or an external API for DTDD - this will take a while") - for movie in tqdm(movies): + for movie in tqdm(movies[0:10]): if use_dtdd_web_api: resp = requests.get("{}/media/{}".format(dtdd_web_api_address, movie['title'])) if resp.status_code == 200: @@ -64,7 +71,6 @@ def main(): yes_or_no = yes_or_no_formatter(raw_status) if (not only_show_yes) or (yes_or_no[1] == "Yes"): movie['statuses'].append(yes_or_no) - to_write.append(movie) # all we need to do now is chuck it in a big ol' json file diff --git a/config.py.example b/config.py.example index 79a1c64..56f52e8 100644 --- a/config.py.example +++ b/config.py.example @@ -5,4 +5,5 @@ memcache_address = 'localhost' memcache_port = 11211 invalidation_time = 86400 # this is the time we can store something in memcache before it is known as invalid use_dtdd_web_api = True -dtdd_web_api_address = "http://dtdd.valknight.xyz" # this is the address the dtdd_api can be found at \ No newline at end of file +dtdd_web_api_address = "http://dtdd.valknight.xyz" # this is the address the dtdd_api can be found at +use_short_names = False # this will simply put out what does match as a list on a single line, instead of the full question \ No newline at end of file diff --git a/dtdd_api.py b/dtdd_api.py index 986ad41..8bd5a54 100644 --- a/dtdd_api.py +++ b/dtdd_api.py @@ -1,9 +1,26 @@ # This should be ran as a service if you want to make use of the web API tech without requesting the main one from flask_api import FlaskAPI from apis.doesthedogdie import get_info_for_movie - +import re app = FlaskAPI(__name__) +to_strip = [ + "Are( any| there)* ", + "Does( the| a| an| someone| it)* ", + "Is( a| there)* ", + "\?" +] + +to_replace = [("die", "dies")] + +def shorten(topic): + for filter in to_strip: + topic = re.sub(filter, '', topic) + for replacement in to_replace: + topic = topic.replace(replacement[0], replacement[1]) + + return topic + @app.route("/") def dtdd_index(): return {"status": "You're probably wanting to make a request to /media/[movie name]"} @@ -14,6 +31,8 @@ def movie_details(key): to_return = get_info_for_movie(key) if to_return == None: return {"error": "cannot find movie"}, 404 + for status in to_return: + status['topic_short'] = shorten(status['topic']) return to_return if __name__ == "__main__":