Import Json web data source to xls or csv
Hi,
i'm new to python and programming with it and so for json format.
I have my excel 2010 program with vba that does the following :
- read the data flow from http://bitcoincharts.com/t/markets.json
- elaborate it and puts it in excel 2010 for further calculations
What i'm willing to do is the same using Linux (xubuntu) and libreoffice.
I thought learning python would be a smart idea for dealing with json
format as it has a json library/module.
How do i manage to read the data source from http://bitcoincharts.com/t/
markets.json and then place it in different cell of a new or existing
xls worksheet?
I'm trying some code with SPE but i can't sort the problem and i'm
receiving many errors.
I just need currency, symbol, bid, ask, volume
This is the source code i was trying to use :
import json
import csv
import urllib
url = "http://bitcoincharts.com/t/markets.json";
response = urllib.urlopen(url);
data = json.loads(response.read())
f = csv.writer(open('file.csv', 'wb+'))
# use encode to convert non-ASCII characters
for item in data:
values = [ x.encode('utf8') for x in item['0'].values() ]
f.writerow([item['currency'], item['high']] + values)
Thanks for any help :-)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Import Json web data source to xls or csv
Hi Michael (name of my son) and thanks for the big help. I'm starting to love python sintax (did they call it python for the slim it is compared to other languages?) Your code didn't work immediatley as it was givin an indentation error that i sorted out quickly fixing the last two lines. It worked like a charm! :-) About your suggestions, i tried datanitro but that it only for excel and seems to not work under linux on playonlinux (as no linux support is given) I haven't tried the other solution you suggested, i will give it a try as soon as possible. What i'm trying to do is find a new programming language that can integrate with softwares like libre office cal or openoffice cal or excel as i had my prg working on windows and vba didn't have any issues, but now that i moved and try to do all on linux vba isn't 100 percent working and many system calls cannot be done. Do you know any place where i can start learning seriously python on the web? Last question : how can i set a condition in order to exclude from importing those rows that have both bid and ask values = none? I'll try to figure it out in the meantime but i'm a noob so any help will be appreciated. I actually started using SPE and have winpdb installed on my linux box. Thanks again for all the help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Json web data source to xls or csv
Il Wed, 20 Feb 2013 06:59:46 +, Cousin Stanley ha scritto:
> io wrote:
>
>>
>> How do i manage to read the data source from
>> http://bitcoincharts.com/t/markets.json
>> I just need currency, symbol, bid, ask, volume
>
> Following is a simple way load the json data and write the desired
> fields to a .csv file
>
>
> import json import urllib
>
> url= "http://bitcoincharts.com/t/markets.json";
>
> response = urllib.urlopen( url ) ;
>
> data = json.loads( response.read() )
>
> list_dicts = [ dict( this ) for this in data ]
>
> f = open( 'markets.csv' , 'w' )
>
> for this_dict in list_dicts :
>
> currency = str( this_dict[ 'currency'] )
> symbol= str( this_dict[ 'symbol' ] )
> bid = str( this_dict[ 'bid' ] )
> ask = str( this_dict[ 'ask' ] )
> volume= str( this_dict[ 'volume' ] )
>
> this_list = [ currency , symbol , bid , ask , volume ]
>
> this_str = ','.join( this_list )
>
> f.write( this_str + '\n' )
>
> f.close()
Thanks Stanley!
That's another nice code to use!
I was trying to sort out some condition but can't get this working :
import json
import urllib
import csv
url = "http://bitcoincharts.com/t/markets.json";
response = urllib.urlopen(url);
data = json.loads(response.read())
f = open("bitcoin.csv","wb")
c = csv.writer(f)
# write headers
c.writerow(["Currency","Symbol","Bid", "Ask", "Volume"])
#if str(d["bid"])and str(d["ask"])[0] not in ( 'none' ):
for d in data where str(d["bid"])and str(d["ask"])[0] not in ( 'none' ):
c.writerow([str(d["currency"]),str(d["symbol"]),str(d["bid"]),str(d
["ask"]),str(d["currency_volume"])])
--
http://mail.python.org/mailman/listinfo/python-list
Re: Import Json web data source to xls or csv
That worked perfectley! Thanks alot. -- http://mail.python.org/mailman/listinfo/python-list
Import web content to csv only if values are different from those of an excel sheet
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! :-)
--
http://mail.python.org/mailman/listinfo/python-list
Read csv file and create a new file
Hi, i have to files. First file is a csv file Second file is a plain text file where each row has a value (text) I want to be able to create a third file using data from the first file excluding the values listed in the second file. Example: First file: --- mtgoxeur12 24 36 mtgoxusd10 12 14 mtgoxpln2 4 6 Second file: mtgoxusd Third File (the resulting one) : mtgoxeur12 24 36 mtgoxpln2 4 6 Thanks to anyone that can help -- http://mail.python.org/mailman/listinfo/python-list
Re: Read csv file and create a new file
I'm a noob in python but my code looks like this :
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)
#apre un file di testo e legge il contenuto del file inserendolo in una
stringa
esclusioni = open('/home/io/exclusions.txt','r')
string = ""
while 1:
line = esclusioni.readline()
if not line:break
string += line
print string
# 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:
if not any(str(d["symbol"]) in s for s in string):
c.writerow([str(d["currency"]),str(d["symbol"]),str(d
["bid"]),str(d["ask"]),str(d["currency_volume"])])
esclusioni.close()
--
http://mail.python.org/mailman/listinfo/python-list
Re: Read csv file and create a new file
> Iterate over the file instead of looping manually. > > for line in esclusioni_file: > esclusioni.append(line.strip()) > print(esclusioni) the print was only to see if it was reading correct data but iìm not needing to see it. > Why are you checking d["symbol"] instead of d["currency"]? Maybe I > misunderstood the question. the file esclusioni.txt has the names of the market places that i want to exclude ... the correspoding marketplace name is found in the symbol value of the json imported data, that's why i'm comparing it with symbol. > Test like this for either set or list container type. Use whichever json > field is appropriate: > > if d["currency"] not in esclusioni: > >> c.writerow([str(d["currency"]),str(d["symbol"]),str(d >> ["bid"]),str(d["ask"]),str(d["currency_volume"])]) >> >> esclusioni.close() that's a nice approach ( if d["symbol"] not in esclusioni: )!!! Thanks i will give it a try ... i was getting crazy and my mind was looping dangerously! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Read csv file and create a new file
Neil, it works great! Just one question : what can i do for ignoring the case sensitive of the symbol? It wasn't working initially, then i wrote the values respecting case sensitive in the file esclusioni and all worked as a charm. I would just like to know if i could ignore the case senstive function. Thanks alot for your help. I'm in debt with you, i'll spend a pizza for you! -- http://mail.python.org/mailman/listinfo/python-list
Re: Read csv file and create a new file
The final working code is :
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)
#apre un file di testo e legge il contenuto del file inserendolo in una
stringa
esclusioni_file = open('/home/io/exclusions.txt','r')
esclusioni = []
for line in esclusioni_file:
esclusioni.append(line.strip())
#print(esclusioni)
# 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:
if d["symbol"] not in esclusioni:
#print d["symbol"]
c.writerow([str(d["currency"]),str(d["symbol"]),str(d
["bid"]),str(d["ask"]),str(d["currency_volume"])])
#esclusioni.close()
--
http://mail.python.org/mailman/listinfo/python-list
Re: Read csv file and create a new file
> Just use a tolower() method on both strings when you're comparing them. > Of course, that may not work well with international character sets. > Some characters in some languages have no lowercase equivalent, and > using toupper() has the same problem in other languages. > > Also, the approach to case insensitive differs between Python 2.x and > 3.x Thanks for the info ! What about str().lower()? -- http://mail.python.org/mailman/listinfo/python-list
Re: Read csv file and create a new file
What you wrote seems interesting but i haven't understood. Can you explain in simple words considering i'm italian and i'm not understanding so well some terms you use. Sorry, i'm sure you are suggesting something really valid but can't understand it. Marco. -- http://mail.python.org/mailman/listinfo/python-list
Python script not working on windows 7 but works fine on linux
The following scripts are working fine on linux but, using the same
version, can't work on windows because i receive the following message:
Script:
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/btc_trading/markets.csv","wb")
c = csv.writer(f)
#apre un file di testo e legge il contenuto del file inserendolo in una
stringa
esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r')
esclusioni = []
for line in esclusioni_file:
esclusioni.append(line.strip())
#print(esclusioni)
# 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:
if d["symbol"] not in esclusioni:
#print d["symbol"]
c.writerow([str(d["currency"]),str(d["symbol"]),str(d
["bid"]),str(d["ask"]),str(d["currency_volume"])])
#esclusioni.close()
Windows error :
Traceback (most recent call last):
File "C:\btc_trading\scripts
\import_json_2_csv_from_web_and_exclusions.py", line 10, in
f = open("/home/io/btc_trading/markets.csv","wb")
IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/
markets.csv'
>>>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python script not working on windows 7 but works fine on linux
Genius! The code i posted was an example. My real code was c:\btc_trading i was just missing the double slashes! Thanks , thankyou very much. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python script not working on windows 7 but works fine on linux
Thanks, btw ...i'm the IT guy! I was missing the double slash as dougas suggested!++Thanks anyway. -- http://mail.python.org/mailman/listinfo/python-list
HTTP GET REQUEST WITH PARAMETERS
HI, everyone, how can i make a HTTP GET REQUEST using python and passing parameters? I would like to recall my script from within openoffice basic and pass parameters to it. Some of the GET or POST are here : https://www.bitstamp.net/api/ thanks for anyhelp -- http://mail.python.org/mailman/listinfo/python-list
Re: Having trouble importing the python turtle on idle
On Sat, 16 May 2020 at 4:38 PM KINGHAMED io wrote: > Hello my name is Hamed > I have purchased python for kids. > I have installed idle and Python launcher 3.8.3 with my 11 inch MacBook > Air (Mac OS Sierra)version 10.12.6 > I have followed all the instructions all the way through for installation > I even downloaded activetcl and had no issues with instructions until > chapter 4 page 45 > which is importing the python turtle on to my screen. > However I have troubleshooted every possible way to get this right even > uninstalling and reinstalling Python several times. > Can you please advise me on how to import the python turtle. > -- https://mail.python.org/mailman/listinfo/python-list
