versioning parameter not working properly - foursquare

when using url : https://api.foursquare.com/v2/users/self?v=20120321 i get photo url "photo": "https://is1.4sqi.net/userpix_thumbs/-NH21T0X1FCTGSY1W.png", which is correct and image is shown when browsed in browser
but when i use https://api.foursquare.com/v2/users/self?v=20131114 i get below response for photo:
"photo": {
"prefix": "https://irs2.4sqi.net/img/user/",
"suffix": "/-NH21T0X1FCTGSY1W.png"
},
which when attached becomes url https://irs2.4sqi.net/img/user/-NH21T0X1FCTGSY1W.png
and says "Internal Error" when browsed in browser.
The above check was performed via https://apigee.com/console/foursquare

You have to construct a full photo URL, as we detail in our docs: https://developer.foursquare.com/docs/responses/photo
You need to insert a size between prefix and suffix. For example, https://irs2.4sqi.net/img/user/300x300/-NH21T0X1FCTGSY1W.png is a working image.

Related

how to replace space in image url in nodejs

I am fetching data from an api and it contains image urls. When i try to display the images it is not showing any picture. when i logged using console.log(service.coverImage), i was able to display the image urls. for example
https://s3.eu-west-2.amazonaws.com/ererf3wery/Hillside Plaza Hotel 5cdebeaf34157a0026526f0d/providerImage/hph.jpeg
You notice the link breaks and it doesn't go to the image directly, now i cannot change this in the database. How can i solve this in Nodejs to replace the places so that it becomes complete.
I have used methods like replace and encodeURIComponent but not helping
thank you in advance
The image url looks fine, if you are not able to see the image in web page, try to remove protocol from it.
url = url.replace("https:", "");
If that doesn't work, then try removing spaces as you wanted:
let url = "https://s3.eu-west-2.amazonaws.com/ererf3wery/Hillside Plaza Hotel-5cdebeaf34157a0026526f0d/providerImage/hph.jpeg";
url = url.replace(/\ /g, "%20");
console.log(url)

SailsJS / Vue / Node: variable undefined when sending to an EJS page

This is a bit of a strange one and I think it's a basic syntax error, but I cannot seem to pin it down.
I have successfully got my controller in Sails (NodeJS) sending some JSON through to the view (an EJS file). It's an object called "Profile" (pulled from a DB, which I have connected & working).
The JSON my page is receiving looks like this:
[{
"personal_photo_url": "bing.jpg",
"show_profile": false,
"id": 1
}]
The relevant code snippet on my .ejs file (view) looks like this:
<h3>Personal photo: {{profile.personal_photo_url}}</h3>
<h3>Show profile to others?: {{ profile.show_profile }}</h3>
<h3>User ID:{{ profile }}</h3>
When the page loads, I'm not seeing any text against "welcome sound" or the "show profile to others?" line, however when I just show "profile" without referencing the fields in the "User ID" line, I receive the following HTML displayed on the page:
Personal photo:
Show profile to others?:
User ID: [ { "personal_photo_url": "bing.jpg", "show_profile": false, "id": 1 } ]
It's worth pointing out that when I do some querying all the fields are listed as "undefined", even though they are showing per above.
So my question is pretty simple - how do I get the values from these fields showing without all the JSON formatting?
Ok, after a bit more trial and error I realised what had happened is that I was sending in an array to the page.
When I adjusted my search result from the database to use the .findOne() method instead of .find() the data was presented as I needed it (ie just one record), and my code above worked perfectly.

Crawling data but the url doesn't change

I want to crawl data using python from this webpage:
https://www.discountoptiondata.com/freedata/
by keep same value for expiration date and symbol but iterating over all values of the start date.
The problem is that the URL stays same for all combinations and hence I cannot get a list of the URLs I want to crawl.
anybody has ideas about how I can do that?
The website you are trying to parse is dynamic, which means it runs some code when you download it in your browser. In your case, the code is set to fetch the data when the "Get OptionData" button is clicked.
You can actually see the browser fetch the data in the Network tab of your browsers Developer Tools. F12 → Network → (Refresh the page) → Fill out the form and Click "Get OptionData". It will show up as a XHR request in the Network Tab list.
The response of the data fetch will look a bit like this
{
"AskPrice": "5.7",
"AskSize": "",
"BidPrice": "0.85",
"ExpirationDate": "2019-06-21",
"LastPrice": "4.4",
"StrikePrice": "1000",
"Symbol": "SPX"
}
The data returned from the data fetch is encoded as JSON, and lucky for us, its very easy to parse in Python. You can get the above JSON code by investigating the XHR request in the Network tab, this was the URL for me
https://www.discountoptiondata.com/freedata/getoptiondatajson?symbol=spx&datadate=2018-06-01&expirationDate=2018-06-15
I am unfamiliar with scrapy, but for JSON based parsing, I would recommend the 'requests' module. Here is an example program that will fetch the data shown on the webpage
import requests
ROOT_URL = "https://www.discountoptiondata.com/freedata/getoptiondatajson"
def fetch_option_data(symbol, datadate, expiration_date):
response = requests.get(ROOT_URL, params={"symbol": symbol, "datadate": datadate, "expirationDate": expiration_date})
return response.json()
data = fetch_option_data('spx', '2018-06-01', '2018-06-15')
for item in data:
print("AskPrice:", item['AskPrice'], "Last Price:", item["LastPrice"])
To view the request or response HTTP headers in Google Chrome, take the following steps :
In Chrome, visit a URL, right click, select Inspect to open the developer tools.
Select Network tab.
Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.
Source
In your case,
Open https://www.discountoptiondata.com/freedata/ in Google Chrome
Right click, select Inspect and select Network Tab
Now if you Select start date, you will find the request url under "Headers" Tab.
Same way you can view the response under "Response" Tab.
Here are the screenshots:
start_date_request_url
option_data_request_url
Example:
Start Date Request URL:
https://www.discountoptiondata.com/freedata/getexpirationdates?symbol=spx&datadate=2018-06-01
Option Data Request URL:
https://www.discountoptiondata.com/freedata/getoptiondatajson?symbol=spx&datadate=2018-06-01&expirationDate=2018-06-15

How to download a file via a Chrome Content Script?

This SO answer details how to download a file via a Chrome Extension, but I am using a Content Script, which has limited access to Chrome's APIs. In other words, I don't have access to the chrome.downloads object. I also tried this vanilla JS solution, but it did not work for me. Does anyone have a solution for Content Scripts or know why the second solution doesn't work?
Write a background page or event page and do it from there using the example in your linked answer. Communicate from/to the content script with chrome messages.
If you mean causing a file to be downloaded to the user's computer, this code will work in a Chrome extension content script or in the JS script an a regular webpage:
Firstly, you can cause a file to download without any JS at all by simply adding the "download" attribute to an anchor tag. With this tag, instead of navigating to the URL in the "href" attribute, the URL will be downloaded.
<a href="http://website.com/example_1.txt" download="saved_as_filename.txt" id="downloader">
static download link</a>
To update the URL dynamically:
var theURL = 'http://foo.com/example_2.txt';
$('#downloader').click(function() {
$(this).attr('href',theURL);
});
If you want the download to be initiated by something other than clicking on a link, you can simulate a click on the link. Note that .trigger() won't work for this purpose. Instead you can use document.createEvent:
$('#downloader').css('display','none');
function initiateDownload(someURL) {
theURL = someURL;
var event = document.createEvent("MouseEvent");
event.initMouseEvent("click", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
// dispatch event won't work on a jQuery object, so use getElementById
var el = document.getElementById('downloader');
el.dispatchEvent(event);
}
initiateDownload('example_3.txt');

I'm looking for a Sharepoint Webpart that can query a list for an RSS feed URL, then display it

Basically what I have a List that will be maintained by the user that has a field that contains a link to an RSS feed.
I tried using the OOTB RSS and it's great, but you have to specify the feed URL and I need that to be based on user selection. For example, the user will select from a list a feed they want to view and this should take them to the feed reader page which will use their selection to get the feed URL and display this on the page.
An alternative which is not a general Sharepoint solution is to use jquery.
Is the list visible on the page or is it "just" a list in Sharepoint?
Of course you might need some kind of proxy to do this in order to call the rss-feeds if they are placed on another server. But you will send the performance to the client instead of the server which is a plus..
My solution was to use the WebPartPages Web Service (SaveWebPart) to change the definition of the web part to use the new feed URL whenever a feed is clicked on.
I created a javascript function the will accept the feed URL and proceed to the page where the feed is displayed. The new feed will not be loaded until the next time you visit the page, therefore if you are already on it you will need to reload, thus the redirect.
For more information on the format of the request and the web part XML format see the following page.
http://msdn.microsoft.com/en-us/library/ms774839%28v=office.12%29.aspx
function SetFeed(feedURL){
var webPartGUID = $("#<WebPartID>").attr('webpartid');
// This is where you set the page URL, Full Web Part XML (including path to FEED),
// storageKey (webPart GUID), and storage type (none, personal, shared)
var soapEnv = "<FULL SOAP XML>";
jQuery.ajax({
url: "http://<SITE PATH>/_vti_bin/WebPartPages.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://microsoft.com/sharepoint/webpartpages/SaveWebPart")
},
complete: function(xData, status){
window.location='REDIRECT TO FEED PAGE';
},
contentType: "text/xml;charset='utf-8'"
});
}

Resources