def get_mongo_connection(): try: conn = mongo.MongoDB(host=app.config['MYSQL_HOST'], port=app.config['MYSQL_PORT'], db=app.config['MONGO_DB']) return conn except Exception as e: print(e)
def __init__(self, config): self.config = config self.mongo = mongo.MongoDB(self.config) self.node = node.Node(self.config) self.repoCloner = repositoryInstaller.RepositoryInstaller(self.config) self.ruby = ruby.Ruby(self.config)
def __init__(self): """Configure MongoDB and Secret Settings""" self.db_songs = mongo.MongoDB("smart_pl", "song_collection") self.connect = auth.connect() # Load secret parameters
return list(set(sum(map(lambda x: x.split("_"), indicators), []))) def filter_stops(words, countries): p = re.compile("[a-z]+") return filter( lambda w: not w in STOPS and p.match(w) and not w in countries, words) def word_is_valid(word): return (EN_US_DICT.check(unicode(word)) and EN_GB_DICT.check(unicode(word)) and len(word) > 2) def lemmatize(tokens): # work heavy! result = set([]) for token in tokens: if word_is_valid(token): result.add(WN_LEMMATIZER.lemmatize(token).lower()) return list(result) mdb = mongo.MongoDB("wdi_data") c = mdb.collections() tokens = tokenize(c) countries = all_countries(mdb) clean_tokens = filter_stops(tokens, countries) lems = sorted(list(lemmatize(clean_tokens))) print lems print len(lems)
elif attr == "duration": # Check duration of track return self.if_(attr, trk["duration"]) # elif attr == "shuffle": # Check if attr is T/F return self.get(attr) # elif attr == "title": # Smart-playlist title is not relevant for sorting return True # else: lgr.debug("Err: attr: `{}` not parsed".format(attr)) return False if __name__ == "__main__": """Manual tests""" db_songs = mongo.MongoDB("test_database", "test_collection") trk = db_songs.find_one() p_cg = parse_config(debug=True) attrs = [ # "keyword_match", "artists", "genres", "go", "duration", "sources" ] lgr.debug("trk: {}\n".format(trk)) for attr in attrs: res = p_cg.check_attr(trk, attr) lgr.debug("attr: {}={}\n".format(attr, res))