Git Product home page Git Product logo

Comments (9)

DevMoore94 avatar DevMoore94 commented on August 15, 2024

Sounds fine to me. Would the python function still generate the words that are being used?

from textthem.

syntonym avatar syntonym commented on August 15, 2024

Yes, but it would be modified to only return json.

from textthem.

DevMoore94 avatar DevMoore94 commented on August 15, 2024

alrighty.

from textthem.

DevMoore94 avatar DevMoore94 commented on August 15, 2024

Accidently closed this. Realize the random generator still needs to be styled. Loving the changes though. got everything setup and installed on my laptop at home.

from textthem.

syntonym avatar syntonym commented on August 15, 2024

I've implemented the changes on https://github.com/syntonym/TextThem/tree/merge_random, but it's... slow. Each time the "random" button is pressed, an ajax request is send to /RandomGenerator which returns a json with {adjective: [adjective], noun: [noun]} and then entered in the form. But the request is still a request and needs some time to return.

Another possibility would be to load the entire dict of random words when loading the page and doing the random stuff in javascript only. Or maybe just load a subset of the dict. Or maybe load random words as soon the page loads.

To checkout my changes just clone my merge_random branch.

from textthem.

DevMoore94 avatar DevMoore94 commented on August 15, 2024

Looking good! Just trying to understand what you are doing,

$("#InputMessage").val(response.adjective + " " + response.noun);

This grabs the adjective and noun variables that were returned by the generatemessage() function correct? I am not that proficient in java script :P

from textthem.

syntonym avatar syntonym commented on August 15, 2024

$.getJSON("/RandomGenerator", function(response) {
This will get the json object lacated at "/RandomGenerator" (you can visit it with your webbrowser too see how it looks like) and pass it to the anonymous function as response.

$("#InputMessage").val(response.adjective + " " + response.noun);
This will then locate the form with the id=#InputMessage and set its value to response.adjective + " " + response.noun.
response is something like:
{ "adjective" : "greedy", "noun" : "rabbit" }
a simple json which is often used in compound with javascript and works similiar to a python dict. Infact python dicts can easy be converted to json with flask.jsonify which is used in TextThem.py line 151.

from textthem.

DevMoore94 avatar DevMoore94 commented on August 15, 2024

Makes sense! so what are the advantages to using json?

from textthem.

syntonym avatar syntonym commented on August 15, 2024

Json is a simple format for data and especially suited for "small things" like this. An alternative to json is XML but json is way more human readable.

from textthem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.