python - Django: Auto Populate CharField using Urllib2 -
I am working on the Djnago project and wondering if I can use the information I am in a large amount Data are quickly imported from the
import model class stock (model.model): ticker = model.carfield (max_long = 250) name = model.carfield (max_long = 250) exchange = model . Serifield (maximum_long = 250) Industry = Model.Carfield (max_long = 250) about = model. TestField () square meta: verbose_name_plural = "stocks" def __unicode __ (self): return self. Ticker So far, I have done this by filling fields using a data from CSV, "ticker," "name" and "exchange" (UISGG "python manage.py" Shell "):
Import CSV from import. CDS. In the reader, enter the fields field = ["ticker", "name", "exchange"] for the row (open ('NASDAQ.csv', 'ru'), I was wondering if I The "Industry" field can auto-populate, similarly urlib2 is pulling data from here. Here is my realline urllib2 code: indusCode = urllib2.urlopen ("http://finance.yahoo .com / q / in? S = "+ t) .read () Industry = [0] industry = industry. Location (" & amp; amp; "," and ")
Sure.
CSV stock from import.model field for field in import stock Csv.reader = ["ticker", "name", "exchange"] (open ('NASDAQ.csv', 'ru'), quote = ' Excel '): row_dict = dict (zip, line)) Indus code = urllib2.urlopen ("http://finance.yahoo.com/q/in?s=" + row_dict [' ticker ']). Read () Industry = Indus code. Limited ('& lt; b & gt; Industry:') [1] .split ('& lt; / b & gt;') [0] Industry = Industry Location ("& amp; amp;", "&") row_dict ['industry'] = industrial stock. .create (** row_dict) has not tested but I believe anything like this should work.
Comments
Post a Comment