<commit_before>import mimetypes
import json
import requests
import os
from requests.auth import HTTPBasicAuth

headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
api_url = 'https://girder.local.wholetale.org/api/v1'

try:
    r = requests.get(
        api_url + '/user/authentication', auth=HTTPBasicAuth('admin', 'arglebargle123')
    )
except:
    print('Girder is no longer running')
    exit()
r.raise_for_status()
headers['Girder-Token'] = r.json()['authToken']['token']

ligo_data = [
    "https://losc.ligo.org/s/events/GW170104/H-H1_LOSC_4_V1-1167559920-32.hdf5",
    "https://losc.ligo.org/s/events/GW170104/GW170104_4_template.hdf5",
    "https://losc.ligo.org/s/events/GW150914/GW150914_4_template.hdf5",
    "https://losc.ligo.org/s/events/BBH_events_v3.json",
    "https://losc.ligo.org/s/events/GW151226/GW151226_4_template.hdf5",
    "https://losc.ligo.org/s/events/GW151226/H-H1_LOSC_4_V2-1135136334-32.hdf5",
    "https://losc.ligo.org/s/events/LVT151012/L-L1_LOSC_4_V2-1128678884-32.hdf5",
    "https://losc.ligo.org/s/events/GW170104/L-L1_LOSC_4_V1-1167559920-32.hdf5",
    "https://losc.ligo.org/s/events/LVT151012/LVT151012_4_template.hdf5",
    "https://losc.ligo.org/s/events/LVT151012/H-H1_LOSC_4_V2-1128678884-32.hdf5",
    "https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.hdf5",
    "https://losc.ligo.org/s/events/GW150914/L-L1_LOSC_4_V2-1126259446-32.hdf5",
    "https://losc.ligo.org/s/events/GW151226/L-L1_LOSC_4_V2-1135136334-32.hdf5",
]
# r = requests.get(api_url + '/repository/lookup', params={'dataId': json.dumps(ligo_data)})

ligo_dataMap = [
    {
        'dataId': 'https://www.gw-openscience.org/s/events/BBH_events_v3.json',
        'doi': None,
        'name': 'BBH_events_v3.json',
        'repository': 'HTTP',
        'size': 2202,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW150914/GW150914_4_template.hdf5',
        'doi': None,
        'name': 'GW150914_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW151226/GW151226_4_template.hdf5',
        'doi': None,
        'name': 'GW151226_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW170104/GW170104_4_template.hdf5',
        'doi': None,
        'name': 'GW170104_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW170104/H-H1_LOSC_4_V1-1167559920-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V1-1167559920-32.hdf5',
        'repository': 'HTTP',
        'size': 1033609,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V2-1126259446-32.hdf5',
        'repository': 'HTTP',
        'size': 1040592,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/LVT151012/H-H1_LOSC_4_V2-1128678884-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V2-1128678884-32.hdf5',
        'repository': 'HTTP',
        'size': 1039648,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW151226/H-H1_LOSC_4_V2-1135136334-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V2-1135136334-32.hdf5',
        'repository': 'HTTP',
        'size': 1040336,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW170104/L-L1_LOSC_4_V1-1167559920-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V1-1167559920-32.hdf5',
        'repository': 'HTTP',
        'size': 1005007,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW150914/L-L1_LOSC_4_V2-1126259446-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V2-1126259446-32.hdf5',
        'repository': 'HTTP',
        'size': 1007420,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/LVT151012/L-L1_LOSC_4_V2-1128678884-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V2-1128678884-32.hdf5',
        'repository': 'HTTP',
        'size': 1018496,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW151226/L-L1_LOSC_4_V2-1135136334-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V2-1135136334-32.hdf5',
        'repository': 'HTTP',
        'size': 1022324,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/LVT151012/LVT151012_4_template.hdf5',
        'doi': None,
        'name': 'LVT151012_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
]

r = requests.post(
    api_url + '/dataset/register',
    params={'dataMap': json.dumps(ligo_dataMap)},
    headers=headers,
)

r = requests.get(api_url + '/dataset', headers=headers)
dataSet = [
    {
        'itemId': obj['_id'],
        '_modelType': obj['_modelType'],
        'mountPath': '/' + obj['name'],
    }
    for obj in r.json()
]

r = requests.get(api_url + '/image', params={'text': 'Jupyter'}, headers=headers)
imageId = r.json()[0]['_id']

tale = {
    "authors": "<NAME>",
    "category": "astronomy",
    "dataSet": dataSet,
    "description": (
        "### LIGO Detected Gravitational Waves from Black Holes\nOn September 14,"
        "2015 at 5:51 a.m. Eastern Daylight Time (09:51 UTC), the twin Laser Inte"
        "rferometer Gravitational-wave Observatory (LIGO) detectors, located in L"<commit_msg>Do not pass a leading slash during LIGO registration<commit_after>import mimetypes
import json
import requests
import os
from requests.auth import HTTPBasicAuth

headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
api_url = 'https://girder.local.wholetale.org/api/v1'

try:
    r = requests.get(
        api_url + '/user/authentication', auth=HTTPBasicAuth('admin', '<PASSWORD>')
    )
except:
    print('Girder is no longer running')
    exit()
r.raise_for_status()
headers['Girder-Token'] = r.json()['authToken']['token']

ligo_data = [
    "https://losc.ligo.org/s/events/GW170104/H-H1_LOSC_4_V1-1167559920-32.hdf5",
    "https://losc.ligo.org/s/events/GW170104/GW170104_4_template.hdf5",
    "https://losc.ligo.org/s/events/GW150914/GW150914_4_template.hdf5",
    "https://losc.ligo.org/s/events/BBH_events_v3.json",
    "https://losc.ligo.org/s/events/GW151226/GW151226_4_template.hdf5",
    "https://losc.ligo.org/s/events/GW151226/H-H1_LOSC_4_V2-1135136334-32.hdf5",
    "https://losc.ligo.org/s/events/LVT151012/L-L1_LOSC_4_V2-1128678884-32.hdf5",
    "https://losc.ligo.org/s/events/GW170104/L-L1_LOSC_4_V1-1167559920-32.hdf5",
    "https://losc.ligo.org/s/events/LVT151012/LVT151012_4_template.hdf5",
    "https://losc.ligo.org/s/events/LVT151012/H-H1_LOSC_4_V2-1128678884-32.hdf5",
    "https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.hdf5",
    "https://losc.ligo.org/s/events/GW150914/L-L1_LOSC_4_V2-1126259446-32.hdf5",
    "https://losc.ligo.org/s/events/GW151226/L-L1_LOSC_4_V2-1135136334-32.hdf5",
]
# r = requests.get(api_url + '/repository/lookup', params={'dataId': json.dumps(ligo_data)})

ligo_dataMap = [
    {
        'dataId': 'https://www.gw-openscience.org/s/events/BBH_events_v3.json',
        'doi': None,
        'name': 'BBH_events_v3.json',
        'repository': 'HTTP',
        'size': 2202,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW150914/GW150914_4_template.hdf5',
        'doi': None,
        'name': 'GW150914_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW151226/GW151226_4_template.hdf5',
        'doi': None,
        'name': 'GW151226_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW170104/GW170104_4_template.hdf5',
        'doi': None,
        'name': 'GW170104_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW170104/H-H1_LOSC_4_V1-1167559920-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V1-1167559920-32.hdf5',
        'repository': 'HTTP',
        'size': 1033609,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V2-1126259446-32.hdf5',
        'repository': 'HTTP',
        'size': 1040592,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/LVT151012/H-H1_LOSC_4_V2-1128678884-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V2-1128678884-32.hdf5',
        'repository': 'HTTP',
        'size': 1039648,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW151226/H-H1_LOSC_4_V2-1135136334-32.hdf5',
        'doi': None,
        'name': 'H-H1_LOSC_4_V2-1135136334-32.hdf5',
        'repository': 'HTTP',
        'size': 1040336,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW170104/L-L1_LOSC_4_V1-1167559920-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V1-1167559920-32.hdf5',
        'repository': 'HTTP',
        'size': 1005007,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW150914/L-L1_LOSC_4_V2-1126259446-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V2-1126259446-32.hdf5',
        'repository': 'HTTP',
        'size': 1007420,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/LVT151012/L-L1_LOSC_4_V2-1128678884-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V2-1128678884-32.hdf5',
        'repository': 'HTTP',
        'size': 1018496,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/GW151226/L-L1_LOSC_4_V2-1135136334-32.hdf5',
        'doi': None,
        'name': 'L-L1_LOSC_4_V2-1135136334-32.hdf5',
        'repository': 'HTTP',
        'size': 1022324,
    },
    {
        'dataId': 'https://www.gw-openscience.org/s/events/LVT151012/LVT151012_4_template.hdf5',
        'doi': None,
        'name': 'LVT151012_4_template.hdf5',
        'repository': 'HTTP',
        'size': 1056864,
    },
]

r = requests.post(
    api_url + '/dataset/register',
    params={'dataMap': json.dumps(ligo_dataMap)},
    headers=headers,
)

r = requests.get(api_url + '/dataset', headers=headers)
dataSet = [
    {
        'itemId': obj['_id'],
        '_modelType': obj['_modelType'],
        'mountPath': obj['name'],
    }
    for obj in r.json()
]

r = requests.get(api_url + '/image', params={'text': 'Jupyter'}, headers=headers)
imageId = r.json()[0]['_id']

tale = {
    "authors": "<NAME>",
    "category": "astronomy",
    "dataSet": dataSet,
    "description": (
        "### LIGO Detected Gravitational Waves from Black Holes\nOn September 14,"
        "2015 at 5:51 a.m. Eastern Daylight Time (09:51 UTC), the twin Laser Inte"
        "rferometer Gravitational-wave Observatory (LIGO) detectors, located in L"
{'fraction_non_alphanumeric': 0.18310999190574692, 'fraction_numerical': 0.1315765806277543, 'mean_word_length': 2.7618403247631935, 'pattern_counts': {'":': 8, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 54, 'lorem ipsum': 0, 'www.': 26, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5348346', 'n_tokens_mistral': 5572, 'n_tokens_neox': 4874, 'n_words': 515}