Example #1
0
  uri: 'https://risingstack.com',
  qs: {
    limit: 10,
    skip: 20,
    sort: 'asc'
  },
  headers: {
    'User-Agent': 'Request-Promise',
    'Authorization': 'Basic QWxhZGRpbjpPcGVuU2VzYW1l'
  }
}

const post_options = {  
  method: 'POST',
  uri: 'https://risingstack.com/login',
  body: {
    foo: 'bar'
  },
  json: true 
    // JSON stringifies the body automatically
}


request(get_options)  
  .then(function (response) {
    console.log("HTTP REQUEST: SUCCESS\n")
    // Request was successful, use the response object at will
  })
  .catch(function (err) {
    // Something bad happened, handle the error
  })
Example #2
0
File: app.js Project: wtam/StoreBot
var Swagger = require('swagger-client')
var open = require('open')
var rp = require('request-promise')

// config items
var pollInterval = 1000
var directLineSecret = 'OU0ZwJKIVPI.cwA.tQo.vtLhimllDrCyLs0VZayTAbaKgxhDeBSrxsaIJqPPGYU'
var directLineClientName = 'StoreCustomerServiceBotDirectLineClient'
var directLineSpecUrl = 'https://docs.botframework.com/en-us/restapi/directline3/swagger.json'

var directLineClient = rp(directLineSpecUrl)
    .then((spec) =>
        // client
        new Swagger(
            {
                spec: JSON.parse(spec.trim()),
                usePromise: true
            }))
    .then((client) => {
        // add authorization header to client
        client.clientAuthorizations.add('AuthorizationBotConnector', new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + directLineSecret, 'header'))
        return client
    })
    .catch((err) =>
        console.error('Error initializing DirectLine client', err))

// once the client is ready, create a new conversation 
directLineClient.then((client) => {
    client.Conversations.Conversations_StartConversation()                          // create conversation
        .then((response) => response.obj.conversationId)                            // obtain id
        .then((conversationId) => {
Example #3
0
  return new Promise((resolve, reject) => {

  let options = {
    url: `${cluster.localUrl || cluster.url}/stats.json`,
    method: 'GET',
    rejectUnauthorized: false,
    timeout: 5000
  };

  rp(options)
    .then((response) => {
      cluster.statsError = undefined;

      if (response.bsqErr) {
        cluster.statsError = response.bsqErr;
        console.error('Get stats error', response.bsqErr);
        return resolve();
      }

      let stats;
      try { stats = JSON.parse(response); }
      catch (e) {
        cluster.statsError = 'ES stats parse failure';
        console.error('Bad response for stats', cluster.localUrl || cluster.url);
        return resolve();
      }

      if (!stats || !stats.data) { return resolve(); }

      cluster.deltaBPS = 0;
      // sum delta bytes per second
      for (let stat of stats.data) {
        if (stat.deltaBytesPerSec) {
          cluster.deltaBPS += stat.deltaBytesPerSec;
        }
      }

      cluster.deltaTDPS = 0;
      // sum delta total dropped per second
      for (let stat of stats.data) {
        if (stat.deltaTotalDroppedPerSec) {
          cluster.deltaTDPS += stat.deltaTotalDroppedPerSec;
        }
      }

      // Look for issues
      for (let stat of stats.data) {
        if ((Date.now()/1000 - stat.currentTime) > 30) {
          setIssue(cluster, {
            type  : 'outOfDate',
            node  : stat.nodeName,
            value : Date.now() - stat.currentTime
          });
        }

        if (stat.deltaPacketsPerSec === 0) {
          setIssue(cluster, {
            type: 'noPackets',
            node: stat.nodeName,
          });
        }

        if (stat.deltaESDroppedPerSec > 0) {
          setIssue(cluster, {
            type  : 'esDropped',
            node  : stat.nodeName,
            value : stat.deltaESDroppedPerSec
          });
        }
      }

      return resolve();
    })
    .catch((error) => {
      let message = error.message || error;
      console.error('STATS ERROR:', options.url, message);

      setIssue(cluster, { type: 'esDown', value: message });

      cluster.statsError = message;
      return resolve();
    });
  });
Example #4
0
    };
}

function processFlightScoreColumn($col) {
    var text = $col.text().trim();
    if (!text)
        return;

    var match = text.match(/(\d+(?:[\.,]\d+))pt\. \((\d+\.\d+)\)/);
    if (!match)
        throw new Error('Could not parse flight score column: ' + text);

    var score = parseFloat(match[1].replace(',', '.'));
    var date = match[2];

    var link = $col.find('a').prop('href');

    return { score, date, link };
}

var options = {
    uri: 'http://www.onlinecontest.org/olc-2.0/gliding/dmsteinzel.html?st=dmst&cl=open&sp=2015&c=DE&sc=nw',
    transform: body => cheerio.load(body, { normalizeWhitespace: true })
};

module.exports = request(options)
    .then($ => processPilotRanking($))
    .then(x => console.log(x));

module.exports.processPilotRanking = processPilotRanking;
Example #5
0
var digReviewsInfoFromSquare = function (options) {
    console.log('begin!');
    var reg = /[0-9]{1,15}/g;
    var re = /[^《》]*/g;
    rp(options)
        .then(function (data) {
            // console.log(data.statusCode);
            // console.log(data);
            $ = cheerio.load(data);
            var reviews = [];
            $('div.media-body').each(function () {
                var reviewInfo = {};
                reviewInfo.rate = $(this).find('h5 > small > span').text();
                reviewInfo.commentid = $(this).find('div.ys-comments-btns').attr('data-cid').trim();
                reviewInfo.userid = $(this).find('h5.media-heading a').attr('href').match(reg).join('');
                reviewInfo.username = $(this).find('h5.media-heading a').text().trim();
                reviewInfo.usercomment = $(this).find('div.ys-comments-message p').text().trim();
                reviewInfo.bookname = $(this).find('div.ys-comments-message > small > a').text().match(re).join('').trim();
                reviewInfo.bookid = $(this).find('div.ys-comments-message > small > a').attr('href').match(reg).join('');
                reviews.push(reviewInfo);
                // console.log(reviewInfo.bookname);
                // console.log(reviewInfo.bookid);
            })
            maplimit = Promise.promisify(require('async').mapLimit);
            maplimit(reviews, 1, function (reviewInfo, callback) {
                review.count({commentid: mongoose.Types.ObjectId(reviewInfo.commentid)})
                    .then(function (data) {

                        if (data < 1) {//不存在则创建新的
                            review.create({
                                rate:reviewInfo.rate,
                                commentid:reviewInfo.commentid,
                                userid:reviewInfo.userid,
                                username:reviewInfo.username,
                                usercomment:reviewInfo.usercomment,
                                bookname:reviewInfo.bookname,
                                bookid:reviewInfo.bookid,
                            }).then(function (data) {
                                console.log(data);
                                callback(null,null);
                            })
                        }
                    })
            }).then(function () {
                if ($('body > div.sokk-body > div > div > div > a').attr('onclick') != undefined) {
                    var nexttime = $('body > div.sokk-body > div > div > div > a').attr('onclick').match(reg).join('');
                    console.log(nexttime);
                    var option = {
                        uri: 'http://www.yousuu.com/comments',
                        qs: {
                            t: nexttime // -> uri + '?access_token=xxxxx%20xxxxx'
                        },
                        // headers: {
                        //     'User-Agent': 'Request-Promise'
                        // },
                        json: true // Automatically parses the JSON string in the response
                    }
                    var deal = function () {
                        digReviewsInfoFromSquare(option);
                    }
                    setTimeout(deal, 10);
                }
            })
        })
}
Example #6
0
User.prototype.getWeather = function(date, location, activities, foundDay) {
  var user = this;

  var newWeatherParams = [];

  var urlFirst = 'http://api.wunderground.com/api';
  var urlAPIKey = '/921c08ecbdcbf50c';
  var urlDate = '/history_' + date;
  var urlLocation = '/q/' + location.lat + ',' + location.lng + '.json'

  var queryUrl = urlFirst + urlAPIKey + urlDate + urlLocation;

  var options = {
    uri: queryUrl,
    headers: {
      'User-Agent': 'Request-Promise'
    },
    json: true
  };

  return http(options)
    .then(function(weatherData) {

        var dailySum = weatherData.history.dailysummary[0];
        var dailyCond = weatherData.history.observations;

        if (dailySum.fog === '1') {
          newWeatherParams.push('fog');

        }
        if (dailySum.rain === '1') {
          newWeatherParams.push('rain')
        }
        if (dailySum.snow === '1') {
          newWeatherParams.push('snow')
        }
        if (dailySum.hail === '1') {
          newWeatherParams.push('hail')
        }
        if (dailySum.maxhumidity !== '' && parseInt(dailySum.maxhumidity) > 70) {
          newWeatherParams.push('humid')
        }
        if (parseInt(dailySum.meanwindspdi) > 15) {
          newWeatherParams.push('windy')
        }

        newWeatherParams.push('highs in the ' + dailySum.maxtempi.slice(0, -1) + '0s')

        newWeatherParams.push('lows in the ' + dailySum.mintempi.slice(0, -1) + '0s')

        //Grabs a weather condition halfway through the daily weather observations
        newWeatherParams.push("Conditions: " + dailyCond[Math.floor(dailyCond.length / 2)].conds);

        return newWeatherParams;
    })
    .then(function(newWeatherParams) {
      activities = activities.concat(newWeatherParams);
      activities.forEach(function(activity) {
        if (user.userActivities.indexOf(activity) === -1) {
          user.userActivities.push(activity);
        }
      });

      foundDay.activities = foundDay.activities.concat(activities);
      foundDay.gotWeather = true;
      return user.save();
    });
}
Example #7
0
router.get('/request/:q/:city', requireSession, function(req, res) {

  var usaJobs = request('https://data.usajobs.gov/api/jobs?keyword=' + req.params.q + '&locationID=' + req.params.city)
    .then(parsingToJSON)
    .then(usaJobsTransformation);
  var github = request('https://jobs.github.com/positions.json?description=' + req.params.q + '&location=' + req.params.city)
    .then(parsingToJSON)
    .then(githubTransformation);
  var dice = request('http://service.dice.com/api/rest/jobsearch/v1/simple.json?text=' + req.params.q + '&city=' + req.params.city)
    .then(parsingToJSON)
    .then(diceTransformation);

  function parsingToJSON(nonParsedData) {
    return JSON.parse(nonParsedData)
  }

  function usaJobsTransformation(usaJobsData) {
    if (usaJobsData.JobData) {
      return usaJobsData.JobData.map(function(item) {
        var posting = {
          title : item.JobTitle,
          company : item.OrganizationName,
          postDate : new Date(item.StartDate).getTime() / 1000,
          linkToSource : item.ApplyOnlineURL,
          location : 'USA'
        };
        return posting;
      })
    } else {
      return [];
    }
  }

  function githubTransformation(githubData) {
    if (githubData) {
      return githubData.map(function(item) {
        var posting = {
          title : item.title,
          company : item.company,
          postDate : new Date(item.created_at).getTime() / 1000,
          linkToSource : item.url,
          location : item.location
        };
        return posting;
      })
    } else {
      return [];
    }
  }

  function diceTransformation(diceData) {
    if (diceData.resultItemList) {
      return diceData.resultItemList.map(function(item) {
        var posting = {
          title : item.jobTitle,
          company : item.company,
          postDate : new Date(item.date).getTime() / 1000,
          linkToSource : item.detailUrl,
          location : item.location
        };
        return posting;
      })
    } else {
      return [];
    }
  }

  Promise.all([usaJobs, github, dice]).then(function(results) {
    var newResult = [];

    for (var i = 0; i < results.length; i++) {
      newResult = newResult.concat(results[i]);
    }
    return newResult;

  }).then(function(newResult) {
    var newResult = newResult.sort(function(a, b) {
      return b.postDate - a.postDate;
    });
    return newResult;

  }).then(function(newResult) {
    res.send(newResult);
  });

});
 .then(venue => {
   if (venue) {
     res.status(200).json(venue);
   } else {
     httpRequest({
       uri: `${foursquare.uri}${venueId}`,
       qs: foursquare.query,
       json: true
     })
     .then((fsq) => {
       var venue = fsq.response.venue
       createVenue({
         venueId: venueId || '',
         name: venue.name || '',
         photoSuffix: venue.bestPhoto ?
           venue.bestPhoto.suffix || '' : '',
         address: venue.location.address || '',
         city: venue.location.city || '',
         state: venue.location.state || '',
         zipcode: venue.location.postalCode || '',
         lat: venue.location.lat || 0,
         lng: venue.location.lng || 0,
         phone: venue.contact ? '' :
           venue.contact.formattedPhone || '',
         rating: venue.rating || '',
         price: !venue.price ? '' :
           venue.price.tier,
         tier: !venue.price ? '' :
           venue.price.message,
         tips: venue.stats.tipCount,
         visitors: venue.stats.visitsCount,
         checkins: venue.stats.checkinsCount,
         hasMenu: venue.hasMenu || '',
         menu: !venue.hasMenu ? '' :
           venue.menu.externalUrl || venue.menu.mobileUrl || '',
         url: venue.url || venue.canonicalUrl || '',
         twitter: venue.contact ? '' :
           venue.contact.twitter || '',
         facebook: venue.contact ? '' :
           venue.contact.facebook || '',
         category: venue.categories[0].shortName || '',
         hours: !venue.hours ? [] :
           venue.hours.timeframes.map(time => {
             return {days: time.days, open: time.open}
           }),
         createdAt: new Date(),
         updatedAt: new Date()
       })
       .then((newVenue) => {
         res.status(201).json(newVenue);
       })
       .fail((err) => {
         console.error(`Could not create new venue: ${err}`);
         throw new Error(`Could not create new venue: ${err}`);
       });
     })
     .catch((err) => {
       console.error(`Failed to get venue data from Foursquare: ${err}`);
       throw new Error(`Failed to get venue data from Foursquare: ${err}`);
     });
   }
 })
Example #9
0
function getFlagDetailsPage(href) {
	var url = URL.resolve(baseUrl, href);
	return request(url).then(cheerio.load)
}
Example #10
0
 .then(rslug => rp(`https://classes.cornell.edu/api/2.0/config/subjects.json?roster=${rslug}`))
Example #11
0
 .then(urls => urls.map(url => rp(url).catch(e => null)))
Example #12
0
 it('/current should exist and be 1', function() {
   return expectJSON(rp('http://127.0.0.1:7786/blockchain/current', { json: true }), {
     number: 6
   });
 });
Example #13
0
 it('/block/0 should exist', function() {
   return expectJSON(rp('http://127.0.0.1:7786/blockchain/block/0', { json: true }), {
     number: 0
   });
 });
const fs = require('fs');
const request = require('request-promise');
const API_URL = 'https://api.meetup.com/2/';
const MEETUP_API_KEY = fs.readFileSync(__dirname + '/data/KEY').toString().trim();

var past = request({
  uri: API_URL + "events/",
  method: "GET",
  qs: {
    "group_urlname": "bostondatavis",
    "key": MEETUP_API_KEY,
    "status": "past"
  }
});

var upcoming = request({
  uri: API_URL + "events/",
  method: "GET",
  qs: {
    "group_urlname": "bostondatavis",
    "key": MEETUP_API_KEY,
    "status": "upcoming"
  }
});


past.then(function(resp) {
  console.log("past", resp);
}).catch(console.error);

Example #15
0
 it('should have identity-of/aaa', function() {
   return httpTest.expectError(404, "No member matching this pubkey or uid", rp('http://127.0.0.1:7799/wot/identity-of/aaa'));
 });
Example #16
0
function requestFlagsPage(startIndex) {
	var path = util.format(flagPageTemplatePath, startIndex);
	var url = URL.resolve(baseUrl, path);
	return request(url).then(cheerio.load);
}
Example #17
0
var _ = require('lodash');
var request = require('request-promise');

request("http://jsonplaceholder.typicode.com/posts")
    .then(function(response){
        var posts  = JSON.parse(response);

       var importantPosts =  _.filter(posts, function(post){
            return _.startsWith(post.title, "dolor");
        });

        console.log(importantPosts);


    });
 function checkHost() {
   console.log('Checking URL url=%s', serverURL);
   return rp(serverURL);
 }
 /**
  * Asks the Pandorabots for a reply
  * @param clientName Name of the user (usually a unique id of the user)
  * @param input Text that the user entered
  * @param sessionId Session id of the conversation (pass undefined if unknown)
  * @return {Promise<{status:string, responses: Array<string>, sessionid: number}>}
  */
 reply(/*string*/ clientName, /*string*/ input, /*number=*/ sessionId) {
   const options = this._options(clientName, input, sessionId);
   return Promise.resolve(request(options));
 }
Example #20
0
    onboard(authInfo) {
        // Ensure getUserInput and getDeveloperInput answers are present
        if (!authInfo || authInfo.length < 2) {
            throw new OpenT2TError(401, OpenT2TConstants.InvalidAuthInput);
        }

        this.logger.verbose("Onboarding Wink Hub");

        // Parse authInfo[1] to get the query parameters, Wink wants 'code'
        var code = url.parse(authInfo[1], true).query['code'];
		
        // this comes from the onboardFlow property 
        // as part of the schema and manifest.xml
        var params = {
            client_id: authInfo[0].client_id,
            client_secret: authInfo[0].client_secret,
            redirect_uri: authInfo[0].redirect_url,
            code: code,
            grant_type: 'authorization_code'
        }

        // build request URI
        var requestUri = this.authUrl + '/token?' + querystring.stringify(params);
        var method = "POST";

        // Set the headers
        var headers = {
            'Accept': 'application/json',
            'cache-control': 'no-cache'
        }

        var options = {
            url: requestUri,
            method: method,
            headers: headers,
            followAllRedirects: true
        };

        return request(options)
            .then(function (body) {
                var tokenInfo = JSON.parse(body); // This includes refresh token, scope etc..
                
                // Wink doesn't return an expiration, so set it to 24 hours
                var expiration = Math.floor(new Date().getTime() / 1000) + 86400;
                // default to one year in seconds
                var refreshExpiration = Math.floor(new Date().getTime() / 1000) + 31557600;

                var authTokens = {};
                authTokens['access'] = {
                    token: tokenInfo.access_token,
                    expiration: expiration,
                    type: tokenInfo.token_type,
                    scopes: tokenInfo.scopes
                }

                authTokens['refresh'] = {
                    token: tokenInfo.refresh_token,
                    expiration: refreshExpiration,
                    type: tokenInfo.token_type,
                    scopes: tokenInfo.scopes
                };
                
                return authTokens;
            });
    }
Example #21
0
Connection.prototype._request = function (options) {
    return rp(options);
}
function pinboard(args) {
  var config = this.config.pinboard;
  if (!config) {
    console.log('Cannot find pinboard settings in _config.yml')
    return
  }
  var token = config.token || process.env.PINBOARD_TOKEN
  var options = {
    uri: 'https://api.pinboard.in/v1/posts/all',
    qs: {
      auth_token: token,
      tag: config.tag,
      format: 'json'
    },
    json: true
  }
  var filePrefix = config.prefix || 'around-the-web'
  var titlePrefix = config.prefix || 'Around the Web'
  var categories = config.categories || ['around the web']
  var layout = config.layout || 'post'

  var processTags = R.pipe(R.split(' '), R.without(config.tag))

  var extract = (files, post) => {
    var date = moment(post.time)
    var filename = `${filePrefix}-${date.format('YYYY')}-${date.week()}.md`
    if (!files[filename]) {
      files[filename] = {
        filename,
        layout,
        date,
        tags: processTags(post.tags),
        content: []
      }
    }
    if (date > files[filename].date) files[filename].date = date
    var content = files[filename].content
    content.push(`## [${post.description}](${post.href})`)
    content.push(post.extended)
    content.push('')
    return files
  }

  var format = files => {
    return R.values(files).map(file => {
      var lines = [
        `layout: ${file.layout}`,
        `title: ${titlePrefix} for ${file.date.format('MMMM D, YYYY')}`,
        `date: ${file.date.format('YYYY-MM-DD')}`,
        `categories:`
      ]
      lines = lines.concat(categories.map(c => `- ${c}`))
      lines.push('tags:')
      lines = lines.concat(file.tags.map(t => `- ${t}`))
      lines.push('---\n')
      lines = lines.concat(file.content)
      return {
        filename: file.filename,
        content: lines.join('\n')
      }
    })
  }

  var fn = R.pipe(R.reduce(extract, {}), format)
  rp(options)
    .then(posts => {
      var files = fn(posts)
      files.map(file => {
        fs.writeFile(`source/_posts/${file.filename}`,
                     file.content, err => {
                       console.log(`${file.filename} generated.`)
                     })
      })
    }).catch(console.log)
}
Example #23
0
function update() {
  rp({
    url: DEV_COMMITS_PAGE,
    headers: {
      'User-Agent': 'ericchu94/luma3ds',
      'Accept': 'application/vnd.github.v3+json',
    },
  }).then(data => {
    const commits = JSON.parse(data);
    const commit = commits[0].sha.substring(0, 7);
    return {
      src: commit,
      commit: commit,
    };
  }).then(info => {
    if (last_latest_src == info.src)
      logger.info(`${LATEST_DEV} is up to date`);
    else {
      return rp(LATEST_DEV_PAGE).then(data => {
        const $ = cheerio.load(data);
        const $build = $('tr td a').filter((i, el) => {
          return $(el).text().includes(info.commit);
        });

        if ($build.length == 0)
          throw new Error(`Build ${info.commit} not found`);

        return `${LATEST_HOST}${$build.attr('href')}`;
      }).then(src => {
        return new Promise((resolve, reject) => {
          const dest = 'tmp_latest_dev'
          const r = request(src);
          r.on('error', reject);
          r.on('response', res => {
            if (res.statusCode != 200)
              return reject(new Error(res.statusMessage));
            const writeStream = unzip.Extract({ path: dest });
            writeStream.on('close', () => {
              resolve(dest);
            });
            r.pipe(writeStream);
          });
        });
      }).then(output => {
        const folder = path.join(output, 'out');
        const file = path.join(folder, 'arm9loaderhax.bin');
        return fs.rename(file, LATEST_DEV).then(() => {
          return output;
        });
      }).then((folder) => {
        return fs.remove(folder);
      }).then(() => {
        last_latest_dev_src = info.src;
        logger.info(`Updated ${LATEST_DEV}`);
      });
    }
  }).catch(err => {
    logger.warn(`Failed to update ${LATEST}: ${err}`);
  });

  rp({
    url: COMMITS_PAGE,
    headers: {
      'User-Agent': 'ericchu94/luma3ds',
      'Accept': 'application/vnd.github.v3+json',
    },
  }).then(data => {
    const commits = JSON.parse(data);
    const commit = commits[0].sha.substring(0, 7);
    return {
      src: commit,
      commit: commit,
    };
  }).then(info => {
    if (last_latest_src == info.src)
      logger.info(`${LATEST} is up to date`);
    else {
      return rp(LATEST_PAGE).then(data => {
        const $ = cheerio.load(data);
        const $build = $('tr td a').filter((i, el) => {
          return $(el).text().includes(info.commit);
        });

        if ($build.length == 0)
          throw new Error(`Build ${info.commit} not found`);

        return `${LATEST_HOST}${$build.attr('href')}`;
      }).then(src => {
        return new Promise((resolve, reject) => {
          const dest = 'tmp_latest'
          const r = request(src);
          r.on('error', reject);
          r.on('response', res => {
            if (res.statusCode != 200)
              return reject(new Error(res.statusMessage));
            const writeStream = unzip.Extract({ path: dest });
            writeStream.on('close', () => {
              resolve(dest);
            });
            r.pipe(writeStream);
          });
        });
      }).then(output => {
        const folder = path.join(output, 'out');
        const file = path.join(folder, 'arm9loaderhax.bin');
        return fs.rename(file, LATEST).then(() => {
          return output;
        });
      }).then((folder) => {
        return fs.remove(folder);
      }).then(() => {
        last_latest_src = info.src;
        logger.info(`Updated ${LATEST}`);
      });
    }
  }).catch(err => {
    logger.warn(`Failed to update ${LATEST}: ${err}`);
  });

  rp({
    url: RELEASE_PAGE,
    headers: {
      'User-Agent': 'ericchu94/luma3ds',
      'Accept': 'application/vnd.github.v3+json',
    },
  }).then(data => {
    const release = JSON.parse(data);
    const tagName = release.tag_name;
    const name = release.name;
    return rp({
      url: TAGS_PAGE,
      headers: {
        'User-Agent': 'ericchu94/luma3ds',
        'Accept': 'application/vnd.github.v3+json',
      },
    }).then(data => {
      const tags = JSON.parse(data);
      for (let tag of tags) {
        if (tag.name == tagName) {
          const commit = tag.commit.sha.substring(0, 7);
          return {
            src: `${name} - ${commit}`,
            commit: commit,
          }
        }
      }
      throw new Error('Failed to get sha of release');
    });
  }).then(info => {
    if (last_release_src == info.src)
      logger.info(`${RELEASE} is up to date`);
    else {
      return rp(LATEST_PAGE).then(data => {
        const $ = cheerio.load(data);
        const $build = $('tr td a').filter((i, el) => {
          return $(el).text().includes(info.commit);
        });

        if ($build.length == 0)
          throw new Error(`Build ${info.commit} not found`);

        return `${LATEST_HOST}${$build.attr('href')}`;
      }).then(src => {
        return new Promise((resolve, reject) => {
          const dest = 'tmp_release'
          const r = request(src);
          r.on('error', reject);
          r.on('response', res => {
            if (res.statusCode != 200)
              return reject(new Error(res.statusMessage));
            const writeStream = unzip.Extract({ path: dest });
            writeStream.on('close', () => {
              resolve(dest);
            });
            r.pipe(writeStream);
          });
        });
      }).then(output => {
        const folder = path.join(output, 'out');
        const file = path.join(folder, 'arm9loaderhax.bin');
        return fs.rename(file, RELEASE).then(() => {
          return output;
        });
      }).then((folder) => {
        return fs.remove(folder);
      }).then(() => {
        last_release_src = info.src;
        logger.info(`Updated ${RELEASE}`);
      });
    }
  }).catch(err => {
    logger.warn(`Failed to update ${RELEASE}: ${err}`);
  });
}
 find: function find(id) {
   return request({
     uri: config.endpoint + '/' + type + '/' + id,
     json: true
   });
 },
 let makeRequest = (api, qs = {}) => request({
   url: url + api,
   method: 'GET',
   qs: Object.assign({}, wallet, qs),
   json: true
 })
Example #26
0
const rp = require("request-promise"), //进入request-promise模块
  fs = require("fs"), //进入fs模块
  cheerio = require("cheerio"), //进入cheerio模块
  depositPath = "I:/test/"; //存放照片的地址
let downloadPath; //下载图片的文件夹地址
module.exports = {
  async getPage(url) {
    const data = {
      url,
      res: await rp({
        url: url
      })
    };
    return data;
  },
  getUrl(data) {
    let list = [];
    const $ = cheerio.load(data.res); //将html转换为可操作的节点
    $("#pins li a")
      .children()
      .each(async (i, e) => {
        let obj = {
          name: e.attribs.alt, //图片网页的名字,后面作为文件夹名字
          url: e.parent.attribs.href //图片网页的url
        };
        list.push(obj); //输出目录页查询出来的所有链接地址
      });
    return list;
  },
  getTitle(obj) {
    downloadPath = depositPath + obj.name;
Example #27
0
 it('/block/8 should exist on S1', function() {
   return expectJSON(rp('http://127.0.0.1:7788/blockchain/block/8', { json: true }), {
     number: 8
   });
 });
Example #28
0
 it('should have 4 members', function() {
   return expectAnswer(rp('http://127.0.0.1:7799/wot/members', { json: true }), function(res) {
     res.should.have.property('results').length(4);
     _.pluck(res.results, 'uid').sort().should.deepEqual(['cat', 'tac', 'tic', 'toc']);
   });
 });
Example #29
0
module.exports.getComment = () => rp(options)
 .flatMap(function (x) {
   return K.fromPromise(request(x));
 })