I see this question answered, but not easy to interpreter. Can someone redo this
ID: 3743668 • Letter: I
Question
I see this question answered, but not easy to interpreter. Can someone redo this assignment? I'm using Python version 2.7.8
Introduction
The information revolution is enabled by an abundance of APIs – or Application Program Interfaces. APIs are software layers that allow developers to share data between services in a common format. For web applications – which are what drive most everything nowadays, including mobile apps – the most common type of API uses what is called a RESTful interface. Understanding how to communicate with RESTful APIs will give you the power to make modern and compelling software that can use data from services such as Facebook and Twitter, and then do amazing things with that data.
Which is why, for your course project, you are going to create a Python application that gets data from a web API and displays it to the program user.
Activity Instruction
For this project, your program must meet the following requirements:
Use a graphical interface to prompt user for text to be sent to the Yoda Speak API
Understand the constraints of the Yoda Speak API and check the text to ensure that it meets those restraints before sending it. If it does not, tell the user what is wrong with it
Send the user’s text to the API and then display the result. If there is an error of any kind, inform the user of that error and ask them if they would like to try again
Once the result is successfully returned, give the user the option to save the result to a file on their computer.The result file must contain the following:
Name of your program
The date and time the data was fetched
The user’s input text
The server’s result
Explanation / Answer
MAJOR FEATURES
#1 Input/output Graphical User Interface
#2 Get output from Yoda Speak API
#3 Validate User Input
IMPLEMENTATION of PYTHON METHODS & DEMO
import requests
class Script:
__gui = None
def __init__(self, gui):
self.__gui = gui
inputtext = ""
errorflag = False
def callwebapi():
resp = requests.get('http://yoda-api.appspot.com/api/v1/yodish?text=' + inputtext)
if resp.status_code != 200:
raise ApiError('GET / {}'.format(resp.status_code))
print('Response Text {}'.format(resp.json()["yodish"]))
def setinput():
inputtext = input("Type a String = ")
def validate():
if(inputtext == ""):
errorflag = True
else:
errorflag = False
def run(self):
setinput()
validate()
callwebapi()
CONFIGURING JYTHON AND USING THESE PYTHON FUNCTIONS IN JAVA
[NOTE: THIS IS THE PYTHON INTERPRETER WHICH WORKS IN JAVA ENVIRONMENT]
import org.python.core.PyInstance;
import org.python.util.PythonInterpreter;
public class InterpreterJython
{
PythonInterpreter interpreter = null;
public InterpreterJython()
{
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
this.interpreter = new PythonInterpreter();
}
void execfile( final String fileName )
{
this.interpreter.execfile(fileName);
}
PyInstance createClass( final String className, final String opts )
{
return (PyInstance) this.interpreter.eval(className + "(" + opts + ")");
}
public static void main( String gargs[] )
{
InterpreterJython ie = new InterpreterJython();
ie.execfile("script.py");
PyInstance script = ie.createClass("Script", "None");
script.invoke("run");
}
}
KEY NOTES FOR SETTING UP EVERYTHING:
1) File names of these two files must be accurate and should be in same folder
2) Calls to API: API must work fine else error stack will be shown in result
Thank You.