Passing parameters to YQL using Java - java

I am using the following code:
String zip = "75227";
String str = "http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20" +
"City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22" +
"food%20pantries%22%20and%20zip%3D%22" + zip +"%22%20and%20(category%3D%2296927050%22%20or" +
"%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)";
Document doc = Jsoup.connect(str).get();
and it is producing the results I want by replacing the zip code value. I would like to also change the location. I tried doing the same I did with the zip code by doing this:
String zip = "32207";
String service = "food pantry";
String testOne = "http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20" +
"City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22" +
service + "%22%20and%20zip%3D%22" + zip +"%22%20and%20(category%3D%2296927050%22%20or" +
"%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)";
When used this way the variable "service" gave me an error.
I initially tried to use the yql table like this:
String search = "http://query.yahooapis.com/v1/public/yql?q=";
String table = "select Title, Address, City, State, Phone, Distance from local.search where " +
"query=\"food pantries\" and zip=\"75227\" and (category=\"96927050\" or category=" +
"\"96934498\") | sort(field=\"Distance\")";
String searchText = search + table;
UPDATE:
Here is the error I am getting:
Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=505, URL=http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22food pantry%22%20and%20zip%3D%2232207%22%20and%20(category%3D%2296927050%22%20or%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:418)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:86)
However, this did not work either. Any ideas on how I can do this search and provide the service and zip code as variables?

Have you tried replacing String service = "food pantry"; with String service = "food%20pantry"; ?
EDIT:
and it is "food pantry" or "food pantries"... ?

Related

How to use Apache Tika to extract the "Subject” field by using Apache Metadata class ?

I'm trying to extract the "Subject" field from an email, but am having some trouble . I was able to get the "To" and "From" fields already, like so :
String messageTo = tikaMetadata.MESSAGE_TO; //Works fine
String toField = tikaMetadata.get(messageTo); //Works fine
System.out.println("From field is : " + fromField); //Works fine
System.out.println("To field is : " + toField); //Works fine
String messageSubj = tikaMetadata.getValues("Message:Raw-Header:Subject");
String subjField = tikaMetadata.get(messageTo); //Doesn't Work
How would we extract the subject field by using Tika ?
any tips helpful thanks
You can try two ways:
String subjectObs = tikaMetadata.get(tikaMetadata.SUBJECT);
but where.SUBJECT is deprecated
String subject = tikaMetadata.get(TikaCoreProperties.DESCRIPTION);probably the substitute that is closest to Metadata.SUBJECT (for more details about TikaCoreProperties look at this: tika documentation)

Neo4j Java OGM select with lock

I am trying to select a path with locking the last node in that path using Java OGM for Neo4j.
To do that in cypher I have written the following query:
String q = "Match path = (p:Root) - [*1..100]-(m:Leaf) WHERE m.State = 'Non-Processed' WITH m,p,path ORDER BY length(path) Limit 1 SET m.State = 'Processing' RETURN path"
It selects the necessary path with locking the last leaf(by changing its State property).
However, when I try to execute this query:
session.query(Path.class, q, propertyMap)
I get a java.lang.RuntimeException: query() only allows read only cypher. To make modifications use execute()
What is the proper way to do this?
You're probably using an older version of neo4j-ogm which had the restriction on session.query(). Please upgrade to neo4j-ogm 1.1.4
Found a (probably not the best) solution.
String uid = UUID.randomUUID().toString();
String lockQuery = "Match path = (p:Root) - [*1..100]-(m:Leaf)"
+ "WHERE m.State = 'Non-Processed' "
+ "WITH m,p,path ORDER BY length(path) Limit 1 SET m.lock = " + uid
session.execute(lockQuery);
String getQuery = "Match path = (p:Root) - [*1..100]-(m:Leaf)"
+ "WHERE m.lock = " + uid + "RETURN path";
Path path = session.query(Path.class, getQuery, new Hashmap<String, Object>());
Will this work?

java / jsoup - retrieve language

i use jsoup to crawl content from specific website´s.
Example, meta-tags:
String meta_description = doc.select("meta[name=description]").first().attr("content");
What i need to crawl as well is the language, what i do:
String meta_language = doc.select("http-equiv").first().attr("content");
But what is thrown:
java.lang.NullPointerException
Anybody could help with with this?
Greetings!
Try this:
String meta_language = doc.select("meta[name=http-equiv]").get(0).attr("content");
System.out.println("Meta description : " + meta_language);
However if you have a list of content in your meta tag then you can use this :
//get meta keyword content
String keywords = doc.select("meta[name=keywords]").first().attr("content");
System.out.println("Meta keyword : " + keywords);

Android Programming - Post Google Form/Spreedsheet (REQUIRED FIELD)

So I have successfully post data onto a Google Spreadsheet using the Google Form source. Everything works perfect UNTIL I make the field (in the Google Form) "required." When I do that, the Android Emulator still responds as if the information sent was properly saved. But on the Google spreadsheet it isn't there.
Am I missing something?
This is my AsyncTask:
new BackgroundTask().execute(
"https://docs.google.com/forms/d/10QStmb9Nr-hcfv889FMSNTZdA_hNUErxeK7vISzkx0E/formResponse",
student.FirstName, "entry_2030274183=",
student.LastName, "entry_1558758483=",
student.Age, "entry_1871336861=",
student.Gender, "entry.2013677542=",
student.Grade, "entry_1921311866=");
This is my Background.
protected String doInBackground(String... params) {
HttpRequest reg = new HttpRequest();
String URL = params[0];
String FirstName = params[1];
String FirstNameEntry = params[2];
String LastName = params[3];
String LastNameEntry = params[4];
String Age = params[5];
String AgeEntry = params[6];
String Gender = params[7];
String GenderEntry = params[8];
String Grade = params[9];
String GradeEntry = params[10];
#SuppressWarnings("deprecation")
String data =
FirstNameEntry + URLEncoder.encode(FirstName) + "&" +
LastNameEntry + URLEncoder.encode(LastName) + "&" +
AgeEntry + URLEncoder.encode(Gender) + "&" +
GenderEntry + URLEncoder.encode(Age) + "&" +
GradeEntry + URLEncoder.encode(Grade);
String response = reg.sendPost(URL, data);
return response;
}
Do I need to put something in the entries if it is a required field?
If you want to look at the HttpRequest class go here (Not My Code):
Secure HTTP Post in Android
Much Appreciated
The only way I can immediately think of is by processing the response and then making your app behave accordingly.
For instance - I tried one test form and if the request send had some required field empty, then the HTTPResponse contains "Looks like you have a question or two that still need attention".
Another way would be to validate if the save was actually successful by searching for the text you gave in the "Confirmation Page".
In both cases, you should be able to differentiate between a successful post and a failed one.

sending multiple parameters through query string in servlet

I want to send multiple parameters to a servlet named cart using this code.but it isending null.plz help.rs is a reference to resultset here
while(rs.next())
{
String name=rs.getString("name");
int cost=rs.getInt("cost");
out.println("\n");
out.println("Name: "+name);
out.println("\nPrice: "+cost);
out.println("\n<a href=\'cart\'?n=name&&c=cost>Add to Cart</a>");
}
There are several problems with the way the link is constructed.
This should work:
out.println("\n<a href='cart?n=" + name + "&c=" + cost + "'>Add to Cart</a>");
In addition, it may be necessary to URL encode the content of name if it can contain characters with special meaning in an URL.

Categories