import sys
sys.path.insert(0, '.')

import getpass

from docopt import docopt

from dmapiclient import DataAPIClient

from dmscripts.env import get_api_endpoint_from_stage
from dmscripts.logging import configure_logger
from dmscripts.framework_utils import set_framework_result


logger = configure_logger()

if __name__ == '__main__':
    arguments = docopt(__doc__)

    framework_slug = arguments['<framework>']
    data_api_url = get_api_endpoint_from_stage(arguments['<stage>'], 'api')
    client = DataAPIClient(data_api_url, arguments['--api-token'])
    user = getpass.getuser()
    result = True if arguments['--pass'] else False

    with open(arguments['<ids_file>'], 'r') as f:
        supplier_ids = filter(None, [l.strip() for l in f.readlines()])

    for supplier_id in supplier_ids:
        logger.info(set_framework_result(client, framework_slug, supplier_id, result, user))
"""
import sys

sys.path.insert(0, ".")

import re
from docopt import docopt
from dateutil.parser import parse as parse_time

from dmutils.s3 import S3
from dmutils.formats import DATETIME_FORMAT

from dmscripts import logging

logger = logging.configure_logger()


def make_copier(src_bucket, target_bucket):
    def copy_file_with_content_disposition(src_path, target_path, download_filename):
        src_key = src_bucket.bucket.get_key(src_path)
        target_bucket.bucket.copy_key(
            target_path,
            src_bucket_name=src_bucket.bucket_name,
            src_key_name=src_path,
            preserve_acl=True,
            metadata={
                "timestamp": parse_time(src_key.last_modified).strftime(DATETIME_FORMAT),
                "Content-Disposition": 'attachment; filename="{}"'.format(download_filename),
            },
        )
if __name__ == "__main__":
    from docopt import docopt
    args = docopt(__doc__)

    client = DataAPIClient(get_api_endpoint_from_stage(args["<stage>"], "api"), args["<api_token>"])
    updated_by = args["--updated-by"] or getpass.getuser()

    declaration_definite_pass_schema = json.load(open(args["<declaration_definite_pass_schema_path>"], "r"))

    declaration_baseline_schema = \
        (declaration_definite_pass_schema.get("definitions") or {}).get("baseline")

    service_schema = json.load(
        open(args["<draft_service_schema_path>"], "r")
    ) if args["<draft_service_schema_path>"] else None

    configure_logger({"script": loglevel_DEBUG if args["--verbose"] else loglevel_INFO})

    mark_definite_framework_results(
        client,
        updated_by,
        args["<framework_slug>"],
        declaration_definite_pass_schema,
        declaration_baseline_schema=declaration_baseline_schema,
        service_schema=service_schema,
        reassess_passed=args["--reassess-passed-sf"],
        reassess_failed=args["--reassess-failed-sf"],
        reassess_failed_draft_services=args["--reassess-failed-draft-services"],
        dry_run=args["--dry-run"],
    )
    scripts/export-dos-participants.py <stage> <api_token> <content_path>
"""
import sys
sys.path.insert(0, '.')

import csv
from docopt import docopt
from dmscripts.env import get_api_endpoint_from_stage
from dmscripts.export_dos_suppliers import (
    FRAMEWORK_SLUG, find_services_by_lot, make_fields_from_content_questions, write_csv
)
from dmapiclient import DataAPIClient
from dmutils.content_loader import ContentLoader
from dmscripts.logging import configure_logger, WARNING

logger = configure_logger({"dmapiclient": WARNING})


def find_all_participants(client):
    return find_services_by_lot(client, FRAMEWORK_SLUG, "user-research-participants")


def make_row(content_manifest):
    question_ids = ["recruitMethods", "recruitFromList", "locations"]
    questions = [content_manifest.get_question(question_id) for question_id in question_ids]
    for question in questions:
        print(question["id"], question.fields, question.id)

    def inner(record):
        row = [
            ("supplier_id", record["supplier_id"]),
import sys
from multiprocessing.pool import ThreadPool
import six
from six.moves import map
from datetime import datetime

import backoff
from docopt import docopt

import dmapiclient

sys.path.insert(0, '.')
from dmscripts.env import get_api_endpoint_from_stage
from dmscripts import logging

logger = logging.configure_logger({'dmapiclient': logging.WARNING})


def request_services(api_url, api_access_token, frameworks):

    data_client = dmapiclient.DataAPIClient(
        api_url,
        api_access_token
    )

    return data_client.find_services_iter(framework=frameworks)


def print_progress(counter, start_time):
    if counter % 100 == 0:
        time_delta = datetime.utcnow() - start_time
"""

import sys
import multiprocessing
from six.moves import map
from datetime import datetime

import backoff
from docopt import docopt
from dmutils import apiclient

sys.path.insert(0, '.')
from dmscripts.env import get_api_endpoint_from_stage
from dmscripts import logging

logger = logging.configure_logger({'dmutils': logging.WARNING})


def request_services(api_url, api_access_token, page=1):

    data_client = apiclient.DataAPIClient(
        api_url,
        api_access_token
    )

    for service in data_client.find_services_iter():
        yield service


def print_progress(counter, start_time):
    if counter % 100 == 0: