Skip to content

Commit

Permalink
Added option to use short names of the categories, so the CW fits on …
Browse files Browse the repository at this point in the history
…a single line
  • Loading branch information
valknight committed May 12, 2019
1 parent 85da724 commit f10a480
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
26 changes: 23 additions & 3 deletions apis/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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/')
Expand Down
12 changes: 9 additions & 3 deletions build_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@
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"

if topic['yes_votes'] > topic['no_votes']:
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")
Expand All @@ -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:
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
21 changes: 20 additions & 1 deletion dtdd_api.py
Original file line number Diff line number Diff line change
@@ -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]"}
Expand All @@ -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__":
Expand Down

0 comments on commit f10a480

Please sign in to comment.