def retrieve_n_questions():
    result = []
    for i in range(100):
        url = 'https://api.stackexchange.com/2.2/questions?tagged=postgres&filter=withbody&page=' + str(i+1) + '&pagesize=100&order=asc&sort=creation&site=stackoverflow'
        result.append(request_to_api(url))
        logger.log_request(retrieve_n_questions.__name__, url)
    return result
Пример #2
0
def create_payment(order_id,
                   access_token,
                   transaction_amount,
                   transaction_text,
                   customer_number,
                   express_checkout=False,
                   is_app=False):
    """
    Creates a initiate payment request to Vipps.

    :param express_checkout: Boolean for enabling express checkout.
    :param order_id: ID for the transaction.
    :param access_token: A token for authorizing the request to Vipps.
    :param transaction_amount: The amount to reserve for the transaction.
    :param transaction_text: The text attached to the transaction.
    :param customer_number:  The number for the Vipps account that will pay for the transaction.
    :return: The response for the initiate payment request, as JSON.
    """
    url = base_url + '/ecomm/v2/payments'
    headers = get_base_ecom_headers(access_token)
    body = get_initiate_payment_http_body(order_id,
                                          transaction_amount,
                                          transaction_text,
                                          customer_number,
                                          express_checkout=express_checkout,
                                          is_app=is_app)
    response = requests.post(url=url, headers=headers, json=body)
    log_request(__name__ + ".create_payment",
                headers=headers,
                body=body,
                response=response.json())
    return response.json()
Пример #3
0
def retrieve_n_questions():
    result = []
    for i in range(100):
        url = 'https://api.stackexchange.com/2.2/questions?tagged=postgres&filter=withbody&page=' + str(
            i + 1) + '&pagesize=100&order=asc&sort=creation&site=stackoverflow'
        result.append(request_to_api(url))
        logger.log_request(retrieve_n_questions.__name__, url)
    return result
Пример #4
0
def cancel_order(order_id, access_token, transaction_text):
    """
    Sends a cancel order request for the provided order id.

    :param order_id: ID for the transaction
    :param access_token: A token for authorizing the request to Vipps.
    :param transaction_text: Text describing the cancel request.
    :return: Response for the cancel order request, as JSON.
    """
    url = base_url + '/ecomm/v2/payments/{order_id}/cancel'.format(
        order_id=order_id)
    headers = get_order_ecom_headers(order_id, access_token)
    body = get_order_ecom_cancel_body(transaction_text)
    response = requests.put(url, headers=headers, json=body)
    log_request(__name__ + ".cancel_order",
                headers=headers,
                body=body,
                response=response.json())
    return response.json()
Пример #5
0
def capture_payment(order_id,
                    access_token,
                    transaction_amount=0,
                    transaction_text="Capture"):
    """
    Captures the reserved payment for the provided order id.

    :param order_id: ID for the transaction.
    :param access_token: A token for authorizing the request to Vipps.
    :param transaction_amount: The amount of the payment to capture, 0 for capturing all.
    :param transaction_text: The associated text for the capture.
    :return: Response for the capture request, as JSON.
    """
    url = base_url + '/ecomm/v2/payments/{order_id}/capture'.format(
        order_id=order_id)
    headers = get_order_ecom_headers(order_id, access_token)
    body = get_capture_payment_http_body(transaction_amount, transaction_text)
    response = requests.post(url=url, headers=headers, json=body)
    log_request(__name__ + ".capture_payment",
                headers=headers,
                body=body,
                response=response.json())
    return response.json()
Пример #6
0
    def GET(self):
        """get one-time token from youtube, exchange for session token"""
        params = urlparse.parse_qs(web.ctx.query[1:])
        if 'token' not in params.keys():
            return 'No youtube session token given'
        one_time_token = params['token'][0]
        youtube.upgrade_token(one_time_token)
        if 'artist' not in params.keys():
            return "please enter an artist"
        if 'album' not in params.keys():
            return "please enter an album"
        artist = params['artist'][0]
        album = params['album'][0]
        logger.log_request("%s, %s, %s, %s" % (datetime.now(), web.ctx.ip, artist, album))
        title = "%s %s" % (artist, album)
        summary = "%s by %s. Playlist generated by AlbumFinder" % (album, artist)
        try:
            album_videos = list(get_album_videos(artist, album))
        except amazonproduct.api.NoExactMatchesFound as e:
            logger.log_error("not found: %s, %s" % (artist, album))
            error_messages.append('Sorry, that album could not be found.')
            return web.seeother('/')

        try:
            playlist_id = youtube.add_playlist(title, summary)
            for video_id in album_videos:
                youtube.add_video_to_playlist(video_id, playlist_id)
            web.seeother("/show_playlist?playlist_id=%s" % playlist_id)
        except gdata.service.RequestError as e:
            if re.search('Playlist already exists', str(e)):
                logger.log_error("already exists: %s" % title)
                error_messages.append('Sorry, that playlist already exists.')
                # get playlist id and show it
            else:
                logger.log_error(str(e))
                raise e
        web.seeother('/')
Пример #7
0
def retrieve_comments_for_posts(posts_ids):
    posts_string = ';'.join(posts_ids)
    url = 'https://api.stackexchange.com/2.2/posts/' + posts_string + '/comments?order=desc&sort=creation&site=stackoverflow'
    result = request_to_api(url)
    logger.log_request(retrieve_comments_for_posts.__name__, url)
    return result
Пример #8
0
def retrieve_answers_for_questions(questions_ids):
    questions_string = ';'.join(questions_ids)
    url = 'https://api.stackexchange.com/2.2/questions/' + questions_string + '/answers?order=desc&sort=activity&site=stackoverflow'
    result = request_to_api(url)
    logger.log_request(retrieve_answers_for_questions.__name__, url)
    return result
Пример #9
0
def retrieve_multiple_users(users_ids_list):
    users_string = ';'.join(users_ids_list)
    url = 'https://api.stackexchange.com/2.2/users/' + users_string + '?page=1&pagesize=100&order=desc&sort=reputation&site=stackoverflow'
    result = request_to_api(url)
    logger.log_request(retrieve_multiple_users.__name__, url)
    return result
Пример #10
0
def retrieve_comments_for_posts(posts_ids):
    posts_string = ';'.join(posts_ids)
    url = 'https://api.stackexchange.com/2.2/posts/' + posts_string + '/comments?order=desc&sort=creation&site=stackoverflow'
    result = request_to_api(url)
    logger.log_request(retrieve_comments_for_posts.__name__, url)
    return result
Пример #11
0
def retrieve_answers_for_questions(questions_ids):
    questions_string = ';'.join(questions_ids)
    url = 'https://api.stackexchange.com/2.2/questions/' + questions_string + '/answers?order=desc&sort=activity&site=stackoverflow'
    result = request_to_api(url)
    logger.log_request(retrieve_answers_for_questions.__name__, url)
    return result
Пример #12
0
def retrieve_multiple_users(users_ids_list):
    users_string = ';'.join(users_ids_list)
    url = 'https://api.stackexchange.com/2.2/users/' + users_string + '?page=1&pagesize=100&order=desc&sort=reputation&site=stackoverflow'
    result = request_to_api(url)
    logger.log_request(retrieve_multiple_users.__name__, url)
    return result