<commit_before>#!/usr/bin/env python3

import soundcloud
from housepy import config, log, util
from mongo import db

def main():

    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))


    features = db.features.find({'properties.FeatureType': "audio", 'properties.SoundCloudURL': None})
    for feature in features:
        log.info("Uploading %s..." % feature['properties']['UploadPath'])
        try:
            path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "uploads", feature['properties']['UploadPath']))
            title = feature['properties']['Title']
            soundcloud_url = upload(path, title)
            db.features.update({'_id': feature['_id']}, {'$set': {'properties.SoundCloudURL': youtube_url}})
        except Exception as e:
            log.error(log.exc(e))


def upload(path, title):
    log.info("Posting %s to soundcloud..." % path)
    try:
        with open(path, 'rb') as f:
            track = {'asset_data': f, 'sharing': "public", 'title': title}
            track = client.post('/tracks', track=track)
            soundcloud_url = track.permalink_url
    except Exception as e:
        log.error("--> could not post track to SoundCloud: %s" % log.exc(e))<commit_msg>query tweak<commit_after>#!/usr/bin/env python3

import soundcloud
from housepy import config, log, util
from mongo import db

def main():

    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))


    features = db.features.find({'properties.FeatureType': "audio", 'properties.SoundCloudURL': {'$exists': True, '$eq': None}})
    for feature in features:
        log.info("Uploading %s..." % feature['properties']['UploadPath'])
        try:
            path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "uploads", feature['properties']['UploadPath']))
            title = feature['properties']['Title']
            soundcloud_url = upload(path, title)
            db.features.update({'_id': feature['_id']}, {'$set': {'properties.SoundCloudURL': youtube_url}})
        except Exception as e:
            log.error(log.exc(e))


def upload(path, title):
    log.info("Posting %s to soundcloud..." % path)
    try:
        with open(path, 'rb') as f:
            track = {'asset_data': f, 'sharing': "public", 'title': title}
            track = client.post('/tracks', track=track)
            soundcloud_url = track.permalink_url
    except Exception as e:
        log.error("--> could not post track to SoundCloud: %s" % log.exc(e))
{'fraction_non_alphanumeric': 0.15426555484284799, 'fraction_numerical': 0.0006414368184733803, 'mean_word_length': 2.817625458996328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2240388', 'n_tokens_mistral': 902, 'n_tokens_neox': 878, 'n_words': 217}