Command line script > Ensure that its module, "models", is located inside an installed app. error

2015-06-07 Thread Oscar Buijten
Hi There,

For various reasons I recently started efforts to covert an existing .php 
application to pyhton + django.
There are quite a few scripts that are executed through cron and so from 
the command line while coding.

I did find some info on how to setup the start of the script, but keep 
running into an error I haven't been able to resolve so far.

Using Python 2.7.x and django 1.8.x + postresql

Script is starting with this:

--  snip  --
import os,sys
sys.path.append('/home/oscar/django/trading/myichimoku')
os.environ['DJANGO_SETTINGS_MODULE']='myichimoku.settings'
from models import MyichiTickers
--  snip  --

The script lives in /home/oscar/django/trading/myichimoku/data in which the 
models.py lives as well

The error I get:

--  snip  --
Traceback (most recent call last):
  File "historic_data_collector.py", line 4, in 
from models import MyichiTickers
  File "/home/oscar/django/trading/myichimoku/data/models.py", line 4, in 

class AuthGroup(models.Model):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", 
line 131, in __new__
'app.' % (new_class.__name__, model_module.__name__)
django.core.exceptions.ImproperlyConfigured: Unable to detect the app label 
for model "AuthGroup." Ensure that its module, "models", is located inside 
an installed app.
--  snip  --

AuthGroup is the 1st table class in models.py

My settings.py lives in: /home/oscar/django/trading/myichimoku/myichimoku/

Here a snippet from the file:
--  snip  --
# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'data',
)
--  snip  --


So the question is: how can I ensure to execute this script from the 
command line with something like: python mycoolscript.py ?

Any help greatly appreciated.

Thanks!
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e72dbbe3-b6fb-4294-b4bc-04d5881b2f8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Command line script > Ensure that its module, "models", is located inside an installed app. error

2015-06-07 Thread Oscar Buijten
Thanks Gergely! :-)

I followed your suggestions and it does seem to improve behaviour, however, 
I now get a new error...

--  snip  --
Traceback (most recent call last):
  File "historic_data_collector.py", line 4, in 
from .models import MyichiTickers
ValueError: Attempted relative import in non-package
--  snip  --

I've done a quick google on it but didn't see anything that would help me 
out.
Any suggestions?

Also, I had a look at your suggestion to create a django-admin command last 
night (but ran into similar issues).
Besides a solution in itself would you mind giving some feedback on why 
that would be better? I didn't get that (yet).

FYI: there are several scripts running on regular interval updating data in 
a database that the web application then uses to show to the end user. I 
now just am converting to python/django

Thanks again,
Oscar



Le dimanche 7 juin 2015 14:26:39 UTC+2, Oscar Buijten a écrit :
>
> Hi There,
>
> For various reasons I recently started efforts to covert an existing .php 
> application to pyhton + django.
> There are quite a few scripts that are executed through cron and so from 
> the command line while coding.
>
> I did find some info on how to setup the start of the script, but keep 
> running into an error I haven't been able to resolve so far.
>
> Using Python 2.7.x and django 1.8.x + postresql
>
> Script is starting with this:
>
> --  snip  --
> import os,sys
> sys.path.append('/home/oscar/django/trading/myichimoku')
> os.environ['DJANGO_SETTINGS_MODULE']='myichimoku.settings'
> from models import MyichiTickers
> --  snip  --
>
> The script lives in /home/oscar/django/trading/myichimoku/data in which 
> the models.py lives as well
>
> The error I get:
>
> --  snip  --
> Traceback (most recent call last):
>   File "historic_data_collector.py", line 4, in 
> from models import MyichiTickers
>   File "/home/oscar/django/trading/myichimoku/data/models.py", line 4, in 
> 
> class AuthGroup(models.Model):
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", 
> line 131, in __new__
> 'app.' % (new_class.__name__, model_module.__name__)
> django.core.exceptions.ImproperlyConfigured: Unable to detect the app 
> label for model "AuthGroup." Ensure that its module, "models", is located 
> inside an installed app.
> --  snip  --
>
> AuthGroup is the 1st table class in models.py
>
> My settings.py lives in: /home/oscar/django/trading/myichimoku/myichimoku/
>
> Here a snippet from the file:
> --  snip  --
> # Application definition
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'data',
> )
> --  snip  --
>
>
> So the question is: how can I ensure to execute this script from the 
> command line with something like: python mycoolscript.py ?
>
> Any help greatly appreciated.
>
> Thanks!
> Oscar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c1c6c75f-28c1-46b0-9b79-581edd7cd17e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Command line script > Ensure that its module, "models", is located inside an installed app. error

2015-06-07 Thread Oscar Buijten
Thanks for your swift responses Gergely. It's much appreciated ;-)
I will try again for the django-admin command
Oscar

Le dimanche 7 juin 2015 14:26:39 UTC+2, Oscar Buijten a écrit :
>
> Hi There,
>
> For various reasons I recently started efforts to covert an existing .php 
> application to pyhton + django.
> There are quite a few scripts that are executed through cron and so from 
> the command line while coding.
>
> I did find some info on how to setup the start of the script, but keep 
> running into an error I haven't been able to resolve so far.
>
> Using Python 2.7.x and django 1.8.x + postresql
>
> Script is starting with this:
>
> --  snip  --
> import os,sys
> sys.path.append('/home/oscar/django/trading/myichimoku')
> os.environ['DJANGO_SETTINGS_MODULE']='myichimoku.settings'
> from models import MyichiTickers
> --  snip  --
>
> The script lives in /home/oscar/django/trading/myichimoku/data in which 
> the models.py lives as well
>
> The error I get:
>
> --  snip  --
> Traceback (most recent call last):
>   File "historic_data_collector.py", line 4, in 
> from models import MyichiTickers
>   File "/home/oscar/django/trading/myichimoku/data/models.py", line 4, in 
> 
> class AuthGroup(models.Model):
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", 
> line 131, in __new__
> 'app.' % (new_class.__name__, model_module.__name__)
> django.core.exceptions.ImproperlyConfigured: Unable to detect the app 
> label for model "AuthGroup." Ensure that its module, "models", is located 
> inside an installed app.
> --  snip  --
>
> AuthGroup is the 1st table class in models.py
>
> My settings.py lives in: /home/oscar/django/trading/myichimoku/myichimoku/
>
> Here a snippet from the file:
> --  snip  --
> # Application definition
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'data',
> )
> --  snip  --
>
>
> So the question is: how can I ensure to execute this script from the 
> command line with something like: python mycoolscript.py ?
>
> Any help greatly appreciated.
>
> Thanks!
> Oscar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0eed69af-1f28-40cb-a4d6-809640b31ce2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Command line script > Ensure that its module, "models", is located inside an installed app. error

2015-06-08 Thread Oscar Buijten
Just to let you know that I got this snippet working now Gergely :-)
Thanks again for putting me on the right track.
What I didn't get though is why I need the " *args, **options". 
I read the doc but didn't grasp the why...
Cheers,
Oscar

--  snip  --
from django.core.management.base import BaseCommand, CommandError

class Command(BaseCommand):
def handle(self, *args, **options):
from data.models import MyichiTickers
tickers_for_exchange = MyichiTickers.objects.filter(exchange="AMS")
for tickerlist in tickers_for_exchange:
print(tickerlist.ticker)
--  snip  --


Le dimanche 7 juin 2015 14:26:39 UTC+2, Oscar Buijten a écrit :
>
> Hi There,
>
> For various reasons I recently started efforts to covert an existing .php 
> application to pyhton + django.
> There are quite a few scripts that are executed through cron and so from 
> the command line while coding.
>
> I did find some info on how to setup the start of the script, but keep 
> running into an error I haven't been able to resolve so far.
>
> Using Python 2.7.x and django 1.8.x + postresql
>
> Script is starting with this:
>
> --  snip  --
> import os,sys
> sys.path.append('/home/oscar/django/trading/myichimoku')
> os.environ['DJANGO_SETTINGS_MODULE']='myichimoku.settings'
> from models import MyichiTickers
> --  snip  --
>
> The script lives in /home/oscar/django/trading/myichimoku/data in which 
> the models.py lives as well
>
> The error I get:
>
> --  snip  --
> Traceback (most recent call last):
>   File "historic_data_collector.py", line 4, in 
> from models import MyichiTickers
>   File "/home/oscar/django/trading/myichimoku/data/models.py", line 4, in 
> 
> class AuthGroup(models.Model):
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", 
> line 131, in __new__
> 'app.' % (new_class.__name__, model_module.__name__)
> django.core.exceptions.ImproperlyConfigured: Unable to detect the app 
> label for model "AuthGroup." Ensure that its module, "models", is located 
> inside an installed app.
> --  snip  --
>
> AuthGroup is the 1st table class in models.py
>
> My settings.py lives in: /home/oscar/django/trading/myichimoku/myichimoku/
>
> Here a snippet from the file:
> --  snip  --
> # Application definition
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'data',
> )
> --  snip  --
>
>
> So the question is: how can I ensure to execute this script from the 
> command line with something like: python mycoolscript.py ?
>
> Any help greatly appreciated.
>
> Thanks!
> Oscar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b1f31ca0-d981-41d5-83f0-ee2048481b29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


push yahoo finance json data into database

2015-06-08 Thread Oscar Buijten
Hi there,
The python learning curve seems to be steeper than expected :-(
As yesterday, help converting my php app into python/django will be 
appreciated.

I have the following:

  snip  ---
from django.core.management.base import BaseCommand, CommandError
import json
from collections import OrderedDict
from yahoo_finance import Share 
from data.models import MyichiTickers, MyichiHistoricalData

exchange  = 'AMS'
startdate = '2014-04-25'
enddate   = '2014-04-29'
minimum_avg_daily_volume = '10'

class Command(BaseCommand):
def handle(self, *args, **options):
from yahoo_finance import Share 
from data.models import MyichiTickers
tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
if tickers_for_exchange:
for tickerlist in tickers_for_exchange:
ticker = Share(tickerlist.ticker) 
if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
data = json.dumps(ticker.get_historical(startdate, enddate))
data = json.loads(data)
print data

  snip  ---

It may not be perfect, but it works.
I would need to get 'data' into the 'MyichiHistoricalData' model

The output is like this;
  snip  ---
[{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
u'6.529'}]
[{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
u'Open': u'13.545'}]
  snip  ---

Where I need help it so extract the keys and values and give them the 
correct model field names in order to save them.

It should be easy really, bt several hours of readin, searching, trial & 
error haven't given me the trick yet

Any suggestions?

Thanks!

Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6e16498-8b13-4b4c-b8ec-489a44b1d274%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-09 Thread Oscar Buijten
Hi James,
Thanks for such a detailed response. I looked at all your links (and 
already had come across some of them)
I guess that my question wasn't specific enough :-(

The table (and model) are existing.
However, the keys that I retrieve in the output I shared do not correspond 
to (some of) the table fields.
So I am struggling to figure out how to push the values provided by key 
names that do not match the fieldnames into my table.
If that would become really complicated I guess I could change the field 
names in the model/table, but I rather not as the trick in itself would 
help me with some other data as well (it's part of the learning curve I 
guess :-) ).
Thanks!
Oscar


As an example;
the key Symbol needs to put it's value into field 'yahoo_symbol' in the 
model/table

Le lundi 8 juin 2015 22:09:05 UTC+2, Oscar Buijten a écrit :
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---
> from django.core.management.base import BaseCommand, CommandError
> import json
> from collections import OrderedDict
> from yahoo_finance import Share 
> from data.models import MyichiTickers, MyichiHistoricalData
>
> exchange  = 'AMS'
> startdate = '2014-04-25'
> enddate   = '2014-04-29'
> minimum_avg_daily_volume = '10'
>
> class Command(BaseCommand):
> def handle(self, *args, **options):
> from yahoo_finance import Share 
> from data.models import MyichiTickers
> tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
> if tickers_for_exchange:
> for tickerlist in tickers_for_exchange:
> ticker = Share(tickerlist.ticker) 
> if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
> data = json.dumps(ticker.get_historical(startdate, enddate))
> data = json.loads(data)
> print data
>
>   snip  ---
>
> It may not be perfect, but it works.
> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
> u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
> u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
> u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
> u'Open': u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the 
> correct model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?
>
> Thanks!
>
> Oscar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e07755cc-69e2-4a64-b44c-04041ae6df32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-09 Thread Oscar Buijten
Hi James,
Thanks for such a detailed response. I looked at all your links (and 
already had come across some of them)
I guess that my question wasn't specific enough :-(

The table (and model) are existing.
However, the keys that I retrieve in the output I shared do not correspond 
to (some of) the table fields.
So I am struggling to figure out how to push the values provided by key 
names that do not match the fieldnames into my table.

As an example;
the key Symbol needs to put it's value into field 'yahoo_symbol' in the 
model/table

If that would become really complicated I guess I could change the field 
names in the model/table, but I rather not as the trick in itself would 
help me with some other data as well (it's part of the learning curve I 
guess :-) ).

Thanks!
Oscar




Le lundi 8 juin 2015 22:09:05 UTC+2, Oscar Buijten a écrit :
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---
> from django.core.management.base import BaseCommand, CommandError
> import json
> from collections import OrderedDict
> from yahoo_finance import Share 
> from data.models import MyichiTickers, MyichiHistoricalData
>
> exchange  = 'AMS'
> startdate = '2014-04-25'
> enddate   = '2014-04-29'
> minimum_avg_daily_volume = '10'
>
> class Command(BaseCommand):
> def handle(self, *args, **options):
> from yahoo_finance import Share 
> from data.models import MyichiTickers
> tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
> if tickers_for_exchange:
> for tickerlist in tickers_for_exchange:
> ticker = Share(tickerlist.ticker) 
> if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
> data = json.dumps(ticker.get_historical(startdate, enddate))
> data = json.loads(data)
> print data
>
>   snip  ---
>
> It may not be perfect, but it works.
> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
> u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
> u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
> u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
> u'Open': u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the 
> correct model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?
>
> Thanks!
>
> Oscar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4dc1dbc6-4645-4b4c-a09c-2f99b3569a9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-09 Thread Oscar Buijten
Oh, here's a part of the model that I forgot to include.

class MyichiHistoricalData(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True)  # Field 
name made lowercase.
symbol = models.CharField(max_length=10, blank=True, null=True)
exchange = models.CharField(max_length=10, blank=True, null=True)
yahoo_symbol = models.CharField(max_length=15)
symbol_period = models.IntegerField()
timeframe = models.CharField(max_length=10, blank=True, null=True)
date = models.DateField(blank=True, null=True)
updated = models.DateTimeField()
open = models.DecimalField(max_digits=10, decimal_places=4, blank=True, 
null=True)
high = models.DecimalField(max_digits=10, decimal_places=4, blank=True, 
null=True)
low = models.DecimalField(max_digits=10, decimal_places=4, blank=True, 
null=True)
close = models.DecimalField(max_digits=10, decimal_places=4, 
blank=True, null=True)
volume = models.IntegerField(blank=True, null=True)
average_volume = models.IntegerField(blank=True, null=True)

Le lundi 8 juin 2015 22:09:05 UTC+2, Oscar Buijten a écrit :
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---
> from django.core.management.base import BaseCommand, CommandError
> import json
> from collections import OrderedDict
> from yahoo_finance import Share 
> from data.models import MyichiTickers, MyichiHistoricalData
>
> exchange  = 'AMS'
> startdate = '2014-04-25'
> enddate   = '2014-04-29'
> minimum_avg_daily_volume = '10'
>
> class Command(BaseCommand):
> def handle(self, *args, **options):
> from yahoo_finance import Share 
> from data.models import MyichiTickers
> tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
> if tickers_for_exchange:
> for tickerlist in tickers_for_exchange:
> ticker = Share(tickerlist.ticker) 
> if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
> data = json.dumps(ticker.get_historical(startdate, enddate))
> data = json.loads(data)
> print data
>
>   snip  ---
>
> It may not be perfect, but it works.
> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
> u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
> u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
> u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
> u'Open': u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the 
> correct model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?
>
> Thanks!
>
> Oscar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/583b73b4-244f-4a14-95c6-eca2e81ff9ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.