コード例 #1
0
ファイル: twitterxml.py プロジェクト: kumagi/python-twoauth
    def end_element(self, name):
        # character data strip
        d = self.cdata.strip(" \n")
        self.cdata = unicode()

        # pop mode and set next mode
        mode = self.mode.pop()
        self.nmode = mode

        if d:
            # d = int(d) \
            #    if d.isdigit() and name[-2:] == "id" else d
            if d == "true":
                d = True
            elif d == "false":
                d = False

            if mode:
                # for ids
                self.data.append(d)
            else:
                # string element
                self.data.append([name, d])
        elif self.name and name == self.name[-1]:
            # empty element
            self.data.append([name, None])
        else:
            elements = []
            while self.name.pop() != name:
                elements.append(self.data.pop())

            self.name.append(name)

            if mode:
                if name == "status":
                    self.data.append(twstatus(elements))
                elif name == "user":
                    self.data.append(twuser(elements))
                else:
                    # array element
                    self.data.append(dict(elements))
            else:
                if isinstance(elements[0], (dict, twstatus, twuser)):
                    # array parent
                    self.data.append((name, elements))
                else:
                    # others
                    if name == "status":
                        self.data.append((name, twstatus(elements)))
                    elif name == "user":
                        self.data.append((name, twuser(elements)))
                    elif name == "ids":
                        # for ids
                        self.data.append((name, tuple(elements)))
                    else:
                        self.data.append((name, dict(elements)))
コード例 #2
0
    def end_element(self, name):
        # character data strip
        d = self.cdata.strip(" \n")
        self.cdata = unicode()

        # pop mode and set next mode
        mode = self.mode.pop()
        self.nmode = mode
        
        if d:
            #d = int(d) \
            #    if d.isdigit() and name[-2:] == "id" else d
            if d == "true": d = True
            elif d == "false": d = False
            
            if mode:
                # for ids
                self.data.append(d)
            else:
                # string element
                self.data.append([name, d])
        elif self.name and name == self.name[-1]:
            # empty element
            self.data.append([name, None])
        else:
            elements = []
            while self.name.pop() != name:
                elements.append(self.data.pop())
            
            self.name.append(name)

            if mode:
                if name == "status":
                    self.data.append(twstatus(elements))
                elif name == "user":
                    self.data.append(twuser(elements))
                else:
                    # array element
                    self.data.append(dict(elements))
            else:
                if isinstance(elements[0], (dict, twstatus, twuser)):
                    # array parent
                    self.data.append((name, elements))
                else:
                    # others
                    if name == "status":
                        self.data.append((name, twstatus(elements)))
                    elif name == "user":
                        self.data.append((name, twuser(elements)))
                    elif name == "ids":
                        # for ids
                        self.data.append((name, tuple(elements)))
                    else:
                        self.data.append((name, dict(elements)))
コード例 #3
0
    def __init__(self, d):
        user = dict(d)
        self.data = user

        for i in ("id", "followers_count", "friends_count", "favourites_count",
                  "utc_offset", "statuses_count"):
            setattr(self, i, int(user[i]) if user[i] != None else None)

        for i in ("protected", "following", "verified"):
            setattr(self, i, user[i])

        for i in ("name", "screen_name", "location", "description",
                  "profile_image_url", "url", "time_zone"):
            setattr(self, i, unicode(user[i]) if user[i] != None else None)

        self.created_at = twittertime(user["created_at"])

        if "status" in user.keys():
            self.status = status.twstatus(user["status"])
コード例 #4
0
ファイル: user.py プロジェクト: HemusAran/gae-twibot
 def __init__(self, d):
     user = dict(d)
     self.data = user
     
     for i in ("id", 
               "followers_count", "friends_count", 
               "favourites_count", 
               "utc_offset", "statuses_count"):
         setattr(self, i, int(user[i]) if user[i] != None else None)
     
     for i in ("protected", "following", "verified"):
         setattr(self, i,  user[i])
     
     for i in ("name", "screen_name", "location",
               "description", "profile_image_url",
               "url", "time_zone"):
         setattr(self, i, unicode(user[i]) if user[i] != None else None)
     
     self.created_at = twittertime(user["created_at"])
     
     if "status" in user.keys():
         self.status = status.twstatus(user["status"])
コード例 #5
0
ファイル: streaming.py プロジェクト: nyotamar/gae-twibot
        json_str = None

        self._lock.acquire()
        try:
            json_str, self._buffer = self._buffer.rsplit("\n", 1)
        except ValueError:
            pass
        except Exception, e:
            print >> sys.stderr, "[Error] %s" % e
        finally:
            self._lock.release()

        if json_str == None: return []

        return [
            status.twstatus(i) if "text" in i.keys() else i
            for i in json.loads(u"[%s]" % json_str.replace("\n", ","))
        ]

    def stop(self):
        self.die = True


# Streaming API class
class StreamingAPI:
    def __init__(self, oauth):
        self.oauth = oauth

    def _request(self, path, method="GET", params={}):
        host = "stream.twitter.com"
        url = "http://%s%s" % (host, path)
コード例 #6
0
ファイル: streaming.py プロジェクト: kumagi/python-twoauth
 def pop(self):
     data = self.read()
     if data == None: return []
     
     return [status.twstatus(i) if "text" in i.keys() else i
             for i in json.loads(u"[%s]" % data.strip().replace("\n", ","))]
コード例 #7
0
ファイル: streaming.py プロジェクト: HemusAran/gae-twibot
    def pop(self):
        json_str = None
        
        self._lock.acquire()
        try:
            json_str, self._buffer = self._buffer.rsplit("\n", 1)
        except ValueError:
            pass
        except Exception, e:
            print >>sys.stderr, "[Error] %s" % e
        finally:
            self._lock.release()
        
        if json_str == None: return []
        
        return [status.twstatus(i) if "text" in i.keys() else i
                for i in json.loads(u"[%s]" % json_str.replace("\n", ","))]
    
    def stop(self):
        self.die = True

# Streaming API class
class StreamingAPI:
    def __init__(self, oauth):
        self.oauth = oauth
    
    def _request(self, path, method = "GET", params = {}):
        host = "stream.twitter.com"
        url = "http://%s%s" % (host, path)
        
        # added delimited parameter