Saturday, October 24, 2015

WikiHow: Get data using pageid

Get pageid using query API
?action=query&list=allpages&format=json&apfrom=A%24%24&aplimit=5

Other APIs to work on the obtained pageId
https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content
https://en.wikipedia.org/w/api.php?action=query&prop=revisions&pageids=27551355&rvprop=timestamp|user|comment|content
https://en.wikipedia.org/w/api.php?action=query&prop=revisions|pageprops&pageids=22989&rvprop=content
https://en.wikipedia.org/w/api.php?action=query&prop=revisions|pageprops&titles=Paris&rvprop=content
https://en.wikipedia.org/w/api.php?action=parse&pageid=27697087&contentmodel=wikitext
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&prop=info&format=json&pageids=27551355

Some other good APIs
https://www.mediawiki.org/wiki/API:Parsing_wikitext
https://www.mediawiki.org/wiki/API:Query
https://www.mediawiki.org/wiki/API:Query
https://www.mediawiki.org/wiki/API:Allpages
https://www.mediawiki.org/wiki/API:Categorymembers

Sunday, October 18, 2015

POST using jersey

Client client = ClientBuilder.newClient();
WebTarget target = client.target("target").path("path_text");;
              //path is optional

Form form = new Form();
form.param("action", "login");
form.param("lgname", "login_id");
form.param("lgpassword", "lgin_pass");
form.param("format", "json");

Response response = target.request().post(Entity.form(form));

Thursday, October 1, 2015

Conversion of wstring to PWSTR

Common examples
std::string s = SOME_STRING; // get temporary LPSTR (not really safe) LPSTR pst = &s[0]; // get temporary LPCSTR (pretty safe) LPCSTR pcstr = s.c_str(); // convert to std::wstring std::wstring ws; ws.assign( s.begin(), s.end() ); // get temporary LPWSTR (not really safe) LPWSTR pwst = &ws[0]; // get temporary LPCWSTR (pretty safe) LPCWSTR pcwstr = ws.c_str();


Solved problem:
Create( __in SomeMap &Metrics, __out PWSTR *metric ) { std::wstring *current = NULL; try { current = new std::wstring(); for (iterator iterator = Metrics.begin(); iterator != Metrics.end(); iterator++) { if (!current->empty()) { current->append (L";"); } current->append(L"{"); current->append(iterator->first.begin(), iterator->first.end()); current->append(L":"); current->append(iterator->second.begin(), iterator->second.end()); current->append(L"}"); } //Either of the following can be used. for the first one, it is directly converting wstring to PWSTR. //second one is using c_str() which converts first to PCWSTR. and then to PWSTR // Since it is first converting to PCWSTR, if we want to change the value later on of the *metric, it will cause memory corruption //*metric = &(*current)[0]; //*metric = const_cast<PWSTR> (current->c_str()); } catch (...) { } Cleanup: if (*metric == NULL) { PTR_FREE(current); } }