The following will dump all the data to the python tab (print it) from the default urban dictionary site.
You might want to find a site which delivers just simple text or parse out the joke or part of interest.
Make sure you have the HTTPClient service installed.
from java.lang import Stringhttp = Runtime.createAndStart("http","HTTPClient")print String(http.get("http://www.urbandictionary.com/"))
So the tough (and it should
So the tough (and it should not be very tough) part is parsing - so you get clean simple text to "speak"
given the following URL
http://www.ajokeaday.com/Clasificacion.asp?ID=64&Pagina=10
It comes back with all sorts of gobbly gook - but if you look closely - you'll find the interesting stuff always starts with
<div class="chiste">
Two strands of DNA were walking down the street. One says to the other, "Do these genes make me look fat?
</div>
I think with the following method
might allow this to work...
speech.speak(find_between( String(http.get("http://www.ajokeaday.com/Clasificacion.asp?ID=64&Pagina=10")),"<div class=\"chiste\">", "</div>")
"random jokes - would just be random categories and pages... you might have to strip more html formatting out with replace functions"
Analyzation of an HTML-Website
This is an good working method to get the important data (the changed classes) out of theese websites (it'll only work with theese):
https://krupp-gymnasium.eu/idesk/infodisplay/mods/link.local.php/panelI…
https://krupp-gymnasium.eu/idesk/infodisplay/mods/link.local.php/panelI…
It is a Java-Method and REALLY detailed and the opposite of an optimized code, but hey, it's working very good ...
Sorry, the code is partly in German:
Ma vo, warum in deutsch? Ist
Ma vo, warum in deutsch? Ist english nicht besser? Dann können andere leute auch das begreifen? Oder hab ich es falsch?
Of course English would be
Of course English would be better, but I had written this a few mounths ago. A few variable-names are partly German or use shortcuts of German words.
Although I think, it is understand-able ...
Thanks for sharing Ma. Vo. I
Thanks for sharing Ma. Vo. I was curious if you could tell me what you use it for. It looks like its final output is to print something. What does it print? How does it help you? How do you use it?
I use it to get the data
I use it to get the data (changed classes) out of theese two websites (posted above the code). They are displaying which teacher are ill or rooms are blocked, and so on.
Then I display the data in a better (/easier) way. This script worked already in an servlet to provide a website with only the "data" for one class (mostly my ; )). Currently it's running in an Android-App, there I worked with it further, save/load it, customize it further ...
But the main thing is this function (and the method to load the HTML from the website, which isn't always so easy at our school-server ..., they break the configuration and certificates regulary).
The data that comes back, is only an big, encapsulated array.
The many prints had been only for testing and debugging, I hadn't removes them, because when somewhere is an error, I can quickly find and fix it (or can persuade me, that the error is'nt at this part).
I hope I had expressed myself clearly ... ; ),
Marvin
I just decided to upload the whole class, it's completly implemented for Android ...
https://drive.google.com/file/d/0B3Q0--r6Z_6VVXlKYjVQSEpXa1E/edit?usp=s…
And sorry (wvantoorn) the variable- and method- names are partly german and all comments, too ...
I don't if Google can translate it, but it should be relativly clear what it does ...
important methods:
vertretungspeichern(Context ctx) -> this is called when the stored data should be updated, it only gives back an boolean, wether this was succesful or not (e.g. no network-connection)
=>Reading from the website->Analyzing it, Generating a JSON, Saving it
vertretunglesen(Context ctx, String klasse, int tag) -> this function is called when the data from the website is needed (to display it), it takes the class (e.g. "9E" (5A, 5B, 5C, 5D, 6A-D, 7A-D, 8A-D, 9A-E, EP, Q1, (Q2,) VK)) and the day (today ot tomorrow).
=>Reading from the storage->Get data out of JSON
alright - I tested this one
alright - I tested this one it works ...
Some things you will need to be careful with - special characters coming back from the Joke site - the joke creates a mp3 file on the file system with the name of the file being the text of the joke - if there are characters the filesystem does not support - it will fail - this particular joke works.. although I thought it was "funny" she say "Euro" for the dash -
Heh.. All Joking aside.. A challenge
I don't usually do much Python, because I'm working most of the time on the Java framework..
but here's "potentially" this could be a Python joke function for InMoov .. there were several (many) issues..
Illegal characters.. I had problems stripping bad stuff out.. html <br> carriage return need stripping out.. i wanted random jokes..
ok .. so its "almost" ready .. the only problem is .. I've disovered google does not accept text over a relatively short length... Sooooo.. you'll need to split up the text into block and then submit them to speech !
And if you want to get "fancy" you should split them up were word count > max value OR puctuation exists .. whatever comes first ! Have Fun !
unknown service org.myrobotlab.service.HTTPClient
Services are case sensitive
Hi Darek
Service names are case sensitive. You can start it like this from a script.
http = Runtime.createAndStart("http","HttpClient")
/Mats
Hi Mats,thanks for your
Hi Mats,
thanks for your help. Unfortunately, it still does not work:
mrl 1.0.1701
[python] [INFO] exec(String)
just in case I make "install
This has to do with
This has to do with conflicting HttpClient versions ..
Its such a popular library - that I'm betting more than one service included it as a dependency .. but they are with different version, the versions clash .. and BOOM
I'll figure out which is which ....
Wow ! .. That was a big mess.
Wow ! .. That was a big mess. Different versions of apach httpclient DO NOT PLAY WELL TOGETHER !!!
There was a evil mixture of 4.2.5 3.1 & 4.5.2 ... But kwatters & I got it all cleaned up.
Below was tested
I'm glad that it was only a
RemoteAdapter dependecies
Hi Grog
To aviod having to "install all" and only install the services that I really use, I added dependencies to RemoteAdapter. I thought that it was the correct place to add them. Where should the dependencies for each service be defined for MRL to work properly ?
Currently I can't start RemoteAdapter, It fails with message:
22:41:12.536 [runtime] ERROR c.m.f.Service [Service.java:2131] runtime error NoClassDefFoundError org/atmosphere/wasync/Encoder
I tried to "install all" but still the same error.
It works from Eclipse.
/Mats
Hi Mats, you had the right
Hi Mats,
you had the right idea of adding nettosphere as a dependency.
wasync is a websocket client library from the same project which gives us the webgui. _goodtimes_
RemoteAdapter should learn to interface with the WebGui.
It seems like you add them, then commented them out, then added them again.
They should be added, although at the moment I'm not seeing the httpclient dependecy... might be there, but the wasyc is definately there...
Is it worky now ?
Hi GroG I added them when I
Hi GroG
I added them when I started to test on the RasPi, because it wouldn't install otherwise.
I will make at test to see if it's enough to have only nettosphere as a dependency in RemoteAdapter.
It installs and starts now.
/Mats
RemoteAdapter
Hi GroG
You were 100% correct. It was only nettosphere that was needed as a dependency in RemoteAdapter.
It really exciting to test out RemoteAdapter. I created two scripts. One in each of the PI's. The script in the head pi starts all services in the head + RemoteAdapter. As a last step it the sends an SSH comnand to start MRL and the body script. The body script starts a services for the body and it's own instance of RemoteAdapter. Since I only have a speaker in the head, the body script sends a command to the head to say that the initialization of ther body script has completed. And it's all worky. AWSOME.
I will continue testing. RemoteAdapter is working far better than I ever expected.
Really great job.
Same problem
Hello everyone sorry to dig out this old solved post!
I meet the same problem as you did, which is when trying to start RemoteAdapter i get the error:
NoClassDefFoundError org/atmosphere/wasync/Encoder.
I tried to install all and it did not work either. I understood that you solved this by adding nettosphere as a dependency to RemoteAdapter. In order to do that i must clone the git under eclipse and add it? Is there an easier way?
Thank you for your time, All the best,
Nicolas Taguet.
Hi The workaround is to go to
Hi
The workaround is to go to the runtime tab => system => install all.
What version are you using ?