Exemple #1
0
    def save_export_files(project, now, get_args, data, md5, name):
        """ Generate two files: meta info and result file and store them locally for logging
        """
        filename_results = os.path.join(settings.EXPORT_DIR, name + '.json')
        filename_info = os.path.join(settings.EXPORT_DIR, name + '-info.json')
        annotation_number = Annotation.objects.filter(
            task__project=project).count()
        info = {
            'project': {
                'title': project.title,
                'id': project.id,
                'created_at':
                project.created_at.strftime('%Y-%m-%dT%H:%M:%SZ'),
                'created_by': project.created_by.email,
                'task_number': project.tasks.count(),
                'annotation_number': annotation_number
            },
            'platform': {
                'version': version.get_git_version()
            },
            'download': {
                'GET': dict(get_args),
                'time': now.strftime('%Y-%m-%dT%H:%M:%SZ'),
                'result_filename': filename_results,
                'md5': md5
            }
        }

        with open(filename_results, 'w') as f:
            f.write(data)
        with open(filename_info, 'w') as f:
            json.dump(info, f, ensure_ascii=False)
        return filename_results
Exemple #2
0
"""
import json
import logging
import os
import requests
import urllib
import attr

from django.db.models import Q, F, Count
from django.conf import settings
from requests.adapters import HTTPAdapter
from core.version import get_git_version
from data_export.serializers import ExportDataSerializer
from users.models import Token

version = get_git_version()
logger = logging.getLogger(__name__)


class BaseHTTPAPI(object):
    MAX_RETRIES = 2
    HEADERS = {
        'User-Agent': 'heartex/' + (version or ''),
    }
    CONNECTION_TIMEOUT = 1.0  # seconds
    TIMEOUT = 100.0  # seconds

    def __init__(self,
                 url,
                 timeout=None,
                 connection_timeout=None,