<commit_before>import soundcloud, time, json
from tornado import gen, web
from housepy import log, util, config
from ingest import save_files

"""Expecting JSON or form metadata with Member and a timestamp in UTC"""

settings = config['soundcloud']
try:
    client = soundcloud.Client(
        client_id=settings['client_id'],
        client_secret=settings['client_secret'],
        username=settings['email'],
        password=settings['password']
    )
except Exception as e:
    log.error("Could not establish SoundCloud client: %s" % log.exc(e))

def parse(request):
    log.info("audio.parse")

    paths = save_files(request)
    if not len(paths):
        return None, "No files"

    # process the json
    data = None
    for path in paths:
        if path[-4:] == "json":
            try:
                with open(path) as f:
                    data = json.loads(f.read())
            except Exception as e:
                log.error(log.exc(e))
                return None, "Could not parse"
            break
    if data is None:
        return None, "No data"          

    # process the audio
    for path in paths:
        if path[-4:] != "json":
            break

    """Would be nice to have Member with this"""
    member = "%s: " % data['Member'] if 'Member' in data else ""
    notes = data['Notes'] if 'Notes' in data else ""
    title = "%s%s" % (member, notes)
    if not len(title.strip()):
        title = util.datestring(data['t_utc'], tz=config['local_tz'])
    soundcloud_url = post_track(path, title)#yield gen.Task(post_track, path)
    log.debug("yielded")
    if soundcloud_url is None:
        return None, "Could not post to Soundcloud"
    data['SoundCloudURL'] = soundcloud_url<commit_msg>audio naming issue<commit_after>import soundcloud, time, json
from tornado import gen, web
from housepy import log, util, config
from ingest import save_files

"""Expecting JSON or form metadata with Member and a timestamp in UTC"""

settings = config['soundcloud']
try:
    client = soundcloud.Client(
        client_id=settings['client_id'],
        client_secret=settings['client_secret'],
        username=settings['email'],
        password=settings['password']
    )
except Exception as e:
    log.error("Could not establish SoundCloud client: %s" % log.exc(e))

def parse(request):
    log.info("audio.parse")

    paths = save_files(request)
    if not len(paths):
        return None, "No files"

    # process the json
    data = None
    for path in paths:
        if path[-4:] == "json":
            try:
                with open(path) as f:
                    data = json.loads(f.read())
            except Exception as e:
                log.error(log.exc(e))
                return None, "Could not parse"
            break
    if data is None:
        return None, "No data"          

    # process the audio
    for path in paths:
        if path[-4:] != "json":
            break

    if 'TeamMember' in data:
        data['Member'] = data['TeamMember']
        del data['TeamMember']              
    member = "%s: " % data['Member'] if 'Member' in data else ""
    notes = data['Notes'] if 'Notes' in data else ""
    title = "%s%s" % (member, notes)
    if not len(title.strip()):
        title = util.datestring(data['t_utc'], tz=config['local_tz'])
    soundcloud_url = post_track(path, title)#yield gen.Task(post_track, path)
    log.debug("yielded")
    if soundcloud_url is None:
        return None, "Could not post to Soundcloud"
    data['SoundCloudURL'] = soundcloud_url
{'fraction_non_alphanumeric': 0.11941143180531975, 'fraction_numerical': 0.0011318619128466328, 'mean_word_length': 2.438715953307393, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3254793', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1017, 'n_words': 329}