I am attempting to connect to a DB on Cloudant. I created the DB from a JSON and uploaded it to Cloudant here: DeanRadar
I copied the info byte for byte into another JSON on my server including the "_id" and "_rev". If I call the JSON directly it works fine, but I can not get the code to work when I enter the URL given above.
I am guessing the URL is just a place holder and it gets resolved before returning it to my browser, like it is supposed to have a ".json" on the end of it or something that the browser can read but not the code. I do not know enough about Cloudant, Couch, angular, etc to know what I am looking for. I have done plenty of PHP/SQL databases but this is my first attempt with cloudant/jason/angular.
Here is the code in question (ignore the fact that I declare dbURL twice, it is there to show what I have used)
var dbURL = 'https://deanradar.cloudant.com/tempdata/80d7d28d9e96778ad3bf4531817ab190';
var dbURL = 'data/tempData.json';
$http.get(dbURL).success(function(data) {
tempDataDeferred.resolve(data);
});
This works, when I access the JSON on my server copied from the cloudant DB, but swapping the dbURL lines (accessing the direct URL for the cloudant DB) returns nothing. You can take that same URL and slap it into your browser address bar and see the info exactly as it sits in the JSON.
Grabbing the "[API URL+]" address doesn't help, it won't even resolve in the browser. Any idea what I need to do to access the DB?
Check this document
https://cloudant.com/for-developers/crud/#browser-update
although in examples they are using jquery.couch you can check the original code and apply it to your angularjs app
Related
The following code used to work but not anymore and I'm seeing junk HTML with success code of 200 returned.
response = urlopen('https://www.tipranks.com/api/stocks/stockAnalysisOverview/?tickers='+symbol)
data = json.load(response)
If you open the page in chrome you will see the JSON file format. But when opened in python I'm now getting:
f1xx.v1xx=v1xx;f1xx[374148]=window;f1xx[647467]=e8NN(f1xx[374148]);f1xx[125983]=n3EE(f1xx[374148]);f1xx[210876]=(function(){var
P6=2;for(;P6 !== 1;){switch(P6){case 2:return {w3:(function(v3){var
v6=2;for(;v6 !== 10;){switch(v6){case 2:var O3=function(W3){var
u6=2;for(;u6 !== 13;){switch(u6){case 2:var o3=[];u6=1;break;case
14:return E3;break;case 8:U3=o3.H8NN(function(){var Z6=2;for(;Z6 !==
1;){switch(Z6){case 2:return 0.5 - B8NN.P8NN();break;}}.....
What should I be doing to adapt to the new backend change so that I can parse the JSON again.
It is a bot protection, to prevent people from doing what you are doing. This API endpoint is supposed to be used only by the website itself, not by some Python script!
If you delete your site data and then freshly access the page in the browser, you'll see it first loads the HTML page that you see which loads some JavaScript, which then executes a POST to another URL with some data. Somewhere in the process a number of cookies get set and finally the code refreshes the page which then loads the JSON data. At this point visiting the URL directly returns the data because the correct cookies are already set.
If you look at those requests, you'll see the server returns a header server: rhino-core-shield. If you google that, you can see that it's part of the Reblaze DDoS Protection Platform.
You may have luck with a headless browser like ghost.py or pyppetteer but I'm not sure how effective it will be, you'll have to try. The proper way to do this would be to find an official (probably paid) API for getting the information you need instead of relying on non-public endpoints.
I'm working on a simple ruby script with cli that will allow me to browse certain statistics inside the terminal.
I'm using API from the following website: https://worldcup.sfg.io/matches
require 'httparty'
url = "https://worldcup.sfg.io/matches"
response = HTTParty.get(url)
I have to goals in mind. First is to somehow save the JSON response (I'm not using a database) so I can avoid unnecessary requests. Second is to check if the new data is available, and if it is, to override the previously saved response.
What's the best way to go about this?
... with cli ...
So caching in memory is likely not available to you. In this case you can save the response to a file on disk.
Second is to check if the new data is available, and if it is, to override the previously saved response.
The thing is, how can you check if new data is available without doing a request for the data? Not possible (given the information you provided). So you can simply keep fetching data every 5 minutes or so and updating your local file.
I have this URL: http://localhost:.../home/blogpost/#'I want to get this string'
I get it when pressing:
#item.Title
#item.Title is from my database and that string will change. Now I need to get the 'I want to get this string' string on that page so that I can do a if statement with it, like this:
#if(#item.Title == 'I want to get this string')
Any suggestions?
The target attribute (the part of an URI after the #) is not sent to the server when the browser retrieves the page. So, you cannot get it out of a normal GET or POST request on the server at all.
That data is available in the browser, so you could access it using javascript of even CSS.
Using ajax techniques, you could load a skeleton page and send the target string yourself to the server and have it react to it, and only then load the rest of the page. A bit overkill for most uses I'm afraid and there are drawbacks as well (e.g. search engine might have more trouble to see your content).
It's easier to send the string to the server as a GET parameter if you have the level of control you seem to have. [simply replace the # with a ?], that will be sent to the server by the browser.
Do note that you should URLencode any data you add on to a URL ...
I'm developing a flash binary that execute an animation in some web pages, and during this time I want to get the current source code of the page and send it via a POST call.
To get current source code I execute some javascript like this :
src = ExternalInterface.call("function(){return document.documentElement.outerHTML;}");
At this point, no problem.
After that, as the source code could be very huge, I wanted to compress it, so I tried to work with BiteArray like this :
var dataSrc:ByteArray = new ByteArray();
dataSrc.writeUTFBytes(src); // xmlData is original XML string
dataSrc.compress();
At this point, how could I send this to some server script (here I use PHP) ?
I mean : I don't want to know how to send data to an URL (I will use URL Loader), but how should I set my variable ?
Directly dataSrc or data.toString() ?
After compressing with ByteArray, I just Base64Encode my result, transmit it to my server script, and in this script I Base64Decode and gzuncompress.
Why should I Base64Encode ? Because to transmit the data to the server, my data is converted in a string and doing this cause bit lose, and padding errors ... Base64Encode permits to convert each bit of my data in a valid string to communicate.
There is a web service that allows me to go to a URL, with my API-key, and request a page of data. The data is returned as JSON. The JSON is well-formed, I ran it through JSONLint and confirmed its OK.
What I would like to do is retrieve the JSON data from within MS Access (2003 or 2007), if possible, and build a table from that data (first time thru), then append/update the table on subsequent calls to that URL. I would settle for "pre-step" where I retrieve this information via another means. Since I have an API key in the URL, I do not want to do this server-side. I would like to keep it all within Access, run it on my PC at home (its for personal use anyway).
If I have to use another step before the database load then Javascript? But I dont know that very well. I dont even really know what JSON is other than what I have read in Wikipedia. The URL looks similar to:
http://www.SomeWebService.com/MyAPIKey?p=1&s=50
where: p = page number
s = records per page
Access DB is a JavaScript Lib for MS Access, quick page search says they play nicely with JSON, and you can input/output with. boo-ya.
http://www.accessdb.org/
EDIT:
dead url; wayback machine ftw:
http://web.archive.org/web/20131007143335/http://www.accessdb.org/
also sourceforge
http://sourceforge.net/projects/accessdb/