<commit_before>
import json
import logging

import requests
from tinyfeedback.helper import send_once as tf


def format_body(run):
    body = {
            'message': run.notes,
            'workout': {
                'duration': run.time,
                'distance': {
                    'value': run.distance ,
                    'units': 'miles',
                },
                'activity_type': 'running',
                'completed_at': run.date.isoformat(),
            }
    }
    return json.dumps(body)


def export_run(run):
    url = 'https://api.dailymile.com/entries.json?oauth_token={}'.format(run.user.dailymile_token)

    body = format_body(run)

    headers = {
            'Content-Type': 'application/json'
    }

    if run.exported_to_dailymile:
        return

    # TODO check that run is not in the future

    response = requests.post(url, data=body, headers=headers)

    if response.status_code == 201:
        run.exported_to_dailymile = True
        run.save()
        tf('users.dailymile.run', {'sent': 1})
    else:
        logging.error(response)
        logging.error(response.json())
        raise Exception<commit_msg>fix tinyfeedback crosspost key<commit_after>
import json
import logging

import requests
from tinyfeedback.helper import send_once as tf


def format_body(run):
    body = {
            'message': run.notes,
            'workout': {
                'duration': run.time,
                'distance': {
                    'value': run.distance ,
                    'units': 'miles',
                },
                'activity_type': 'running',
                'completed_at': run.date.isoformat(),
            }
    }
    return json.dumps(body)


def export_run(run):
    url = 'https://api.dailymile.com/entries.json?oauth_token={}'.format(run.user.dailymile_token)

    body = format_body(run)

    headers = {
            'Content-Type': 'application/json'
    }

    if run.exported_to_dailymile:
        return

    # TODO check that run is not in the future

    response = requests.post(url, data=body, headers=headers)

    if response.status_code == 201:
        run.exported_to_dailymile = True
        run.save()
        tf('openrunlog', {'users.dailymile.run.sent': 1})
    else:
        logging.error(response)
        logging.error(response.json())
        raise Exception
{'fraction_non_alphanumeric': 0.11617021276595745, 'fraction_numerical': 0.003404255319148936, 'mean_word_length': 1.9350811485642947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '5865281', 'n_tokens_mistral': 731, 'n_tokens_neox': 687, 'n_words': 144}