Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40141 > unrolled thread
| Started by | io <maroso@libero.it> |
|---|---|
| First post | 2013-02-28 17:25 +0000 |
| Last post | 2013-02-28 14:13 -0500 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Import web content to csv only if values are different from those of an excel sheet io <maroso@libero.it> - 2013-02-28 17:25 +0000
Re: Import web content to csv only if values are different from those of an excel sheet Joel Goldstick <joel.goldstick@gmail.com> - 2013-02-28 14:13 -0500
| From | io <maroso@libero.it> |
|---|---|
| Date | 2013-02-28 17:25 +0000 |
| Subject | Import web content to csv only if values are different from those of an excel sheet |
| Message-ID | <512f92fa$0$40355$4fafbaef@reader1.news.tin.it> |
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.
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! :-)
[toc] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-02-28 14:13 -0500 |
| Message-ID | <mailman.2666.1362078796.2939.python-list@python.org> |
| In reply to | #40141 |
[Multipart message — attachments visible in raw view] — view raw
On Thu, Feb 28, 2013 at 12:25 PM, io <maroso@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web