<commit_before>import cherrypy
import htpc
from htpc.proxy import get_image
from json import loads
from urllib2 import urlopen

class Couchpotato:
    def __init__(self):
        htpc.MODULES.append({
            'name': 'CouchPotato',
            'id': 'couchpotato',
            'test': htpc.WEBDIR + 'couchpotato/ping',
            'fields': [
                {'type': 'bool', 'label': 'Enable', 'name': 'couchpotato_enable'},
                {'type': 'text', 'label': 'Menu name', 'name': 'couchpotato_name'},
                {'type': 'text', 'label': 'IP / Host *', 'name': 'couchpotato_host'},
                {'type': 'text', 'label': 'Port *', 'name': 'couchpotato_port'},
                {'type': 'text', 'label': 'API key', 'name': 'couchpotato_apikey'},
                {'type': 'text', 'label': 'Basepath (starts with a slash)', 'name': 'couchpotato_basepath'}
        ]})

    @cherrypy.expose()
    def index(self):
        return htpc.LOOKUP.get_template('couchpotato.html').render()

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def ping(self, couchpotato_host, couchpotato_port, couchpotato_apikey, couchpotato_basepath, **kwargs):

        if(couchpotato_basepath == ""):
            couchpotato_basepath = "/"
        if not(couchpotato_basepath.endswith('/')):
            couchpotato_basepath += "/"

        url = 'http://' + couchpotato_host + ':' + couchpotato_port + couchpotato_basepath + 'api/' + couchpotato_apikey
        try:
            return loads(urlopen(url + '/app.available', timeout=10).read())
        except:
            return

    @cherrypy.expose()
    def GetImage(self, url, h=None, w=None, o=None):
        return get_image(url, h, w, o)

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def GetMovieList(self, limit=''):
        return self.fetch('movie.list?limit_offset=' + limit)

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def GetNotificationList(self, limit='20'):
        data = self.fetch('notification.list?limit_offset=' + limit)
        self.fetch('notification.markread')
        return data

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def DeleteMovie(self, id=''):
        return self.fetch('movie.delete/?id=' + id)

    @cherrypy.expose()
    @cherrypy.tools.json_out()<commit_msg>Update couchpotato.py<commit_after>import cherrypy
import htpc
from htpc.proxy import get_image
from json import loads
from urllib2 import urlopen

class Couchpotato:
    def __init__(self):
        htpc.MODULES.append({
            'name': 'CouchPotato',
            'id': 'couchpotato',
            'test': htpc.WEBDIR + 'couchpotato/ping',
            'fields': [
                {'type': 'bool', 'label': 'Enable', 'name': 'couchpotato_enable'},
                {'type': 'text', 'label': 'Menu name', 'name': 'couchpotato_name'},
                {'type': 'text', 'label': 'IP / Host *', 'name': 'couchpotato_host'},
                {'type': 'text', 'label': 'Port *', 'name': 'couchpotato_port'},
                {'type': 'text', 'label': 'API key', 'name': 'couchpotato_apikey'},
                {'type': 'text', 'label': 'Basepath (starts with a slash)', 'name': 'couchpotato_basepath'}
        ]})

    @cherrypy.expose()
    def index(self):
        return htpc.LOOKUP.get_template('couchpotato.html').render()

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def ping(self, couchpotato_host, couchpotato_port, couchpotato_apikey, couchpotato_basepath, **kwargs):

        if(couchpotato_basepath == ""):
            couchpotato_basepath = "/"
        if not(couchpotato_basepath.endswith('/')):
            couchpotato_basepath += "/"

        url = 'http://' + couchpotato_host + ':' + couchpotato_port + couchpotato_basepath + 'api/' + couchpotato_apikey
        try:
            return loads(urlopen(url + '/app.available', timeout=10).read())
        except:
            return

    @cherrypy.expose()
    def GetImage(self, url, h=None, w=None, o=None):
        return get_image(url, h, w, o)

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def GetMovieList(self, limit=''):
        return self.fetch('movie.list?status=active&limit_offset=' + limit)

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def GetNotificationList(self, limit='20'):
        data = self.fetch('notification.list?limit_offset=' + limit)
        self.fetch('notification.markread')
        return data

    @cherrypy.expose()
    @cherrypy.tools.json_out()
    def DeleteMovie(self, id=''):
        return self.fetch('movie.delete/?id=' + id)

    @cherrypy.expose()
    @cherrypy.tools.json_out()
{'fraction_non_alphanumeric': 0.1611713665943601, 'fraction_numerical': 0.0021691973969631237, 'mean_word_length': 2.7950617283950616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4588699', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1525, 'n_words': 292}