data_garden

1

votes
0

answer
97

views

Docker-compose: bind Celery to Postgres database

My Docker app runs with Flaskas backend and Celeryas an asyncronous task manager. Task results are then dumped in a SQLalchemy database owned by Postgres. However, I am not being able to make Celery interact with Postgres. STRUCTURE docker-compose-dev.yml web/ entrypoint.sh celery_worker.py migrati...
data_garden
1

votes
0

answer
371

views

Flask-SLQAlchemy OperationalError: (sqlite3.OperationalError) no such table

I am new to databases, therefore sorry if this is too basic, but I had no luck with other related questions in SO. MODELS.py import json from app import db class User(db.Model): __tablename__='user' ''' Model for storing user data. ''' id = db.Column(db.Integer, primary_key=True) name = db.Column(d...
data_garden
1

votes
0

answer
44

views

Matplotlib - plot face landmarks with no background image

The code bellow provides face-aligment to any photo I give as input. Face-aligment link: https://github.com/1adrianb/face-alignment import face_alignment import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from skimage import io # Run the 3D face alignment on a...
data_garden
1

votes
2

answer
39

views

counting elements in a list of tuples with added weight per item

I have a list of tuples: for i, item in enumerate(tags_and_weights): tags = item[0] weight = item[1] which prints: 1 (['alternative country', 'alternative pop', 'alternative rock', 'art rock', 'brill building pop', 'country rock', 'dance rock', 'experimental', 'folk', 'folk rock', 'garage rock', 'gb...
data_garden
1

votes
2

answer
142

views

Trigger Celery task in a RESTful Route

I would like to set a route for my Celery tasks and monitor them. This is the code I have in my flask app running at localhost:5000 background.py Task: @celery.task(queue='cache') def cache_user_tracks_with_features(): return {'status': 'Task completed!'} Route: @task_bp.route('/filter', methods=['G...
data_garden
1

votes
1

answer
66

views

Cherrypy ::: fail to load index.html

I have this folder structure: index.html tutorial -> public -> css -> style.css tut.py where tutorialis root. inside tut.py, which I run as python tut.py, this snippet sets root (tutorial): if __name__ == '__main__': conf = { '/': { 'tools.sessions.on': True, 'tools.staticdir.root': os.path.abspath...
data_garden
1

votes
1

answer
66

views

How can I set a Timer to control a function call inside a loop?

I have this function, which plays Spotify: #a function to play Spotify def play(id_): print 'playing', id_ os.system('osascript -e 'tell application \'Spotify\' to play track \'%s\''' % (id_,)) and the following loop, which iterates through all playlist songs, obtains all playable id's (foreign_id),...
data_garden
1

votes
1

answer
307

views

Scrapy - print pipeline data in a script's context

After using scrapy framework, I would like to process my pipeline.py output within my python script context. The pipeline output is tracks.jl, as follows: pipeline.py class PitchforkTracks(object): def __init__(self): self.file = open('tracks.jl', 'wb') a json file is generated on the same script.py...
data_garden
1

votes
1

answer
53

views

JSON results in API calls

If I go about last.fm API, using pylast wrapper, and lookup for similar tracks, like so: track = last.get_track('Radiohead', 'Karma Police') for similar in track.get_similar(): print (similar) I get: SimilarItem(item=pylast.Track(u'Radiohead', u'No Surprises', pylast.LastFMNetwork('key', 'secret', '...
data_garden
1

votes
2

answer
345

views

Updating new dictionary keys + increment old dictionary values

I am constantly generating playlists with this structure: playlist = {u'user1': {u'Roads': 1.0, u'Pyramid Song': 1.0, u'Go It Alone': 1.0}} and I upload it to a directory. Then I check if file has already been uploaded before. if os.path.exists('db/playlist.json'): with open('playlist.json', 'r+')...
data_garden
1

votes
1

answer
383

views

Python - function to increment dictionary values

Starting from two nested dictionaries: p1 = {'user1': {u'Codex': 1.0, u'High And Dry': 1.0, u'Hey': 1.0, u'O': 1.0, u'Videotape': 1.0, u'Pyramid Song': 1.0}} and p2 = {'user1': {u'Codex': 1.0, u'High And Dry': 1.0, u'Hey': 1.0, u'O': 1.0, u'Videotape': 1.0, u'Pyramid Song': 1.0, u'x': 1.0, u'y': 1...
data_garden
1

votes
2

answer
97

views

Python class - attribute inheritance

I am trying to implement a project using class inheritance, where parent class is: class radio: def __init__(self, artist=None, track=None, genre=None): self.artist = artist self.track = track self.genre = genre then I create methods for each attribute (non working examples): def seed_artist(self):...
data_garden
1

votes
2

answer
47

views

Python - import module which imports module

I have three scripts in the same location: /__init__.py interface.py radio.py playlist.py playlist.py has child classes stored, like: class playlist1(radio): '''child class''' and radio.py has the parent class: class radio(object): '''parent class''' I'm trying to run interface.py, which has: if __n...
data_garden
1

votes
1

answer
59

views

BeautifulSoup - extract <a> value

I'd like to extract all values like 'Dance' in the format below: Dance I've tried: for a in soup.find_all('a', rel=True): tag = a['rel'] which partially works, printing [u'tag']. but then if I go on: print [t.string for t in tag] I get the following error: AttributeError: 'unicode' object has no att...
data_garden
1

votes
1

answer
404

views

Google Places Api - pass an address with the right encoding

In order to make a Google Places Api call, I use this function: def build_URL(search_text='',types_text=''): base_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json' key_string = '?key=mykey' query_string = '&query='+urllib.quote(search_text...
data_garden
1

votes
1

answer
910

views

Split dataframe column into two columns based on delimiter

I am preprocessing text for classification, and I import my dataset like this: dataset = pd.read_csv('lyrics.csv', delimiter = '\t', quoting = 2) dataset prints on terminal: lyrics,classification 0 I should have known better with a girl like yo... 1 You can shake an apple off an apple tree\nSh...
data_garden
1

votes
1

answer
251

views

Setting Google Credentials with Flask and Gunicorn

I have an app which incidentally uses public youtube API data, not user-related. STAGE 1: Running from command line At the top of my youtube_module.py, I had: from oauth2client.client import GoogleCredentials CREDENTIALS = GoogleCredentials.get_application_default() as documentation requires, at .b...
data_garden
1

votes
1

answer
98

views

Caffe - Check failed: mdb_status == 0 (2 vs. 0) No such file or directory

I am trying to train a custom caffe model for face recognition. (Refer to github project here: https://github.com/danduncan/HappyNet) For that I am using a docker image for caffe (which works), in a sharedfolder on my machine: Docker sharedfolder structure: execute_3_train_custom_model datasets/ m...
data_garden
1

votes
1

answer
84

views

Find all points below a line on a map

In order to draw a path between two points on a map with many points (almost two thousand), I use the following function: def path_between_cities(self, cities_with_coordinates, from_to): from matplotlib.lines import Line2D # coordinates from chosen path x = [int(from_to[0][2]), int(from_to[1][2...
data_garden
4

votes
1

answer
0

views

Authorize with Spotify using Nginx

I have a docker app running three services: client --> react frontend web --- > flask backend nginx ->- a reverse proxy for both This is the (simplified) project structure: docker-compose-dev.yml services/ client/ src/ app.jsx components/ spotify-auth.js Spotify.jsx nginx/ dev.conf web/ Here is w...
data_garden
1

votes
1

answer
5.4k

views

XMLHttpRequest - relative or absolute path?

I'm trying to make HTTP tests in my local server. On my html file, I link src='scripts/scriptedHTTP.js: var req = new XMLHttpRequest(); req.open('GET', 'file.txt', false); req.send(null); console.log(req.responseText); I serve on localhost:8000 with python -m SimpleHTTPServer. file.txt is on the sam...
data_garden
8

votes
1

answer
149

views

Authorize Spotify using React and Nginx in Docker

I am building a dockerized REST API app with the following structure: ../ web/ nginx/ dev.conf Dockerfile-dev client/ build/ conf/ Dockerfile-dev node_modules/ package_json public/ src/ App.jsx components/ SpotifyRedirect.jsx spotify-client/ Dockerfile-dev node_modules pa...
data_garden
1

votes
1

answer
574

views

Scrapy - encoding issue - scraping out quotes

I have this class: class PitchforkTracks(scrapy.Spider): name = 'pitchfork_tracks' allowed_domains = ['pitchfork.com'] start_urls = [ 'http://pitchfork.com/reviews/best/tracks/?page=1', 'http://pitchfork.com/reviews/best/tracks/?page=2', 'http://pitchfork.com/reviews/best/tracks/?page=3', 'http://pi...
data_garden
1

votes
1

answer
399

views

sqlite - Inserting many values at once

I have data structured as a dictionary, and I want to use it to feed a database: playlists={ 'user1':{'Karma Police':3.0,'Roxanne':4.0,'Sonnet':5.0,'We Will Rock You':1.0,'Song 1': 1.0}, 'user2':{'Karma Police':2.0,'Roxanne':3.0,'Sonnet':2.0,'We Will Rock You':3.0,'Song 2': 1.0}, 'user3':{'Karma Pol...
data_garden
1

votes
1

answer
717

views

Python - JSON ValueError: Extra data

I am trying to join json files: path_to_json = 'generated_playlists/p1/' json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')] json files are structured like this: {'user1': {'Wild Wood': 1.0, 'You Do Something To Me': 1.0, 'Reprise': 1.0}} but when I do: for...
data_garden
1

votes
2

answer
40

views

Python - passing parameter via command line to module function

I have this function defined in a module called tags.py: def lastfm_artist_to_tags(artist): tag_weight = {} result = last.get_artist(artist).get_top_tags() for tag in result: tag_weight[str(tag.item.get_name())] = str(tag.weight) tag_weight = {k: int(v) for k, v in tag_weight.items()} return sorted...
data_garden
1

votes
1

answer
42

views

Python - get closest integer value sorted by musical notation

given a list of integers values = [7, 9, 10, 11] If I want to find the closest value to value = 0 I could simply use closest_value = min(values, key=lambda x:abs(x-value)) and get [out]: 7 however, in my case values correspond to integers of musical notation, like so: notation_values = {'C':0, 'C#':...
data_garden
11

votes
2

answer
259

views

Installing pandas in docker Alpine

I am having a really hard time trying to install a stable data science package configuration in docker. This should be easier with such mainstream, relevant tools. The following is the Dockerfile that used to work, with a bit of a hack, removing pandas from the package core and installing it separa...
data_garden
1

votes
1

answer
55

views

Caffe - network not learning

I am failing at training a VGG NET model from scratch. Please allow me to describe my steps so far: From two folders contaning my training and validation images, labeled as training_list.txt and validation_list.txt, generated data.mdb files. After inspection these mdb files show valid img data and c...
data_garden
1

votes
1

answer
1.7k

views

Flask - Listen to POST request

I'm using Flask in order to retrieve a coordinate value generated with javascript. Flask code: from flask import Flask, request, session, g, redirect, url_for, abort, \ render_template, flash, jsonify @app.route('/geo', methods= ['GET', 'POST']) def geo(): return render_template('geo.html') @app.rou...
data_garden
1

votes
1

answer
2.5k

views

Installing Icecast on OS X: Homebrew or MacPorts?

I've been trying to run an Icecast server for a while, without success. I've installed it with Homebrew and MacPorts, but can't make it run either way. When I enter icecast -c ~/.icecast.xml, Terminal doesn't return anything, and it stays like that indefinitely, unless I [1]+ Stopped it. My config...
data_garden
1

votes
2

answer
2.7k

views

localStorage undefined

with this function: function appendToStorage(name, data) { var old = localStorage.getItem(name); if (old === null) old = ''; localStorage.setItem(name, old + data); } appendToStorage('oldData', $('textbox').value); and this html: say it... I get undefinedundefinedundefined... on the console. what I...
data_garden
3

votes
3

answer
50

views

javascript - transforming arrays

how do I use Javascript to turn this list: var array = ['no yes', 'maybe certainly']; into this one: var array2 = ['no', 'yes', 'maybe', 'certainly']
data_garden
2

votes
1

answer
16.1k

views

Telnet smtp.mail - must issue STARTTLS command first

On my Mac terminal, I am trying to telnet into my smtp.gmail.com through port 587. On Google Apps, (which is set to manage a Dreamhost domain), I have relay configured, as follows: 'Allowed senders: Only addresses in my domains' 'Require SMTP Authentication: Yes' when I HELO , I get: 250 smtp.gmail....
data_garden
5

votes
5

answer
7.2k

views

Scrapy - Reactor not Restartable

with: from twisted.internet import reactor from scrapy.crawler import CrawlerProcess I've always ran this process sucessfully: process = CrawlerProcess(get_project_settings()) process.crawl(*args) # the script will block here until the crawling is finished process.start() but since I've moved this...
data_garden
3

votes
2

answer
58

views

Python :: passing a list as parameter

responses in pyen, a thin library for music data, returns dictionaries in this fashion: {u'id': u'AR6SPRZ1187FB4958B', u'name': u'Wilco'} I'm looping through and printing artists: response = en.get('artist/search', artist_location='Chicago') artists = response['artists'] for artist in artists: sys.s...
data_garden
2

votes
1

answer
405

views

Spotipy - get track ids from track names

Usually, spotipy requires track IDs as parameters to be passed, in order to return track names. Say I have two lists, not obtained from the Spotify API: artists [u'Moses Sumney', u'Cherry Glazerr', u'Danny Brown', u'NxWorries'] and their respective songs: tracks [u'Lonely World', u'Told You I'd Be W...
data_garden
2

votes
1

answer
410

views

Tagging mp3 files in python 2.7 using eyeD3

I am trying go create a taste profile for a directory of mp3 files using python 2.7 script, but it seems there's something wrong with my eyed3 module. first I had to import it with 'd' instead of 'D' import eyed3 then I had to change deprecated playlist method to catalog.get_item_dicts(). but now i...
data_garden
2

votes
3

answer
55

views

Splitting strings with words from right based on limit

I have this list, consisting of string of tags and weights: lst = ['rock 101071', 'pop 69159', 'alternative 55777', 'indie 48175', 'electronic 46270', 'female vocalists 42565', 'favorites 39921', 'Love 34901', 'dance 33618', '00s 31432'] and I'm trying to convert that into tuples like: [('rock ', '...
data_garden
2

votes
2

answer
142

views

Intersecting nested lists using a lambda function

I would like to intersect two nested lists: source = [['one', 'two', 'three'], ['four', 'five', 'six'], ['seven', 'eight', 'nine']] target = [['three', 'whatever'], ['four', 'whatever'], ['whatever', 'whatever']] So I can return the lists in source where intersections were found: result = [['one', '...
data_garden

View additional