Giter VIP home page Giter VIP logo

reddit_episode_bot's Introduction

Reddit episode bot Tests

A script that provides info and links to TV episodes. It can automatically create a comment like below:

Picking up where he left off, Bojack Horseman is now set to start filming his dream movie Secretariat.

(Summary text is covered by spoilertag until mouseover)

This repo was archived when Heroku stopped offering free server resources. Feel free to fork this project if desired, the code is pretty simple so it should work with just a bit of touch-up.

How to activate

You have to mention, reply, or message /u/the_episode_bot. If you post a thread with the correct format in the title it automatically activates. (currently limited to participating subreddits*). The bot runs during the day and sleeps during the night (Pacific Time)

Requests should be in a form similar to this:

/u/the_episode_bot Simpsons season 3 episode 2.

Regex parsing allows the bot to accept many different request formats, as well as misspellings. The show title can be automatically inferred if the subreddit corresponds to a show in the TV-related subreddits list. Note that the listing is out of date, so please message me if there is a new show to include. Also, the bot can't distinguish between different series of the same TV show. Sorry Doctor Who fans, you are out of luck.

Development

  1. Download Python 3
  2. Install packages via pip install -r requirements.txt
  3. set your omdb api key as a environment variable
  4. debug unit tests in unit_tester.py to get a feel for how the code works (also see code diagram in info folder)
  5. Run timer.py

For running bot on heroku look at the info folder

Thanks to

Contributions and constructive criticism are welcomed.

reddit_episode_bot's People

Contributors

almenon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dan-king

reddit_episode_bot's Issues

Add in API key for reddit bot

I stopped the bot because the omdbAPI went private. It's just 1$ a month though, so I should restart it back up again.

attributeerror

Jul 14 22:16:04 obscure-peak-2895 app/worker.1: INFO:root:analyzing https://www.reddit.com/r/BoJackHorseman/comments/hr8tv2/rewatching_s1ep1_and_bojack_has_a_panic_attack/
Jul 14 22:16:04 obscure-peak-2895 app/worker.1: INFO:root:request: Rewatching S1-EP1, and Bojack has a panic attack from the prospect of making a phone call. RELATABLE. 💀
Jul 14 22:16:04 obscure-peak-2895 app/worker.1: INFO:root:Parsed request is http://www.omdbapi.com/?apikey=&t=bojack%20horseman&Season=1&Episode=1
Jul 14 22:16:04 obscure-peak-2895 app/worker.1: DEBUG:root:{"Title":"BoJack Horseman: The BoJack Horseman Story, Chapter One","Year":"2014","Rated":"N/A","Released":"22 Aug 2014","Season":"1","Episode":"1","Runtime":"25 min","Genre":"Animation, Comedy, Drama","Director":"Joel Moser","Writer":"Raphael Bob-Waksberg (created by), Raphael Bob-Waksberg","Actors":"Will Arnett, Amy Sedaris, Alison Brie, Paul F. Tompkins","Plot":"A publishing house eagerly awaits BoJack's memoirs, but he hasn't even started yet. His agent/ex and his publisher try to talk him into working with a ghost writer, but BoJack's too despondent about being washed up to focus.","Language":"English","Country":"USA","Awards":"N/A","Poster":"https://m.media-amazon.com/images/M/MV5BMjI1MDQ3MzMzNF5BMl5BanBnXkFtZTgwMDE4ODM5MTE@._V1_SX300.jpg","Ratings":[{"Source":"Internet Movie Database","Value":"7.1/10"}],"Metascore":"N/A","imdbRating":"7.1","imdbVotes":"2522","imdbID":"tt3957774","seriesID":"tt3398228","Type":"episode","Response":"True"}
Jul 14 22:16:04 obscure-peak-2895 app/worker.1: INFO:root:JSON: {'Title': 'BoJack Horseman: The BoJack Horseman Story, Chapter One', 'Year': '2014', 'Rated': 'N/A', 'Released': '22 Aug 2014', 'Season': '1', 'Episode': '1', 'Runtime': '25 min', 'Genre': 'Animation, Comedy, Drama', 'Director': 'Joel Moser', 'Writer': 'Raphael Bob-Waksberg (created by), Raphael Bob-Waksberg', 'Actors': 'Will Arnett, Amy Sedaris, Alison Brie, Paul F. Tompkins', 'Plot': "A publishing house eagerly awaits BoJack's memoirs, but he hasn't even started yet. His agent/ex and his publisher try to talk him into working with a ghost writer, but BoJack's too despondent about being washed up to focus.", 'Language': 'English', 'Country': 'USA', 'Awards': 'N/A', 'Poster': 'https://m.media-amazon.com/images/M/MV5BMjI1MDQ3MzMzNF5BMl5BanBnXkFtZTgwMDE4ODM5MTE@._V1_SX300.jpg', 'Ratings': [{'Source': 'Internet Movie Database', 'Value': '7.1/10'}], 'Metascore': 'N/A', 'imdbRating': '7.1', 'imdbVotes': '2522', 'imdbID': 'tt3957774', 'seriesID': 'tt3398228', 'Type': 'episode', 'Response': 'True'}
Jul 14 22:16:06 obscure-peak-2895 app/worker.1: ERROR:root:can't set attribute
Jul 14 22:16:06 obscure-peak-2895 app/worker.1: Traceback (most recent call last):
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "heroku_timing.py", line 22, in <module>
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     bot.scan(last_time)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/bot.py", line 88, in scan
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     check_subreddits(last_scan)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/bot.py", line 112, in check_subreddits
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     submission.add_comment(answer)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/objects.py", line 1187, in add_comment
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     response = self.reddit_session._add_comment(self.fullname, text)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/__init__.py", line 2669, in _add_comment
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     retval = decorator(add_comment_helper)(self, thing_id, text)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/decorators.py", line 271, in wrap
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     return function(*args, **kwargs)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/__init__.py", line 2662, in add_comment_helper
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "<decorator-gen-8>", line 2, in request_json
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/decorators.py", line 116, in raise_api_exceptions
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/__init__.py", line 632, in request_json
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     data = json.loads(response, object_hook=hook)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/json/__init__.py", line 367, in loads
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/json/decoder.py", line 339, in decode
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/json/decoder.py", line 355, in raw_decode
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     obj, end = self.scan_once(s, idx)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/__init__.py", line 490, in _json_reddit_objecter
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     return object_class.from_api_response(self, json_data['data'])
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/objects.py", line 55, in from_api_response
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     return cls(reddit_session, json_dict=json_dict)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     underscore_names=['replies'])
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/objects.py", line 70, in __init__
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     self._has_fetched = self._populate(json_dict, fetch)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:     setattr(self, name, value)
Jul 14 22:16:06 obscure-peak-2895 app/worker.1:   File "/app/.heroku/python/lib/python3.6/site-packages/praw/objects.py", line 127, in __setattr__
Jul 14 22:16:06 obscure-peak-2895 app/worker.1: AttributeError: can't set attribute

check_downvoted causing errors

ERROR:root:can't set attribute

Traceback (most recent call last):

  File "heroku_timing.py", line 24, in <module> 
    bot.scan(last_time) 
  File "/app/bot.py", line 90, in scan 
    check_downvoted(last_scan) 
  File "/app/bot.py", line 174, in check_downvoted 
    for x in comments: 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/__init__.py", line 567, in get_content 
    page_data = self.request_json(url, params=params) 
  File "<decorator-gen-8>", line 2, in request_json 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/decorators.py", line 116, in raise_api_exceptions 
    return_value = function(*args, **kwargs) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/__init__.py", line 632, in request_json 
    data = json.loads(response, object_hook=hook) 
  File "/app/.heroku/python/lib/python3.5/json/__init__.py", line 332, in loads 
    return cls(**kw).decode(s) 
  File "/app/.heroku/python/lib/python3.5/json/decoder.py", line 339, in decode 
    obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
  File "/app/.heroku/python/lib/python3.5/json/decoder.py", line 355, in raw_decode 
    obj, end = self.scan_once(s, idx) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/__init__.py", line 490, in _json_reddit_objecter 
    return object_class.from_api_response(self, json_data['data']) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/objects.py", line 55, in from_api_response 
    return cls(reddit_session, json_dict=json_dict) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/objects.py", line 614, in __init__ 
    underscore_names=['replies']) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/objects.py", line 70, in __init__ 
    self._has_fetched = self._populate(json_dict, fetch) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/objects.py", line 179, in _populate 
    setattr(self, name, value) 
  File "/app/.heroku/python/lib/python3.5/site-packages/praw/objects.py", line 127, in __setattr__ 
    object.__setattr__(self, name, value) 
AttributeError: can't set attribute 

Bot should save last scan time before exiting in all cases

An error occured in the PRAW library I use to access reddit. The error propogated upwards and was uncaught by my error handler, killing the bot before it could save the last scan time. When the bot restarted it found a post, commented, then died again, forming a nasty loop.

The fix for this is very simple, I should've caught all types of errors in the exception handler.

e̶x̶c̶e̶p̶t̶ ̶p̶r̶a̶w̶.̶e̶r̶r̶o̶r̶s̶.̶P̶R̶A̶W̶E̶x̶c̶e̶p̶t̶i̶o̶n̶ ̶a̶s̶ ̶e̶:̶

except Exception as e:

Read custom formatting from subreddit's wiki

If would be nice if mods could customize the bot's formatting on their subreddit by adding formatting rules to a page in their wiki. The bot could scrape all the pages when it restarts (which is daily).

Comment below if you want this feature or have any thoughts on the matter.

search by episode title

Being able to recognize episode titles would increase the number of posts / mentions the bot is able to respond too.

to-do: use database instead of requesting from omdb

get data from local copy of omdb rather than scraping it from the site. This has 4 advantages:

  1. faster
  2. less error-prone (no worrying about omdb website being down)
  3. script would not be any burden on the omdb website anymore
  4. database could be customized to add missing episodes, shows, and information not present

Only 1 disadvantage: local database would be out of sync with online database - eventually online database will be updated and I would have to merge customized local database with copy of online one.

centralize subreddit settings

I have settings I need to hardcode scattered about all over the place. Subreddit to show mapping, netflix link, spoiler format, hulu link, etc...

It's annoying adding a subreddit when I get a new one on board.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.