Import web content to csv only if values are different from those of an excel sheet

Joel Goldstick joel.goldstick at gmail.com
Thu Feb 28 14:13:14 EST 2013


On Thu, Feb 28, 2013 at 12:25 PM, io <maroso at libero.it> wrote:

> Hi,
>
> i have the following python script that reads json data from a website
> and writes it in a csv file that i will then import to excel. (i have
> just started since a week with py so i'm a noob!) :
> -------------------------------------------------------
>
> import json
> import urllib
> import csv
>
> url = "http://bitcoincharts.com/t/markets.json"
> response = urllib.urlopen(url);
> data = json.loads(response.read())
>
> f = open("/home/io/markets.csv","wb")
> c = csv.writer(f)
>
> # write headers
> c.writerow(["Currency","Symbol","Bid", "Ask", "Volume"])
>
> for d in data :
>     if d["currency"] <> "SLL":  #esclude la valuta di secondlife SLL
>         if d["bid"] is not None and d["ask"] is not None:
>             c.writerow([str(d["currency"]),str(d["symbol"]),str(d
> ["bid"]),str(d["ask"]),str(d["currency_volume"])])
>
> ------------------------------------------------------
>
> I have an .ods file (libre calc - i'm on linux) where i have in a sheet
> called "exclusions" a list of names (symbol) the i want to exclude during
> the import from web.
>

If you could output this file as csv you don't have a difficult problem.
If you can't, I found this:
http://stackoverflow.com/questions/4745024/spreadsheet-to-python-dictionary-conversion
which discusses reading ods files.

>
> I would like to modify my script so that it can parse each row in the
> "exclusion" sheet and if "symbol"  = "parsed row value" then don't write
> it to the csv file ... to loop on all values in the "exclusion" sheet.
>
> I know it's certainly possible but i don't know how to do that.  (if it
> results easier having the exclusion list in a text file it's not a
> problem, i'm not really stuck with librecalc!)
>
> Thanks in advance to any helpful soul!  :-)
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130228/d75b7043/attachment.html>


More information about the Python-list mailing list