Re: "Data blocks" syntax specification draft

2018-05-21 Thread Chris Lindsay via Python-list
So this is a syntax for defining large blocks of static data in-line with
code.

If a block of static data is large enough to start to be ugly, a common
approach is to load the data from some other file, in a language which is
designed around structured data. YAML comes to mind - it has minimal
punctuation, and whitespace as syntax, with little in the way of syntax
ambiguity since it isn't already a scripting language.

What use-case do you foresee for your proposed new format, that isn't
already (better) accomplished by using a separate structured
data/serialisation language?

On 21 May 2018 at 10:21, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Mon, 21 May 2018 01:28:51 +0300, Mikhail V wrote:
>
> > Source examples on
> > Github will force a crappy font and replace tabs.
>
>
> Is that supposed to convince us that using mandatory TABs is a good idea?
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Chris
Open Cosmos

Any opinions given above are my own.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stock quotes off the web, py style

2018-05-16 Thread Chris Lindsay via Python-list
 >It serves a naked set of data, which happens to conform to the python
source code specification for dictionaries and consequently can be compiled
into a dictionary with 'eval', like so:

I would highly discourage any long-term usage (or any usage) of eval() in
this sort of context. If iextrading was compromised, a malicious third
party could simply start serving arbitrary python expressions (instead of
the dictionary-like data currently) and your script would execute it
unquestioningly.

Consider using ast.literal_eval() -
https://docs.python.org/3/library/ast.html#ast.literal_eval  for parsing
string representations of basic python datatypes.

On 16 May 2018 at 13:33, Friedrich Rentsch  wrote:

>
>
> On 05/16/2018 02:23 AM, Mike McClain wrote:
>
>>  Initially I got my quotes from a broker daily to plug into a
>> spreadsheet, Then I found Yahoo and wrote a perl script to grab them.
>> When Yahoo quit supplying quotes I found AlphaVantage.co and rewrote
>> the perl script.
>>  AlphaVantage.co has been down since last week and I found
>> iextrading.com has a freely available interface. Since it needs
>> a rewrite and I'm trying to get a handle on python this seems
>> like a good opportunity to explore.
>>  If someone would please suggest modules to explore. Are there any
>> upper level modules that would allow me to do something like:
>>
>> from module import get
>> def getAquote(symbol):
>>  url = 'https://api.iextrading.com/1.0/stock/()/quote'.format(symbol)
>>  reply = module.get(url)
>>  return my_parse(reply)
>>
>> Thanks,
>> Mike
>> --
>> Men occasionally stumble over the truth, but most of them pick
>> themselves up and hurry off as if nothing ever happened.
>>  - Churchill
>>
>
> I didn't know the site you mention. I've been getting quotes from Yahoo
> daily. The service they discontinued was for up to 50 symbols per page. I
> now parse a separate page of some 500K of html for each symbol! This site
> is certainly more concise and surely a lot faster. It serves a naked set of
> data, which happens to conform to the python source code specification for
> dictionaries and consequently can be compiled into a dictionary with
> 'eval', like so:
>
> >>> ibm = urllib2.urlopen ("https://api.iextrading.com/1.0/stock/IBM/quote
> ").read()
> >>> ibm = eval (ibm)
> >>> for item in sorted (ibm.items()): print '%-24s%s' % item
>
> avgTotalVolume  5331869
> calculationPriceclose
> change  -0.56
> changePercent   -0.00388
> close   143.74
> closeTime   1526414517398
> companyName International Business Machines Corporation
> delayedPrice143.74
> delayedPriceTime1526414517398
> high143.99
> iexAskPrice 0
> iexAskSize  0
> iexBidPrice 0
> iexBidSize  0
> iexLastUpdated  0
> iexMarketPercent0
> iexRealtimePrice0
> iexRealtimeSize 0
> iexVolume   0
> latestPrice 143.74
> latestSourceClose
> latestTime  May 15, 2018
> latestUpdate1526414517398
> latestVolume4085996
> low 142.92
> marketCap   131948764304
> open143.5
> openTime1526391000646
> peRatio 10.34
> previousClose   144.3
> primaryExchange New York Stock Exchange
> sector  Technology
> symbol  IBM
> week52High  171.13
> week52Low   139.13
> ytdChange   -0.0485148849103
>
> You would do multiple symbols in a loop which you enter with an open
> urllib object, rather than opening a new one for each symbol inside the
> loop.
>
> Frederic
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Chris
Open Cosmos

Any opinions given above are my own.
-- 
https://mail.python.org/mailman/listinfo/python-list