Example #1
0
    def _read_loop(self, resp):
        data = ''
        while self.running:
            if resp.isclosed():
                break

            # read length
            length = ''
            while True:
                c = resp.read(1)
                if c == '\n':
                    break
                length += c
            length = length.strip()
            if length.isdigit():
                length = int(length)
            else:
                continue

            # read data
            data = resp.read(length)

            # turn json data into status object
            if 'in_reply_to_status_id' in data:
                status = parse_status(json.loads(data), self.api)
                if self.listener.on_status(status) == False:
                    self.running = False
            elif 'delete' in data:
                delete = json.loads(data)['delete']['status']
                if self.listener.on_delete(delete['id'], delete['user_id']) == False:
                    self.running = False
            elif 'limit' in data:
                if self.listener.on_limit(json.loads(data)['limit']['track']) == False:
                    self.running = False
Example #2
0
    def on_data(self, data):
        """Called when raw data is received from connection.

        Override this method if you wish to manually handle
        the stream data. Return False to stop stream and close connection.
        """

        if 'in_reply_to_status_id' in data:
            status = parse_status(json.loads(data), self.api)
            if self.on_status(status) is False:
                return False
        elif 'delete' in data:
            delete = json.loads(data)['delete']['status']
            if self.on_delete(delete['id'], delete['user_id']) is False:
                return False
        elif 'limit' in data:
            if self.on_limit(json.loads(data)['limit']['track']) is False:
                return False
Example #3
0
for user_name in members:
    print user_name
    if not os.path.exists('data/%s.txt' % user_name):
        continue
    f = open('data/%s.txt' % user_name)
    data = json.load(f)

    if is_finding_graph:
        friends = []

    if is_finding_times:
        hour_counts = {}

    for d in data:
        s = parse_status(d,api)

        if is_finding_hashes:
            hashes = find_hash(s.text)
            for h in hashes:
                if not hash2people.has_key(h):
                    hash2people[h] = []
                if not user_name in hash2people[h]:
                    hash2people[h].append(user_name)

        if is_finding_graph:
            """
            build dict:
            members = {'user':['user_mentioned1','user_mentioned2']}
            """
            people = find_hash(s.text,find_mentionings=True)