在csv文件中运行nodeJS函数

时间:2019-03-06 18:18:27

标签: javascript node.js csv express axios

我有一个nodeJS应用,在其中设计了它可以根据企业名称运行三个API调用并返回结果。我想要做的是在我拥有的CSV文件中运行此应用程序。下面是我的代码。有关如何执行此操作的任何想法?以下是我的代码示例。我试图运行名称列,将其传递到我的函数中,然后在CSV文件中返回结果。

function fetchYelp() {
    let token = '<Token>';
    axios.get('https://api.yelp.com/v3/businesses/search?term=Grace Christian Fellowship&location=Mounds, il 62964',{
        headers: {
            Authorization: 'Bearer ' + token
        }
    })
        .then(res => {
            if(res.data.businesses.length < 1){
                fetchWhitePages();
            }else{
                console.log(res.data.businesses);
                console.log('running YelpAPI')
            }
        })
        .catch(err => {
            console.log(err)
        })
}
fetchYelp();


function fetchWhitePages() {
    axios.get('https://proapi.whitepages.com/3.0/business?api_key=<key>&address.city=Mounds&address.country_code=US&address.postal_code=62964&address.state_code=il&name=Grace Christian Fellowship')

        .then(res => {

            if(!res.data.business.length < 1){
                fetchGooglePlace()
            }else{
                console.log(res.data);
                console.log('running whitePagesAPi')
            }
        })
        .catch(err => {
            console.log(err)
        });
}

function fetchGooglePlace(){
    axios.get('https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Grace Christian Fellowship, mounds il 62964&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry,place_id&key=<APIKEY>')

        .then(res => {
            if(res.data.candidates.length < 1){
                console.log('Manual Search')
            }else{
                console.log(res.data.candidates[0].place_id);
                console.log('Passing Place ID to fetchGoogleTel')
                fetchGoogleTel()
            }

        })
        .catch(err => {
            console.log(err)
        });
}

function fetchGoogleTel () 

0 个答案:

没有答案