Filtering JSON From Twitter's API - json

I am currently pulling data from Twitter's API through a Node.js connection running on my computer. Here's the heart of my search:
///
var param = {q: "Futbol -filter:retweets -filter:replies", lang: "en", result_type: "popular", count: 10}
client.get('search/tweets',param,function(error,tweets,response){// MY SEARCH GOES HERE}
The git repo is here: https://github.com/KingOfCramers/Twitter-Stream-JSON-in-Node
I have a few questions because I am confused about the twitter syntax for Node.js.
First, I pass it to "q" any information relating to a search. What are those parameters called? What page on the Twitter API lists all of them?
Secondly, I am currently passing other arguments as well, such as lang and result_type. I want to tailor my search to specific accounts. Is there a parameter to search by username or the id of the user on Twitter? Eventually I want to stream twitter JSON data from specific groups, like Congresspeople (a different request, client.stream()).
Thanks!

You are using standard search operators, which are explained here. If you want to filter your search by specific accounts, you need to use from: query parameter described in that page.

Related

How to make Simple-JSON variable template query in grafana?

I am trying to create a dynamic variable for a graph using a kdb+ database, which requires the Simple-JSON plug in. However, I am struggling to figure out how to write the query in the Query search bar under Variables on my Dashboard.
I have looked into the documentation found here but there is only a few mentions of the templating feature for variables in grafana, but nothing on how to do it.
https://github.com/grafana/simple-json-datasource/blob/master/README.md
You can write arbitrary text in the timeserie query, it doesn't need to be one of the hardcoded metrics that /search returns.
There is also the simpod json datasource plugin.
https://grafana.com/grafana/plugins/simpod-json-datasource
built on top of the Simple JSON Datasource. It has refactored code, additional features and active development.
One of the "additional features" is an "Additional JSON Data" tab where you can use variables. {"key": $variableValue}
It actually turns out that the adaptor for kdb+/grafana needs it's search function overloaded to be able to accept variables and return a string (or something that grafana can understand).

How to dynamically auto populate a input field uisng Nodejs and MySQL?

I have a field in my website where I want users to enter book names that they can checkout from the database. I want it so that when they start typing the names I want suggestions or drop down under the input box matching the name of the book they are typing.
Is it possible to achieve something like this? I have a books table in my MySQL database and I am using Nodejs as my backend. I have searched a lot online but did not find anything related to this online. Therefore, I decided to ask the question here.
You have to send AJAX request with type GET and send the typed character to the Backend.
and in backend you have to do query for ex :select * from book where name like %input%
Then you have to return the result as an array to the front-end.
Finally, in your front-end code you have to render the result array under the input.
Also, you can use any ready jquery plugin to do this task in front-end code.
The UI element is commonly called a "typeahead" or autocomplete.
Twitter release their frontend component as a jQuery plugin called typeahead.js. Most frontend frameworks will have an equivalent plugin or component.
The backend datasource for the books is up to you to implement.
For small datasets you can render the required book data within the page so it is directly accessible from your javascript.
For large datasets you will probably need to create a backend "book search" service in Nodejs. Typeahead libraries can send that user input to a URL via an AJAX request and the service returns the matching results, usually as a JSON object.
Code for geek example for your stack.
You can make a drop-down menu with book names and using ajax you can get value from the input and search in database and display data .
I suggest you to use mongo db as database.
You can find tutorials in w3 schools or
in malayalam https://www.youtube.com/c/Crossroadstalk

How to make free jqgrid filter in url human readable

Free jqgrid reads data from server using json format.
Filter condition is created using jqgrid advanced search, toolbar search or in code.
It is read from GET request query string filters parameter using
var urlFilters,
namedParameters = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'),
parameters = {},
nameAndValue,
$grid = $("#grid"), i;
for (i = 0; i < namedParameters.length; i += 1) {
nameAndValue = namedParameters[i].split('=');
parameters[nameAndValue[0]] = decodeURIComponent(nameAndValue[1]);
if (nameAndValue[0] === "filters") {
urlFilters= decodeURIComponent(nameAndValue[1]);
}
}
$grid.jqGrid({
postData: { filters: urlFilters }
datatype: "json",
This requires passing encoded filters condition url which is not human readable and editable:
http://localhost//Desktop?filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22Baas%22%2C%22op%22%3A%22eq%22%2C%22data%22%3A%22KLIENT%22%7D%2C%7B%22field%22%3A%22Liigid%22%2C%22op%22%3A%22eq%22%2C%22data%22%3A%22%22%7D%5D%7D
Sometimes users needs to edit browser url directly to create new filter condition ?
How to make url human readable so that it can edited directly ?
How to force jqgrid to create advanced and toolbar search conditons in OData or other format which does not need escaped using % when passed in url ?
Free jqgrid has OData plugin.
How to extract OData search filter creation form this plugin and allow jqgrid to serialize search condition in this format and parse it back to show in advanced search filter?
Or is it possible modify current search condion so that " (%22) is not used in it ?
There are related questions in How to force jqgrid to query data using OData in query string and in How one could use server side sorting and paging with Azure Mobile Services
but I dont know which is best way to implement this.
OData is striclty not required. Maybe some simple change in free jqgrid search condition serializer and deserializer allows to make it human editable in URL. However using OData makes API more standardized.
ASP.NET MVC4 and jquery are used.
I personally use Fiddler very active. It's free Tool which can be downloaded from here. Fiddler allows to catch full HTTP traffic. It includes additionally some tools which simplify encoding and decoding of typical HTTP traffic.
After starting Fiddler you can choose in Tool the menu item "TextWizard" or use Ctrl+E. After that you will get very simple interface which allows you to decode/encode the filters value. For example you can insert the filter value from your question %7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22Baas%22%2C%22op%22%3A%22eq%22%2C%22data%22%3A%22KLIENT%22%7D%2C%7B%22field%22%3A%22Liigid%22%2C%22op%22%3A%22eq%22%2C%22data%22%3A%22%22%7D%5D%7D at the top part of the Wizard and choose URLDecode as transform operation. You will see immediately the decoded results
You can copy the result modify it and decode back. For example the filter Name cn "bob" should be written as {"groupOp":"AND","rules":[{"field":"Name","op":"cn","data":"bob"}]}. Using the same tool and choosing URLEncode operation you will get
Thus you can use filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22Name%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22bob%22%7D%5D%7D as the URL.

How to Update Ember Model to Show JSON Search Response

I feel like this answer to this question is trivial, but I am having a difficult time figuring out how to do this the 'Ember way'.
Quick problem background: I am creating a recipe app with Ember frontend and a Rails API backend. I am implementing a search feature to find recipes based on ingredients. I have already configured my Rails API endpoint which sends back the correct records as JSON.
Ember.$.get('/recipes_query', {query: query})
.then(function(reponse) {
// Do something here
});
Now all I need to do is display these. What I am confused about is how to handle the data when it is retrieved (or in other words, how to push these to the store, and then ONLY show the most recently retrieved results). I could push these results to the store and then use a filter to display the correct results, but this seems like an extra step - the JSON response already contains everything I need to display. What is the Ember convention for performing this simple task?
It would be trivial answer if you would use query instead of jQuery.get, so if possible, refactor to:
this.store.query('recipe', {query: query})
.then(records => {
// you have everything you need as records
});

Whats the REST way of showing forms to user

I was reading this Questions regarding REST
What exactly is RESTful programming?
While reading i get that the client is independent of server and client don't need to construct anything.
I want to know that when we are building forms like user registration . Then what is the REST way of doing it.
I mean when i do GET for /user/new then
Does the server has to send the complete FORM in html
Only send fields in JSON and form is constructed by client itself
But then again there will be many complexities, if i just send the fields, then what things like
Hidden fields
Default value for select boxes
what about some logic like this field can'r be greater than 30 etc
REST is, as you're already aware, a way of communicating between a client and a server. However, the issue here is what is being defined as the "client". Personally, I tend to consider that the browser itself is not in itself the client: instead, the client is written in JavaScript, and the browser is merely a conduit to executing it.
Say for the sake of argument that you wish to view the details of user '1414'. The browser would be directed to the following location:
/UserDetails.html#1414
This would load the static file ViewUser.html, containing all the form fields that may be necessary, as well as (via a <script> tag) your JavaScript client. The client would load, look at the URL and make a RESTful call to:
GET /services/Users/1414
which would send back JSON data relating to that user. When the user then hits "save", the client would then make the following call:
PUT /services/Users/1414
to store the data.
In your example, you wanted to know how this would work with a new user. The URL that the browser would be directed to would be:
/UserDetails.html#0
(or #new, or just # - just something to tell the JavaScript that this is a new client. This isn't a RESTful URL so the precise details are irrelevant).
The browser would again load the static file ViewUser.html and your JavaScript client, but this time no GET would be made on the Users service - there is no user to download. In addition, when the user is saved, this time the call would be:
POST /services/Users/
with the service ideally returning a 302 to /services/Users/1541 - the location of the object created. Note that as this is handled in the client not the browser, no actual redirection occurs.
"Forms" for hypermedia APIs could be rendered in a "forms aware" media type like for instance Mason (https://github.com/JornWildt/Mason), Hydra (http://www.markus-lanthaler.com/hydra/) or Sirene (https://github.com/kevinswiber/siren). In Mason (which is my project) you could have a "create user" action like this:
{
"#actions": {
"create-user": {
"type": "json",
"href": "... URL to resource accepting the POST ...",
"method": "POST",
"title": "Create new user",
"schemaUrl": "... Optional URL to JSON schema definition for input ..."
"template": {
"Windows Domain": "acme"
}
}
}
}
The client can GET a resource that include the above action, find it be the name "create-user" and in this way be told which method to use, where to apply it, how the payload should be formated (in this case its JSON as described by an external schema definition) and some default values (the "template" object).
If you need more complex descriptions (like selection lists and validation rules as you mention) then you are on your own and will have to encoded that information in your own data - or use HTML or XForms.
There are multiple ways to do what you want.
You can use GET for /user/new along with a create-form link relation to get a single link. This can in plain HTML or HTML fragment, or a schema description, practically anything you want (the result will be less reusable than the other solutions).
You can use a standard MIME type which supports form descriptions. For example HAL with a form extension or collection+json.
You can use an RDF format, like JSON-LD with a proper vocab like Hydra.