<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Magic 8 Ball w&#x2F; JSON and Python]]></title><description><![CDATA[<p dir="auto">OK, so I did a very simple "magic 8 ball" app in Python.  It is a springboard to using the OLED expansion board on my Intel Edison (which has buttons I want to utilize to make it a standalone app that will refresh (or just run again) when a button is pressed on the expansion board.  I have a lot to do to get the Edison up and working, so I am doing my dev on the Omega2+ and so far, from the command line, it is working great.  Again, nothing too outstanding, but another stepping stone.</p>
<p dir="auto">Here is the Python code.  I happen to have Python3 installed.</p>
<pre><code>#!/usr/bin/env python

from OmegaExpansion import oledExp
import random
import json

getnum = "answer"+str(random.randint(1,20))
with file('/smb/scripts/magic8ball.json', 'r') as answerfile:
	answer = json.load(answerfile)

oledExp.driverInit()
oledExp.setCursor(0, 0)
oledExp.write("+-------------------+")
oledExp.setCursor(1, 0)
oledExp.write("|Magic 8 Ball Speaks|")
oledExp.setCursor(2, 0)
oledExp.write("+-------------------+")
oledExp.setCursor(4, 0)
oledExp.write(answer[getnum])
oledExp.setCursor(7, 0)
oledExp.write("+-------------------+")

exit()

</code></pre>
<p dir="auto">Here is the .json with the answers.</p>
<pre><code>{
	"answer1": "It is certain.",
	"answer2": "It is decidedly so.",
	"answer3": "Without a doubt.",
	"answer4": "Definitely yes.",
	"answer5": "You may rely on it.",
	"answer6": "As I see it, yes.",
	"answer7": "Most likely.",
	"answer8": "Outlook good.",
	"answer9": "Yes.",
	"answer10": "Signs point to yes.",
	"answer11": "Reply hazy try again.",
	"answer12": "Ask again later.",
	"answer13": "Better not tell you now.",
	"answer14": "Cannot predict now.",
	"answer15": "Concentrate and ask again.",
	"answer16": "Don't count on it.",
	"answer17": "My reply is no.",
	"answer18": "My sources say no.",
	"answer19": "Outlook not so good.",
	"answer20": "Very doubtful."
}
</code></pre>
]]></description><link>http://community.onion.io/topic/1772/magic-8-ball-w-json-and-python</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 15:53:42 GMT</lastBuildDate><atom:link href="http://community.onion.io/topic/1772.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Mar 2017 16:05:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Magic 8 Ball w&#x2F; JSON and Python on Tue, 07 Mar 2017 16:05:46 GMT]]></title><description><![CDATA[<p dir="auto">OK, so I did a very simple "magic 8 ball" app in Python.  It is a springboard to using the OLED expansion board on my Intel Edison (which has buttons I want to utilize to make it a standalone app that will refresh (or just run again) when a button is pressed on the expansion board.  I have a lot to do to get the Edison up and working, so I am doing my dev on the Omega2+ and so far, from the command line, it is working great.  Again, nothing too outstanding, but another stepping stone.</p>
<p dir="auto">Here is the Python code.  I happen to have Python3 installed.</p>
<pre><code>#!/usr/bin/env python

from OmegaExpansion import oledExp
import random
import json

getnum = "answer"+str(random.randint(1,20))
with file('/smb/scripts/magic8ball.json', 'r') as answerfile:
	answer = json.load(answerfile)

oledExp.driverInit()
oledExp.setCursor(0, 0)
oledExp.write("+-------------------+")
oledExp.setCursor(1, 0)
oledExp.write("|Magic 8 Ball Speaks|")
oledExp.setCursor(2, 0)
oledExp.write("+-------------------+")
oledExp.setCursor(4, 0)
oledExp.write(answer[getnum])
oledExp.setCursor(7, 0)
oledExp.write("+-------------------+")

exit()

</code></pre>
<p dir="auto">Here is the .json with the answers.</p>
<pre><code>{
	"answer1": "It is certain.",
	"answer2": "It is decidedly so.",
	"answer3": "Without a doubt.",
	"answer4": "Definitely yes.",
	"answer5": "You may rely on it.",
	"answer6": "As I see it, yes.",
	"answer7": "Most likely.",
	"answer8": "Outlook good.",
	"answer9": "Yes.",
	"answer10": "Signs point to yes.",
	"answer11": "Reply hazy try again.",
	"answer12": "Ask again later.",
	"answer13": "Better not tell you now.",
	"answer14": "Cannot predict now.",
	"answer15": "Concentrate and ask again.",
	"answer16": "Don't count on it.",
	"answer17": "My reply is no.",
	"answer18": "My sources say no.",
	"answer19": "Outlook not so good.",
	"answer20": "Very doubtful."
}
</code></pre>
]]></description><link>http://community.onion.io/post/11856</link><guid isPermaLink="true">http://community.onion.io/post/11856</guid><dc:creator><![CDATA[Brad Buskey]]></dc:creator><pubDate>Tue, 07 Mar 2017 16:05:46 GMT</pubDate></item></channel></rss>