Пример #1
0
def process_collect_statuses(q, i):
    while True:
        try:
            friend = q.get(True, timeout=5)
        except Empty:
            return

        out = os.path.join(outdir, config.friend_statuses_filename(friend['id'], friend['name']))
        msgs = []
        page_url = None
        while True:
            r = fb_call(friend['id'], section='statuses', params={'limit':100}, page_url=page_url)
            if 'data' in r:
                d = r
            elif 'statuses' in r and 'data' in r['statuses']:
                d = r['statuses']
            else:
                break

            for status in d['data']:
                if 'message' in status:
                    msgs.append(status['message'])

            if 'paging' not in r or 'next' not in d['paging']:
                break
            page_url = d['paging']['next']
        data = {'id': friend['id'], 'name': friend['name'], 'statuses': msgs}
        with open(out, 'w') as f:
            f.write(json.dumps(data, indent=4, sort_keys=True))
Пример #2
0
def friend_statuses(friend_id, friend_name):
    with open(os.path.join(outdir, config.friend_statuses_filename(friend_id, friend_name)),'r') as fin:
        data = json.loads(fin.read())
        try:
            for status in data['statuses']:
                yield status
        except KeyError:
            pass