Beispiel #1
0
    def _anything_1(self,*args):
        tosearch = []
        for arg in args:
            tosearch.append(str(arg))
        self.input = ' '.join(tosearch)
        if hasattr(self, 'howmany'):
            howmany = self.howmany
        dbgmsg = "%s%d%s%s" % ("getting ", self.howmany, " results about: ", self.input)
        self._outlet(4, dbgmsg)
        for tweet in Twitter().search(self.input, cached=False)[:howmany]:
            author = encode_utf8(plaintext(tweet.author))
            date = encode_utf8(plaintext(tweet.date))
	    description = encode_utf8(plaintext(tweet.description))    
            self._outlet(1, description)
            self._outlet(2, author)
            self._outlet(3, date)
def extract_tvseries(dom):
    '''
    Extract a list of highest ranking TV series from DOM (of IMDB page).

    Each TV series entry should contain the following fields:
    - TV Title
    - Ranking
    - Genres (comma separated if more than one)
    - Actors/actresses (comma separated if more than one)
    - Runtime (only a number!)
    '''

    tvseries = []

    # iterates over top 50 IMBD tv series
    for tvserie in dom.by_tag("td.title")[:50]:
        tvserie_array = []
        genres_array = []
        actors_array = []
        # tv serie title is encoded and added to tv serie array
        title = tvserie("a")[0].content
        tvserie_array.append(encode_utf8(title))
        # tv serie ranking is encoded and added to tv serie array
        ranking = tvserie("span.value")[0].content
        tvserie_array.append(encode_utf8(ranking))
        # tv serie genres are added to tv serie array
        for genres in tvserie("span.genre a"):
            # genre is encoded and added to genres array
            genres_array.append(encode_utf8(genres.content))
        # seprates genres with commas
        genres = COMMA.join(genres_array)
        tvserie_array.append(genres)
        # tv serie actors are added to tv serie array
        for actors in tvserie("span.credit a"):
            # actor is encoded and added to actors array
            actors_array.append(encode_utf8(actors.content))
        # seprates actors with commas
        actors = COMMA.join(actors_array)
        tvserie_array.append(actors)
        # tv serie runtime is encoded and stripped to numbers
        runtime = encode_utf8(tvserie("span.runtime")[0].content)
        runtime = runtime.rstrip(' mins.')
        tvserie_array.append(runtime)
        tvseries.append(tvserie_array)

    return tvseries
Beispiel #3
0
    def _anything_1(self,*args):

        #default vars
        varservice = 'imap.gmail.com'
        varport = 993
        varsecure = True
        varfolder = 'inbox'
        varquery = ''
        varfield = 'subject'
        howmany = 1

        if hasattr(self, 'service'):
            varservice = self.service
        if hasattr(self, 'port'):
            varport = self.port
        if hasattr(self, 'folder'):
            varfolder = self.folder
        if hasattr(self, 'search'):
            varquery = self.search
        if hasattr(self, 'howmany'):
            howmany = self.howmany

        if hasattr(self, 'username') and hasattr(self, 'passw'):
            self.input = str(args[0])
            mail = Mail(self.username, self.passw, service=varservice, port=varport)
            if self.input == "search":
                mailres = getattr(mail,varfolder).search(varquery, field=varfield)
                for amail in mailres[:howmany]:
                    m = getattr(mail,varfolder).read(amail)
                    self._outlet(2, encode_utf8(plaintext(m.author)))
                    self._outlet(3, encode_utf8(plaintext(m.subject)))
                    self._outlet(4, encode_utf8(plaintext(m.body)))
                    self._outlet(5, m.attachments)
            elif self.input == "getf":
                print mail.folders
                for folder in mail.folders.keys():
                    self._outlet(1, folder)
        else:
            self._outlet(6, "you need to insert username and password inlets")
Beispiel #4
0
 def test_encode_utf8(self):
     # Assert Python bytestring.
     for s in self.strings:
         self.assertTrue(isinstance(web.encode_utf8(s), str))
     print "pattern.web.encode_utf8()"
Beispiel #5
0
 def test_encode_utf8(self):
     # Assert Python bytestring.
     for s in self.strings:
         self.assertTrue(isinstance(web.encode_utf8(s), str))
     print "pattern.web.encode_utf8()"
Beispiel #6
0
    def _anything_1(self,*args):

        #default vars
        varstart=1
        varcount=10
        varsort='relevancy'
        varsize='medium'
        download=False
        outpath=tempfile.gettempdir()

        tosearch = []
        for arg in args:
            tosearch.append(str(arg))
        self.input = ' '.join(tosearch)

        if hasattr(self, 'start'):
            varstart = self.start
        if hasattr(self, 'count'):
            varcount = self.count
        if hasattr(self, 'sort'):
            varsort = self.sort
        if hasattr(self, 'size'):
            varsize = self.size
        if hasattr(self, 'download'):
            download = self.download
        if hasattr(self, 'outpath'):
            outpath = os.path.abspath(self.outpath)
        dbgmsg = "%s%d%s%d%s%s%s%s%s%s%s%s%s%s" % ("start:", varstart, " count:", varcount, " sort:", varsort, " size:", varsize, " search:", self.input, " download:", download, " output path:", outpath)
        self._outlet(5, dbgmsg)

        engine = Flickr(license=None)
        results = engine.search(self.input, start=varstart, count=varcount, sort=varsort, size=varsize, cached=False)

        if (download):
            now = datetime.datetime.now()
            timenow = "%s%s%s" % (self.input, "_", now.strftime('%Y%m%d-%H%M'))
            pathdir = os.path.join(outpath, timenow)
            if not os.path.isdir(pathdir):
                os.mkdir(pathdir)
                output = "%s%s" % ("created: ", str(pathdir))
                self._outlet(5, output)

        for img in results:
            author = encode_utf8(plaintext(img.author))
	    description = encode_utf8(img.description)
            url = encode_utf8(img.url)
            self._outlet(1, description)
            self._outlet(2, author)
            self._outlet(3, url)
            if (download):
                if url != "None":
                    data = img.download()
                    filename = img.url.rsplit("/",1)[1]
                    pathfile = os.path.join(pathdir, filename)
                    f = open(pathfile, "w")
                    f.write(data)
                    f.close()
                    output = "%s%s" % ("downloaded: ", str(pathfile))
                    self._outlet(5, output)

        if (download):
            self._outlet(4, str(pathdir))