Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Handiklap
Aug 14, 2004

Mmmm no.
I've been stumbling my way through making a small Python 3.3 server monitor, because budget is $0, and have it (kind of) working. Each of the hosts runs an instance of Coretemp w/ the remote server plugin that runs a simple web server and spits out json to connected clients. This was my third approach after abandoning a couple wmi implementations because hosts ended up becoming practically unresponsive under load; these are rendering slaves and experience extended periods of 100% utilization, which is really what I'm concerned about monitoring in the first place.

Anyway, the problem I'm having is with consuming the json the hosts provide using urllib. I know less about http than I do Python, so when readurl raises BadStatusLine, I'm capturing the json from it and parsing the CPU and ram data I want, rinse and repeat instead of maintaining a connection and parsing each new json as it refreshes. Christ, I feel dirty just typing that out. Is there a trick to doing this gracefully, or would using socket to build my own requests let me not rely on the whole thing routinely making GBS threads the bed? I mean, it works, but it feels shady as gently caress, and I'd love to not be a Coding Horrors celebrity.

Handiklap fucked around with this message at 14:29 on Dec 15, 2013

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Handiklap posted:

I've been stumbling my way through making a small Python 3.3 server monitor, because budget is $0, and have it (kind of) working. Each of the hosts runs an instance of Coretemp w/ the remote server plugin that runs a simple web server and spits out json to connected clients. This was my third approach after abandoning a couple wmi implementations because hosts ended up becoming practically unresponsive under load; these are rendering slaves and experience extended periods of 100% utilization, which is really what I'm concerned about monitoring in the first place.

Anyway, the problem I'm having is with consuming the json the hosts provide using urllib. I know less about http than I do Python, so when readurl raises BadStatusLine, I'm capturing the json from it and parsing the CPU and ram data I want, rinse and repeat instead of maintaining a connection and parsing each new json as it refreshes. Christ, I feel dirty just typing that out. Is there a trick to doing this gracefully, or would using socket to build my own requests let me not rely on the whole thing routinely making GBS threads the bed? I mean, it works, but it feels shady as gently caress, and I'd love to not be a Coding Horrors celebrity.
Perhaps this is something Requests with streaming enabled would be good for.

How feasible would it be to create a Pip-like utility that cleanly handles compiling other language code? Ie something like the Ubuntu package manager, but for Python on any operating system. Pip works well for Python-only modules, but has a high chance of making GBS threads the bed if there's any C in it. Windows installers and Ubuntu packages are nice, but aren't available for everything.

Dominoes fucked around with this message at 16:31 on Dec 15, 2013

rock2much
Feb 6, 2004

Grimey Drawer
I just finished the Codecademy course for Python and now I don't know where to go to learn more, practical python. Any suggestions?

Dominoes
Sep 20, 2007

rock2much posted:

I just finished the Codecademy course for Python and now I don't know where to go to learn more, practical python. Any suggestions?
Start a project, then look up or ask about whatever you can't figure out. It makes it (for me at least) easier to commit things to memory, and understand concepts.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Dominoes posted:

You're right; the answer is Signals and slots.

updatePbarSignal = QtCore.pyqtSignal(float)

self.updatePbarSignal.connect(lambda value: self.update_pbar(value))

[/code]
I left out the pbars past the first to keep the example simple, but you could pass the pbar object's name through emit, connect, and the set method to keep the code compact while adding the extra pbars.

Here are the four bits of code I added. You can use them as a template for doing this in the future.
  • ex.updatePbarSignal.emit(osc1.next()) - use this in the place you'd normally update the widget with setValue() or w/e.

  • updatePbarSignal = QtCore.pyqtSignal(float) - Boilerplate that has to include the data type of the signal. You can use Python or QT data tapes. I like putting it in the GUI's class, above the __init__ method.

  • self.updatePbarSignal.connect(lambda value: self.update_pbar(value)) - Lambda's used here as a workaround; the connect command only likes a single line, and can't pass variables directly. Usually goes in the gui's __init__.

  • def update_pbar(self, value):
    self.pbar1.setValue(value)
    - You can update with the GUI in this method without triggering errors.

Yea - the easiest-to-find tutorials and instructions don't cover custom signals... They should.

I couldn't get that connect statement to work. Just to confirm, is that likely from a change in recent releases of PyQt4? I had to use:

Python code:
        self.update_pbar_signal1 = QtCore.pyqtSignal(float)

        ...

        QtCore.QObject.connect(self, QtCore.SIGNAL("update_pbar_signal1"), (lambda value: self.update_pbar1(value)))
I saw this online before and they were all like, "This is more Pythonic now!" I don't really get it. They had a nice, shorter, object-oriented call that got replaced with some global-scope declaration. But regardless you got me enough of the clues that I see how this is goes. Thanks for your help!

Dominoes
Sep 20, 2007

Rocko Bonaparte posted:

I couldn't get that connect statement to work. Just to confirm, is that likely from a change in recent releases of PyQt4?

Could be. What version of PyQT are you using? My example used 'new style' signals and slots, and the the bit of code you posted uses the old style. The new style was introduced in PyQt 4.5. PyQt5 drops the old style entirely.

The old style is based on the C++ QT. New style is cleaner and more Pythonic.

Handiklap
Aug 14, 2004

Mmmm no.

Dominoes posted:

Perhaps this is something Requests with streaming enabled would be good for.

I tried this with the same results. Upon further inspection, the problem is that the server is returning an empty status code. Is there anyway to intercept the response and modify response.status before it throws a fit?

Dominoes
Sep 20, 2007

Handiklap posted:

I tried this with the same results. Upon further inspection, the problem is that the server is returning an empty status code. Is there anyway to intercept the response and modify response.status before it throws a fit?
Python code:
if not request.statuscode:
    do this
?

Handiklap
Aug 14, 2004

Mmmm no.

Dominoes posted:

Python code:
if not request.statuscode:
    do this
?

But without a valid status, it raises BadStatusLine, and the assignment that raised the exception doesn't actually happen. I ended up using socket to just read it line by line:
Python code:
import socket
import json

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
data = 'GET /\r\n'
s.connect((host, 5200))
s.sendall(data.encode('utf-8'))

for i in range(5):
    print(json.loads(s.makefile().readline()))

s.shutdown
s.close

rock2much
Feb 6, 2004

Grimey Drawer

Dominoes posted:

Start a project, then look up or ask about whatever you can't figure out. It makes it (for me at least) easier to commit things to memory, and understand concepts.

So I made a thing, where at some point it sorts a dictionary and then prints the keys & values in a nice format. I googled and found
code:
def printplus(obj):
    """
    Pretty-prints the object passed in.

    """
    # Dict
    if isinstance(obj, dict):
        #added 'key=itemgetter(1), reverse=True' to sort by second item and descending order
        for k, v in sorted(obj.items(), key=itemgetter(1), reverse=True):
            print u'{0}: {1}'.format(k, v)

    # List or tuple            
    elif isinstance(obj, list) or isinstance(obj, tuple):
        for x in obj:
            print x

    # Other
    else:
        print obj
which works fine on repl.it, but when I try to run the .py file on my computer I get
code:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>"C:\path\number assignment.py"
  File "C:\path\number assignment.py", line 16
    print u'{0}: {1}'.format(k, v)
                    ^
SyntaxError: invalid syntax
or
code:
C:\Windows\system32>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> "C:\path\number assignment.py"
  File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio
n 2-3: truncated \UXXXXXXXX escape
>>>

BannedNewbie
Apr 22, 2003

HOW ARE YOU? -> YOSHI?
FINE, THANK YOU. -> YOSHI.
That looks like Python 2.x code and you're trying to run it on Python 3.3.

rock2much
Feb 6, 2004

Grimey Drawer
Oh, drat. I thought it would work backwards but I guess not. Thanks.

Dominoes
Sep 20, 2007

Using 'items()' instead of 'iteritems()' implies Python 3 as well. Your code should work with parentheses around the print calls.

Dominoes fucked around with this message at 23:31 on Dec 15, 2013

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dominoes posted:

Using 'items()' instead of 'iteritems()' implies Python 3 as well. Your code should work with parentheses around the print calls.

items works fine in Python2. In fact, it's what I've used for years (because I always forget about iteritems).

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Dominoes posted:


Could be. What version of PyQT are you using? My example used 'new style' signals and slots, and the the bit of code you posted uses the old style. The new style was introduced in PyQt 4.5. PyQt5 drops the old style entirely.

The old style is based on the C++ QT. New style is cleaner and more Pythonic.

I thought I was using a release with the new style in it. This is what I installed anyways: PyQt4-4.10.3-gpl-Py3.3-Qt4.8.5-x64, which claims to be PyQt 4.10.3.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Dominoes posted:

How feasible would it be to create a Pip-like utility that cleanly handles compiling other language code? Ie something like the Ubuntu package manager, but for Python on any operating system. Pip works well for Python-only modules, but has a high chance of making GBS threads the bed if there's any C in it. Windows installers and Ubuntu packages are nice, but aren't available for everything.

Down this road lies madness.

What exactly is this for? Just over-ambitious side-project? It's a very hard problem to solve.

If you're actually just trying to get poo poo done - just use the distribution-native packages for python wrappers. Any missing pure-python libraries are pretty easy to wrap in packages once you do it a few times. It's still a huge pain in the rear end though - like, can easily be somebody's full time job if you absolutely need to have reliable deploys + dependencies on python apps and you end up maintaining your own repos etc etc.

Whatever it is you're doing, consider not doing it. Just make do with a bit of manual setup or make it a vagrant script or something.

QuarkJets
Sep 8, 2008

Dominoes posted:

I read through the quickstart and high level docs for H5PY, but can't figure out how to effectively store the data, either as groups or datasets. The three axes are stock symbol, date, and attribute (ie high, close prices). Would I use groups, or datasets? If I use datasets to store the prices, how can I correlate what each array value is for? I feel like while datasets (arrays) would be fast and compact, ensuring each array values matches up with what stock, date and attribute it's for would be a disaster.

For groups would I set it up like this?
/dataset/GOOG/2013-01-01/close = 800.74
/dataset/GOOG/2013-01-01/high = 810.34
/dataset/GOOG/2013-01-02/close = 801.25

etc Would I use attributes?

Haven't tried Pandas yet.

Just think of groups as folders and datasets as N-dimensional tables of data that you put inside of groups. I'd think that having a group for each stock name would be best, and then you could set up datasets of dates and prices

So your HDF5 file could look like this:

/GOOG/date
/GOOG/high_price
/GOOG/close_price
/GOOG/low_price
/YHOO/date
/YHOO/high_price
/YHOO/close_price
/YHOO/low_price
/IBM/date
/IBM/high_price
/IBM/close_price
/IBM/low_price

So each group would be a stock name, and each group would be containing 4 1-D datasets: date, high_price, close_price, low_price. Each day, you'd put a new entry into each dataset. Maybe you make a new HDF5 file each month, or maybe each year. This is a nice and simple way to organize your data. There are lots of other ways that you could organize your data in HDF5 datasets, this is just a basic one.

The analogue in MySQL would be to have a table of stock names with unique IDs and a table of price data that has a unique id, date, high_price, close_price, low_price, and a unique stockname id that maps back to the stock name table. This is fine and has advantages and disadvantages.

OnceIWasAnOstrich
Jul 22, 2006

Dominoes posted:

How feasible would it be to create a Pip-like utility that cleanly handles compiling other language code? Ie something like the Ubuntu package manager, but for Python on any operating system. Pip works well for Python-only modules, but has a high chance of making GBS threads the bed if there's any C in it. Windows installers and Ubuntu packages are nice, but aren't available for everything.

What exactly do you mean compiling other languages. Is this just in the context of compiling Python modules with other language code in them? Pip works perfectly well for that almost every time, assuming that you have your system set up right with all the dependencies you need. On the other hand that assumption is the single biggest challenge if you wanted to make a utility that took care of that for you. Are you looking for a replacement for setuptools that somehow makes the process of standardizing a build easier? There is a lot of work that goes into making any particular library able to compile everywhere, and making a tool that could do that sounds insane.

I have yet to find a package that Pip doesn't install and compile correctly assuming I had brew or apt-get the dependencies correctly and there wasn't a bug in the code itself.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dominoes posted:

How feasible would it be to create a Pip-like utility that cleanly handles compiling other language code? Ie something like the Ubuntu package manager, but for Python on any operating system. Pip works well for Python-only modules, but has a high chance of making GBS threads the bed if there's any C in it. Windows installers and Ubuntu packages are nice, but aren't available for everything.

I've never really had any problem with pip on ubuntu. It Just Works and is the main reason for using linux instead of Windows for python development.

You can get it to work on Windows by correctly configuring Visual Studio (but it isn't easy to configure that right...I had it done once years ago, but have no recollection of what I did).

Pollyanna
Mar 5, 2005

Milk's on them.


Anyone who's used Bokeh: exactly how do I create an independent plot that I can embed into a totally different page? There's create_html_snippet(), but I don't really understand how it works. It outputs something.embed.js, and I'm not sure how to work that into a Jinja2 template.

Alternatively, has anyone figured out how to get bokeh-server working on Heroku?

Dominoes
Sep 20, 2007

Mr. Wynand posted:

Down this road lies madness.
What exactly is this for? Just over-ambitious side-project? It's a very hard problem to solve.
If you're actually just trying to get poo poo done - just use the distribution-native packages for python wrappers. Any missing pure-python libraries are pretty easy to wrap in packages once you do it a few times. It's still a huge pain in the rear end though - like, can easily be somebody's full time job if you absolutely need to have reliable deploys + dependencies on python apps and you end up maintaining your own repos etc etc.

Whatever it is you're doing, consider not doing it. Just make do with a bit of manual setup or make it a vagrant script or something.

OnceIWasAnOstrich posted:

What exactly do you mean compiling other languages. Is this just in the context of compiling Python modules with other language code in them? Pip works perfectly well for that almost every time, assuming that you have your system set up right with all the dependencies you need. On the other hand that assumption is the single biggest challenge if you wanted to make a utility that took care of that for you. Are you looking for a replacement for setuptools that somehow makes the process of standardizing a build easier? There is a lot of work that goes into making any particular library able to compile everywhere, and making a tool that could do that sounds insane.

I have yet to find a package that Pip doesn't install and compile correctly assuming I had brew or apt-get the dependencies correctly and there wasn't a bug in the code itself.

Thermopyle posted:

I've never really had any problem with pip on ubuntu. It Just Works and is the main reason for using linux instead of Windows for python development.

You can get it to work on Windows by correctly configuring Visual Studio (but it isn't easy to configure that right...I had it done once years ago, but have no recollection of what I did).
I ran into a bit of trouble trying to get H5PY installed on Ubuntu. Installing PyQt5 was a pain before the latest Ubuntu release which included a package. I've failed 100% of the time when trying on Windows. A pip that downloads and configures dependencies and compilers so modules just worked would be nice.

QuarkJets posted:

Just think of groups as folders and datasets as N-dimensional tables of data that you put inside of groups. I'd think that having a group for each stock name would be best, and then you could set up datasets of dates and prices

So your HDF5 file could look like this:
Thanks dude I'll take a stab at that this evening.

Pollyanna
Mar 5, 2005

Milk's on them.


Disregard previous post! Got something working, finally. Go check out How are my stocks doing? and follow the instructions there for great fun!

By the way, I mention it there, but I want the url to be (for example) /stocks?symbol=AAPL and that will return the stock chart for AAPL. How do I do this in Flask?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Pollyanna posted:

Disregard previous post! Got something working, finally. Go check out How are my stocks doing? and follow the instructions there for great fun!

By the way, I mention it there, but I want the url to be (for example) /stocks?symbol=AAPL and that will return the stock chart for AAPL. How do I do this in Flask?

:google: "Python flask get URL variables value" and you will see many ways.

Dren
Jan 5, 2001

Pillbug

Dominoes posted:

How feasible would it be to create a Pip-like utility that cleanly handles compiling other language code? Ie something like the Ubuntu package manager, but for Python on any operating system. Pip works well for Python-only modules, but has a high chance of making GBS threads the bed if there's any C in it. Windows installers and Ubuntu packages are nice, but aren't available for everything.

Anacondas. It gets talked about a lot on here I don't know how you've missed it.

Dominoes posted:

I ran into a bit of trouble trying to get H5PY installed on Ubuntu. Installing PyQt5 was a pain before the latest Ubuntu release which included a package. I've failed 100% of the time when trying on Windows. A pip that downloads and configures dependencies and compilers so modules just worked would be nice.

They have a prebuilt package for H5PY. The QT package is 4.8, but maybe there is a QT5 package available somewhere.

http://docs.continuum.io/anaconda/pkgs.html

OnceIWasAnOstrich
Jul 22, 2006

Yeah like he said Anacondas does half of that, although it only works for a subset of packages and although a vaguely remember it installing a working copy of gcc and letting me compile a random library through pip at one point, although when I tried again just now it was still complaining about visual studio so who knows.

I think you or anyone else dealing with relatively large amounts of data that isn't quite relational database complicated should really look into Pandas. DataTables give you amazing Numpy compatible support for row/column based data with annotation that stock to datapoints through operations. It was also a godsend when working with shittons of timepoint data.

It's just a bonus that it can use HDF5/PyTables as a backend to do out of core computation. Also speaking of that PyTables is a good alternative to h5py that is less of a thin wrapper over the C library with a more Pythonic interface of you don't want to go all the way to using Pandas (which you should because it is awesome).

OnceIWasAnOstrich fucked around with this message at 20:16 on Dec 16, 2013

Dren
Jan 5, 2001

Pillbug

OnceIWasAnOstrich posted:

Yeah like he said Anacondas does half of that, although it only works for a subset of packages and although a vaguely remember it installing a working copy of gcc and letting me compile a random library through pip at one point, although when I tried again just now it was still complaining about visual studio so who knows.

Anaconda isn't meant to let you compile packages that aren't pure python. The package manager, conda, will let you grab prebuilt binaries for packages. Anaconda supports a good amount of packages across linux/windows/mac. That way when you want to install numpy you don't have to gently caress with getting all the numpy dependencies with apt-get or installing Visual Studio or whatever mac people do.

If you want a package that needs to be compiled and isn't provided in the anacoda distro you can poke around on the net to see if someone else has packaged it for conda or you can do so yourself.

Btw, I second the idea that he should switch to pandas. Pandas is basically awesome.

Dominoes
Sep 20, 2007

I started a pandas tutorial last night and watched bits of videos from its creator. Looks like it could open interesting possibilities.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Dominoes posted:

I ran into a bit of trouble trying to get H5PY installed on Ubuntu. Installing PyQt5 was a pain before the latest Ubuntu release which included a package. I've failed 100% of the time when trying on Windows. A pip that downloads and configures dependencies and compilers so modules just worked would be nice.


Right, so usually the way that problem is solved is through actual package managers. Linuxes have deb/rpm/etc, OS/X has the that weird homebrew system and Windows has gently caress-all which is why everyone hates developing on Windows even if they are Microsoft #1 fan. Your best bet is to find windows installers for specific packages you need (like the ones pointed out above) or maybe you can hack up some poo poo using cygwin - either way, it just isn't a pleasant experience :)

Pollyanna
Mar 5, 2005

Milk's on them.


I'm trying to add a script tag to a template in Flask. I have a variable snippet that looks like this:

code:
<script src="ebd3c913-924c-4dfb-88e5-ac837f011fb0.embed.js" bokeh_plottype="embeddata"
        bokeh_modelid="ebd3c913-924c-4dfb-88e5-ac837f011fb0" bokeh_modeltype="Plot" async="true"></script>
I want to pass this in to the template as-is. However, when I put {{ snippet }} in and pass snippet, it gets added like this:

code:
&lt;script src=&#34;b5632c4c-1f74-4238-a90f-0324de045a86.embed.js&#34; bokeh_plottype=&#34;embeddata&#34;
        bokeh_modelid=&#34;b5632c4c-1f74-4238-a90f-0324de045a86&#34; bokeh_modeltype=&#34;Plot&#34; async=&#34;true&#34;&gt;&lt;/script&gt;
and the script appears as plain text as opposed to an actual tag. How do I stop this from happening?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
http://flask.pocoo.org/docs/templating/#controlling-autoescaping

Pollyanna
Mar 5, 2005

Milk's on them.


Oh. :doh: I could have sworn I looked up the Jinja2 documentation for it...

Anyway, I have yet another problem, and this one's bizarre. Lemme give you some background first:

I have this script...

Python code:
from flask import Flask, render_template
import plots

app = Flask(__name__)


# Define and add a home page.

@app.route('/')  # The base URL for the home page.
def resume():
    return render_template('resume.html')


@app.route('/echo/<message>')
def echo(message):
    # Echos the message passed to it.
    return "%s" % message


@app.route('/stocks')
def stocks():
    return render_template('stocks.html')


@app.route('/stocks/<symbol>')
def lookup(symbol):

    s = symbol

    snippet = plots.build_plot(s)

    return render_template('stocks.html', snippet=snippet)

# Create plot HTML pages.

# Run this thing!
if __name__ == '__main__':
    app.run(debug=True)
that uses a function from this script...

Python code:
__author__ = 'rebecca'

from bokeh.plotting import *

import datetime
import pandas
import pandas.io.data as web
from pyta import *


# Create a plot for each symbol.

def build_plot(symbol):

    input_symbol = symbol

    #print input_symbol

    start = datetime.date(2012, 1, 1)

    end = datetime.date.today()

    periods = 50

    file_name = '%s.html' % symbol

    output_file(file_name, title='How are my stocks doing today?')

    #print input_symbol

    data = web.DataReader(input_symbol, 'google', start, end)

    close = data['Close'].values  # Returns Numpy array.

    dates = data.index.values  # Returns Numpy array.

    # Plot raw stock data.

    x = data.index

    y = close

    line(x[50:], y[50:], width=800, height=600, color='#1B9E77', x_axis_type='datetime', legend='Price at Close')
    hold()


    # Perform TA on stock data.


    # Define SMA 50.

    sma50 = sma(close, periods)

    # Define Bollinger Bands.

    upperband = bollinger_upper(close, sma50, periods)

    lowerband = bollinger_lower(close, sma50, periods)

    # Define RSI.

    rsi50 = rsi(close)

    # Define MACD Line, Signal, and Histogram.

    macd = macd_line(close)

    signal = macd_signal(close)

    hist = macd_hist(close)


    # Plot analyses.


    # SMA 50:

    line(x, sma50, color='#D95F02', x_axis_type='datetime', legend='50-day SMA')

    # Bollinger shading glyph:

    bandprice = stackify(upperband, lowerband)  # Reverse the upper band data and append it to the lower band data.

    banddates = stackify(dates, dates)  # Do the same for the dates.

    # TODO: Explain how Patch works, and why the data has to be manipulated in this manner.

    patch(pandas.to_datetime(banddates), bandprice, color='#7570B3', fill_alpha=0.2, x_axis_type='datetime')


    # Remove hold, allow for more plots to be added.

    curplot().title = symbol
    curplot().height = 600
    curplot().width = 1000

    yaxis().axis_label = 'Price (USD)'

    grid().grid_line_alpha = 0.4

    snippet = curplot().create_html_snippet(embed_save_loc='./static/js', static_path='./static/js/bokeh.js')

    return snippet
and when run, causes this error...

code:
Session output file 'GOOG.html' already exists, will be overwritten.
127.0.0.1 - - [16/Dec/2013 21:41:16] "GET /stocks/GOOG HTTP/1.1" 200 -
127.0.0.1 - - [16/Dec/2013 21:41:16] "GET /stocks/56d50133-674f-408d-b700-baacb25fae09.embed.js HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/rebecca/Desktop/NerdStuff/Python/flask-heroku/app/routes.py", line 30, in lookup
    snippet = plots.build_plot(s)
  File "/Users/rebecca/Desktop/NerdStuff/Python/flask-heroku/app/plots.py", line 31, in build_plot
    data = web.DataReader(input_symbol, 'google', start, end)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/pandas/io/data.py", line 76, in DataReader
    retry_count=retry_count, pause=pause)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/pandas/io/data.py", line 424, in get_data_google
    adjust_price, ret_index, chunksize, 'google', name)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/pandas/io/data.py", line 336, in _get_data_from
    hist_data = src_fn(symbols, start, end, retry_count, pause)
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/pandas/io/data.py", line 209, in _get_hist_google
    return _retry_read_url(url, retry_count, pause, 'Google')
  File "/Users/rebecca/anaconda/lib/python2.7/site-packages/pandas/io/data.py", line 169, in _retry_read_url
    "return a 200 for url %r" % (retry_count, name, url))
IOError: after 3 tries, Google did not return a 200 for url 'http://www.google.com/finance/historical?q=56d50133-674f-408d-b700-baacb25fae09.embed.js&startdate=Jan+01%2C+2012&enddate=Dec+16%2C+2013&output=csv'
Let me point out the problem: for some reason, the stock symbol passed to plots.build_plot() (and thereby web.DataReader() ) gets changed from 'GOOG' to the name of the .js snippet I'm trying to embed into the HTML. I have no loving clue why this is happening.

Particularly weird is this:

code:
127.0.0.1 - - [16/Dec/2013 21:41:16] "GET /stocks/GOOG HTTP/1.1" 200 -
127.0.0.1 - - [16/Dec/2013 21:41:16] "GET /stocks/56d50133-674f-408d-b700-baacb25fae09.embed.js HTTP/1.1" 500 -
:confused: Why does it suddenly query a different URL even after loading the correct one? And where the hell is the symbol changing, anyway?

When I ask it to print input_symbol before querying web.DataReader:

code:
GOOG
127.0.0.1 - - [16/Dec/2013 21:53:08] "GET /stocks/GOOG HTTP/1.1" 200 -
0bdfe477-c7ce-4185-8d52-f9a2a31c2eb4.embed.js
127.0.0.1 - - [16/Dec/2013 21:53:08] "GET /stocks/0bdfe477-c7ce-4185-8d52-f9a2a31c2eb4.embed.js HTTP/1.1" 500 -
Traceback (most recent call last):
    ....
:wtf: Is that function being called twice somehow!? I can't see a reason why it would be, none of this makes sense.

Anyone got any ideas?

Modern Pragmatist
Aug 20, 2008

Pollyanna posted:

Anyone got any ideas?

I'm assuming that your using the <script> tag you mentioned previously. The path to the JavaScript file is relative since it doesn't contain the domain etc. because of this it looks in the "current directory" for this file based on the structure of your URL. Based on the structure, it thinks the file is at stocks/some.idiotic.filename.js which just sends another request but now instead of the symbol the last part of the URL is the JavaScript file. You should probably specify the absolute path to the JavaScript file using url_for.

Modern Pragmatist fucked around with this message at 04:58 on Dec 17, 2013

FoiledAgain
May 6, 2007

What's this about?

code:
>>> type(None)
<class 'NoneType'>
>>> isinstance(None, NoneType)
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
NameError: name 'NoneType' is not defined
How can it tell me that None is of type NoneType, and then tell me it doesn't know what NoneType is?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
There's no guarantee that NoneType is in the global scope. It's in the types module.

FoiledAgain
May 6, 2007

Suspicious Dish posted:

There's no guarantee that NoneType is in the global scope. It's in the types module.

That makes sense, but then this doesn't work:

code:
>>> from types import NoneType
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
ImportError: cannot import name NoneType
None must have some kind of special status?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Are you on Python 2 or Python 3? NoneType isn't exposed anywhere in Python 3, from my recollection. The only way to get it is to do type(None) (which is actually what the types module did anyway)

FoiledAgain
May 6, 2007

Suspicious Dish posted:

Are you on Python 2 or Python 3? NoneType isn't exposed anywhere in Python 3, from my recollection. The only way to get it is to do type(None) (which is actually what the types module did anyway)

I'm on 3.3. I have absolutely no need to do anything with this, it's just a curiosity that I came across. I also learned today that isinstance(True,int)==True.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
There's a lot of modules in PyPi to work with subversion, so I was hoping somebody could recommend a few before I just try to figure what a bunch of them can or can't do. I have to deal with a situation where subversion is being used basically for software distribution (sad) to some Windows machines. So we'd use it to revert and update to a specific revision of the repository. Is there a general heavyweight module for this, or at least one more suitable for this kind of thing?

evilentity
Jun 25, 2010

FoiledAgain posted:

What's this about?

code:
>>> type(None)
<class 'NoneType'>
>>> isinstance(None, NoneType)
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
NameError: name 'NoneType' is not defined
How can it tell me that None is of type NoneType, and then tell me it doesn't know what NoneType is?

Why the hell do you need this?

Adbot
ADBOT LOVES YOU

Kumquat
Oct 8, 2010

evilentity posted:

Why the hell do you need this?

FoiledAgain posted:

I have absolutely no need to do anything with this, it's just a curiosity that I came across.

  • Locked thread