I'm not sure that this is the right place to post this but...
A while ago someone posted that they were working on a method of importing live data from the stock markets into Scratch. I remember reading the post and being particularly interested as I've been working on a virtual stock market program in Scratch.
The problem is, I now can't find that post despite many forum searches. If I recall correctly the author was a fairly well known user, possibly Paddle2See or Jens.
Does anyone have any idea what I'm talking about or am I going mad...?
SB
Offline
You're not going crazy. There was a leaked beta of something called NetScratch a while back from a member of the Scratch Team's blog that would import data from the Scratch website, but I don't remember anything about stocks. It never worked online, and the beta seems to be lost forever (I swear they remotely deleted it from my flash drive
).

Offline
ScipioBellorum wrote:
I'm not sure that this is the right place to post this but...
A while ago someone posted that they were working on a method of importing live data from the stock markets into Scratch. I remember reading the post and being particularly interested as I've been working on a virtual stock market program in Scratch.
The problem is, I now can't find that post despite many forum searches. If I recall correctly the author was a fairly well known user, possibly Paddle2See or Jens.
Does anyone have any idea what I'm talking about or am I going mad...?
SB
I was working on a Python script that would use Scratch's remote sensors to import stock market data. I got it working for one stock but kind of lost interest as it was simpler to just use Python to work with the data directly and skip the Scratch part. Here is the Python script I was working with, if you want to take it further
import urllib
import re
from array import array
import socket
import time
HOST = '127.0.0.1' # IP address of the remote host (in this case, the local machine)
# to connect to Scratch on a different computer, just put in its IP address
PORT = 42001 # The same port as used by the server
# sendScratchCommand(cmd)
# this function packages a message according the Scratch Networking Protocol
# and then sends it off
def sendScratchCommand(cmd):
n = len(cmd)
a = array('c')
a.append(chr((n >> 24) & 0xFF))
a.append(chr((n >> 16) & 0xFF))
a.append(chr((n >> 8) & 0xFF))
a.append(chr(n & 0xFF))
scratchSock.send(a.tostring() + cmd)
def get_quote(symbol):
base_url = 'http://finance.google.com/finance?q='
content = urllib.urlopen(base_url + symbol).read()
m = re.search('class="pr".*?>(.*?)<', content)
if m:
quote = m.group(1)
else:
quote = 'no quote available for: ' + symbol
return quote
# Make a connection to Scratch
print("connecting...")
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scratchSock.connect((HOST, PORT))
print("connected!")
# Get value - report it if it has changed
OldQuote = 0
while 1:
Quote = get_quote('nyse:ge')
TimeStamp = time.asctime()
if Quote <> OldQuote:
sendScratchCommand('sensor-update StockPrice ' + str(Quote))
sendScratchCommand('sensor-update TimeStamp ' + '\"' + TimeStamp + '\"')
sendScratchCommand('broadcast "QuoteRefresh"')
print TimeStamp, Quote
OldQuote = Quote
else:
print TimeStamp
time.sleep(10)
scratchSock.close()
Offline
Paddle2See wrote:
ScipioBellorum wrote:
I'm not sure that this is the right place to post this but...
A while ago someone posted that they were working on a method of importing live data from the stock markets into Scratch. I remember reading the post and being particularly interested as I've been working on a virtual stock market program in Scratch.
The problem is, I now can't find that post despite many forum searches. If I recall correctly the author was a fairly well known user, possibly Paddle2See or Jens.
Does anyone have any idea what I'm talking about or am I going mad...?
SBI was working on a Python script that would use Scratch's remote sensors to import stock market data. I got it working for one stock but kind of lost interest as it was simpler to just use Python to work with the data directly and skip the Scratch part. Here is the Python script I was working with, if you want to take it further
import urllib
import re
from array import array
import socket
import time
HOST = '127.0.0.1' # IP address of the remote host (in this case, the local machine)
# to connect to Scratch on a different computer, just put in its IP address
PORT = 42001 # The same port as used by the server
# sendScratchCommand(cmd)
# this function packages a message according the Scratch Networking Protocol
# and then sends it off
def sendScratchCommand(cmd):
n = len(cmd)
a = array('c')
a.append(chr((n >> 24) & 0xFF))
a.append(chr((n >> 16) & 0xFF))
a.append(chr((n >> 8) & 0xFF))
a.append(chr(n & 0xFF))
scratchSock.send(a.tostring() + cmd)
def get_quote(symbol):
base_url = 'http://finance.google.com/finance?q='
content = urllib.urlopen(base_url + symbol).read()
m = re.search('class="pr".*?>(.*?)<', content)
if m:
quote = m.group(1)
else:
quote = 'no quote available for: ' + symbol
return quote
# Make a connection to Scratch
print("connecting...")
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scratchSock.connect((HOST, PORT))
print("connected!")
# Get value - report it if it has changed
OldQuote = 0
while 1:
Quote = get_quote('nyse:ge')
TimeStamp = time.asctime()
if Quote <> OldQuote:
sendScratchCommand('sensor-update StockPrice ' + str(Quote))
sendScratchCommand('sensor-update TimeStamp ' + '\"' + TimeStamp + '\"')
sendScratchCommand('broadcast "QuoteRefresh"')
print TimeStamp, Quote
OldQuote = Quote
else:
print TimeStamp
time.sleep(10)
scratchSock.close()
Wow.
Offline
Paddle2See wrote:
I was working on a Python script that would use Scratch's remote sensors to import stock market data. I got it working for one stock but kind of lost interest as it was simpler to just use Python to work with the data directly and skip the Scratch part. Here is the Python script I was working with, if you want to take it further
[etc.]
I thought it was you. I'm sorry to hear that you're no longer working on it as it could be very useful if coupled with my existing project. Unfortunately, I have no experience what so ever with Python or anything similar but I will take a look non the less.
Thanks for your help,
SB
Offline