-
1Step 1
Setup Parts
Connect your Omega, Expansion Dock, and OLED Expansion as shown. -
2Step 2
Setup Wifi
You will need to setup wifi so that we can install python and fetch stock data from google:wifisetup
Follow the instructions and give the Omega access to your wifi network.
-
3Step 3
Update and Install Python
We will need to install the full version of Python so that we have access to some libraries necessary for webscraping:opkg update opkg install python
You may or may not need to clear some space on your Omega for the installation. If you are doing this right out of the box, you should be fine.
-
4Step 4
Create the Shell Script
Navigate to your "/" directory. Create the shell script which we will be using:cd / cat > stock.sh
Now paste the following code (You can save and exit the command by entering CTRL + D):
#!/bin/sh oled-exp -c echo $1 > /root/ticker.txt VAR=$(python ./stock_script.py) oled-exp -i oled-exp write $VAR
-
5Step 5
Create the Python Script
Now lets do the same with our python script.cat > stock_script.py
#!/usr/bin/env python import urllib
import json
myfile = open('/root/ticker.txt', 'r') rg=myfile.read() site="http://www.google.com/finance/info?q="+rg
jfile=urllib.urlopen(site) jsfile=jfile.read()
jsfile=jsfile.replace("\n","") jsfile=jsfile.replace("/","") jsfile=jsfile.replace("]","") jsfile=jsfile.replace("[","")
a=json.loads(jsfile)
ticker=a['t'] price=a['l_fix'] info=ticker+":"+price
print info -
6Step 6
Change Permissions
Make both files we just created executable by entering this:chmod +x stock.sh stock_script.py
-
7Step 7
Execute Script
Now let's see how Apple is doing.
./stock.sh AAPL
-
8Step 8
Going Further (optional) :
To take the project one step further, let's schedule our script to run every minute. To do this, enter the command:crontab -e
You will be taken to the vi-editor of the scheduling file. Add the following line to your file and make sure to end the file with an empty line or #.
*/1 * * * * /stock.sh AAPL
You can save and quit the editor by entering ZZ.
Using this project as a template, we can go even further with webscraping projects. Maybe build a new headline streamer or an up to date weather tracker.
-
9Step 9
Complete!
Parts of this project can and are encouraged to be used in other projects.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.