コード例 #1
0
def twitter_query(context):
    '''
    Gets user ids, and feeds them into a function to query twitter.
    '''
    input_file = context['input']
    auth_file = context['auth']
    id_list = get_id_list(input_file)
    offset = context['start_idx_input']
    start_idx = context['start_idx_api']

    log('Creating oauth pool...')
    api_pool = kids_pool(auth_file, start_idx=start_idx, verbose=1)

    for i, user_id in enumerate(id_list[offset:]):
        if i == 0:  # first cursor, only if flag is set.
            cursor = context['cursor']
        else:
            cursor = -1
        filename, s3_filename, s3_id_key = get_user_id_file(user_id, context)
        if not s3.exists(s3_id_key):
            query_user_friends_ids(filename, user_id, api_pool, cursor=cursor)
            log('Sending file to s3: {}'.format(s3_filename))
            s3.disk_2_s3(filename, s3_filename)
            s3.disk_2_s3(context['log'], context['s3_log'])
            os.remove(filename)
            # send an update to s3 after each iteration!
            s3.disk_2_s3(context['log'], context['s3_log'])
        else:
            log('{} already queried!!!'.format(user_id))
        log('>>> {} out of {}'.format(i + offset, len(id_list)))
        time.sleep(1)
コード例 #2
0
ファイル: app.py プロジェクト: jonasdahl/zfinger
def user_image_resize(user, size):
    tmp = False
    if s3.exists(personal(path(user))):
        tmp = BytesIO(s3.get(personal(path(user)))['Body'].read())
    elif s3.exists(original(path(user))):
        tmp = BytesIO(s3.get(original(path(user)))['Body'].read())

    if tmp:
        image = Image.open(tmp)
        image.thumbnail((size, size), Image.ANTIALIAS)
        tmp = BytesIO()
        image.save(tmp, 'JPEG')
        tmp.seek(0)
        return Response(tmp, content_type='image/jpeg')
    else:
        return missing
コード例 #3
0
ファイル: buildbot.py プロジェクト: Jshauk/sumatrapdf
def stats_for_ver(ver):
	local_path = os.path.join(get_stats_cache_dir(), ver + ".txt")
	if not os.path.exists(local_path):
		s3_path = "sumatrapdf/buildbot/%s/stats.txt" % ver
		if not s3.exists(s3_path): return None
		s3.download_to_file(s3_path, local_path)
		assert(os.path.exists(local_path))
	return Stats(local_path)
コード例 #4
0
ファイル: buildbot.py プロジェクト: kun2008/Sumatrapdf_ocx
def stats_for_ver(ver):
	local_path = os.path.join(get_stats_cache_dir(), ver + ".txt")
	if not os.path.exists(local_path):
		s3_path = "sumatrapdf/buildbot/%s/stats.txt" % ver
		if not s3.exists(s3_path): return None
		s3.download_to_file(s3_path, local_path)
		assert(os.path.exists(local_path))
	return Stats(local_path)
コード例 #5
0
ファイル: app.py プロジェクト: jonasdahl/zfinger
def me():
    user = verify_token(request.args.get('token'))
    if user:
        return jsonify({
            'uid': user,
            'personal': s3.exists(personal(path(user)))
        })
    else:
        return jsonify({
            'uid': 'unknown',
            'personal': False
        })
コード例 #6
0
ファイル: app.py プロジェクト: jonasdahl/zfinger
def user_image(user):
    if request.method == 'GET':
        if s3.exists(personal(path(user))):
            obj = s3.get(personal(path(user)))
            return send_file(obj['Body'], mimetype=obj['ContentType'])
        elif s3.exists(original(path(user))):
            obj = s3.get(original(path(user)))
            return send_file(obj['Body'], mimetype=obj['ContentType'])
        else:
            return Response(missing, content_type='image/svg+xml')

    elif request.method == 'POST' and verify_token(request.args.get('token')):
        image = request.files['file']
        mimetype = from_buffer(image.stream.read(1024), mime=True)
        s3.put(personal(path(user)), image, mimetype)
        return 'Personal image uploaded successfully'

    elif request.method == 'DELETE' and verify_token(request.args.get('token')):
        s3.delete(personal(path(user)))
        return 'Personal image deleted successfully'
    else:
        return 'You can only edit you own picture!'
コード例 #7
0
ファイル: test_s3.py プロジェクト: noverde/serpens
    def test_exists_succeeded(self, m_boto3):
        aws_response = {
            "Contents": [{
                "Key": "foo.pdf",
                "LastModified": "",
                "ETag": "da6342837a42ed4316d53bc2d8cebd33",
                "Size": 15327,
                "StorageClass": "STANDARD",
            }]
        }
        m_boto3.client.return_value.list_objects_v2.return_value = aws_response
        response = s3.exists("bar", "baz")

        self.assertTrue(response)
        m_boto3.client.return_value.list_objects_v2.assert_called_once()