示例#1
0
文件: rie.py 项目: WillemJan/Misc
class get:
    def __init__(self):
        self.api = API()

    def __strclean__(self, strin):
        # Clean those evil strings.
        strout = ""
        for item in strin:
            if not item.find('http') > -1:
                if item.isalpha():
                    strout += item
                else:
                    strout += " "
        strout = strout.strip()
        return (strout.split(' '))

    def GET(self, path):
        try:
            # Get parsed Europeana fullrecord-data from url.
            fullrecord = self.api.get_parse_europeana_object(escapejs(path))
        except:
            # Else return empty record.
            return ({})

        words = []
        for item in fullrecord.keys():
            word_list = self.__strclean__(fullrecord[item])
            for word in word_list:
                if len(word) > 4:
                    words.append(word)
        fullrecord["word"] = words

        return (simplejson.dumps(fullrecord))
示例#2
0
class get:
    def __init__(self):
        self.api= API()
    def GET(self,path):
        url=self.api.get_parse_europeana_object(path)
        if "object" in url.keys():
            try:
                f = urllib2.urlopen(url["object"])
                if "content-type" in f.headers.keys():
                    return(simplejson.dumps(url))
            except:
                url["object"] = "http://www.lokaal.lan/blackcat.gif"
        else:
            url["object"] = "http://www.lokaal.lan/blackcat.gif"
        return(simplejson.dumps(url))
示例#3
0
class get:
    def __init__(self):
        self.api = API()

    def __strclean__(self, strin):
        # Clean those evil strings.
        strout = ""
        for item in strin:
            if not item.find('http') > -1:
                if item.isalpha():
                    strout += item
                else:
                    strout += " "
        strout = strout.strip()
        return (strout.split(' '))

    def GET(self, path):
        try:
            # Get parsed Europeana fullrecord-data from url.
            if path.find('/www.europeana.eu/portal/') > -1:
                fullrecord = self.api.get_parse_europeana_object(
                    escapejs(path))
        except:
            # Else return empty record.
            return ({})

        words = []
        for item in fullrecord.keys():
            word_list = self.__strclean__(fullrecord[item])
            for word in word_list:
                if len(word) > 4:
                    words.append(word)
        fullrecord["word"] = words
        referer = web.ctx.env.get('HTTP_REFERER')
        if referer:
            if referer.startswith(
                    'http://www.europeana.fe2.nl') or referer.startswith(
                        'http://europeana.fe2.nl'):
                return (simplejson.dumps(fullrecord))
            else:
                return (
                    '<a href="http://europeana.fe2.nl/">http://europeana.fe2.nl/</a>'
                )
        return (
            '<a href="http://europeana.fe2.nl/">http://europeana.fe2.nl/</a>')
示例#4
0
文件: euro.py 项目: WillemJan/Misc
class get:
    def __init__(self):
        self.api = API()

    def GET(self, path):

        url = self.api.get_parse_europeana_object(path)
        words = []
        for word in url["description"].split(' ') + url["title"].split(' '):
            if len(word) > 4:
                if word.isalpha():
                    words.append(word)
        url["word"] = words
        if "object" in url.keys():
            try:
                f = urllib2.urlopen(url["object"], timeout=1)
                if "content-type" in f.headers.keys():
                    return (simplejson.dumps(url))
            except:
                url["object"] = "http://www.lokaal.lan/blackcat.gif"
        else:
            url["object"] = "http://www.lokaal.lan/blackcat.gif"
        return (simplejson.dumps(url))