0

PyPortal Custom Quotes
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PyPortal Custom Quotes

by makerdan on Sat Apr 27, 2019 5:24 pm

Hi,

I'm trying to do the PyPortal Quotes but using my own quotations. I can see doing this one of two ways:
1) Re-create the PHP script that could then run on my personal website as a way to retrieve quotes from a quotes database, stored as a .json file on the server.
2) Save a .json file of my quotes locally on the PyPortal (or on an SD card), which would then be retrieved and used by the tutorial code.

Currently I'm trying out the second option by saving a .json file to the CIRCUITPYTHON usb drive (in the same folder as code.py), but I am having trouble figuring out how to code the DATA_SOURCE variable as well as how to code the script to read the Author and Text on the .json file.

I don't have much at the moment, but here's what I do have:

import time
import board
import adafruit_pyportal
from adafruit_pyportal import PyPortal

# The current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]

# Set up where we'll be fetching data from
DATA_SOURCE = adafruit_pyportal.Fake_Requests(cwd+"/myquotes.json")

pyportal = PyPortal()


Any help would be much appreciated!

makerdan
 
Posts: 11
Joined: Sun Nov 18, 2012 9:05 pm
Location: Dallas, TX USA

Re: PyPortal Custom Quotes

by johnpark on Mon Apr 29, 2019 12:23 pm

You can do this by saving your .json file contents on the root of the PyPortal drive as local.txt and then use the default code.py for the project. It's set up to automatically grab the data in the local.txt file as a way of testing things when you don't have a connection to the Internet.

johnpark
 
Posts: 532
Joined: Wed Mar 25, 2009 2:15 pm

Re: PyPortal Custom Quotes

by makerdan on Tue May 21, 2019 2:21 pm

Thank you, this information is very helpful. I have managed to get my own quote displayed, but then how do I tell it to move to the next quotation? The default code for the Quote Book only displays the first quote in this situation.

makerdan
 
Posts: 11
Joined: Sun Nov 18, 2012 9:05 pm
Location: Dallas, TX USA

Re: PyPortal Custom Quotes

by johnpark on Tue May 28, 2019 1:42 pm

Ah, yes, the local.txt file is static, so you would need to make other adjustments to the code, such as have multiple keys in that file and randomize the key variable selector.

johnpark
 
Posts: 532
Joined: Wed Mar 25, 2009 2:15 pm

Please be positive and constructive with your questions and comments.