<commit_before>import uuid from 'node-uuid';
import moment from 'moment';
import {Actions} from 'flummox';
import request from 'superagent';
import constants from '../../config/constants';

class FlightActions extends Actions {

  setAirport(airport) {
    return airport;
  }

  setDates(dates) {
    var {startDate, endDate} = dates;
    return {startDate, endDate};
  }

  clearAirports() {
    return 'clear';
  }

  setUUID(id) {
    return id;
  }

  airportList(airports, hash) {
    return {airports, hash};
  }

  async searchAirport(searchString) {
    let hash = uuid.v4();
    this.setUUID(hash);
    request.get(`${constants.api}/search_airport/${searchString}`)
      .end(res => {
        this.airportList(res.body, hash);
      });
  }

  async fetchAirport(airport) {
    request.get(`${constants.googleMapsAPI}/json?address=${airport.airportCode} ${airport.name} ${airport.country} airport&sensor=false`)
      .end(res => {
        let airportWithLocations = _.clone(airport);
        airportWithLocations.location = res.body.results[0].geometry.location;
        this.setAirport(airportWithLocations);
      });
  }

  createJourney() {
    return uuid.v4();
  }

  connectIo() {
    return 'connect-io';
  }

  getFlickrImage(date, lat, long) {
    request.get(`https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=f07305911011fb8f88eb92e9d2ab1749&privacy_filter=1&accuracy=4&safe_search=1&content_type=1&media=photos&lat=${lat}&lon=${long}&is_getty=true&sort=interestingness-desc&format=json&nojsoncallback=1`)
      .end(res => {
        if (res.ok) {
          let photo = res.body.photos.photo[0];
          this.setImage(date, `https://farm${photo.farm}.staticflickr.com/${photo.server}/${photo.id}_${photo.secret}_z.jpg`);
        } else {
          alert('Oh no! error ' + res.text);
      }
    });
  }

  setImage(date, url) {
    return {date, url};
  }
}

export default FlightActions;<commit_msg>Flickr API fallback to not getty image query if no getty is found<commit_after>import uuid from 'node-uuid';
import moment from 'moment';
import {Actions} from 'flummox';
import request from 'superagent';
import constants from '../../config/constants';

class FlightActions extends Actions {

  setAirport(airport) {
    return airport;
  }

  setDates(dates) {
    var {startDate, endDate} = dates;
    return {startDate, endDate};
  }

  clearAirports() {
    return 'clear';
  }

  setUUID(id) {
    return id;
  }

  airportList(airports, hash) {
    return {airports, hash};
  }

  async searchAirport(searchString) {
    let hash = uuid.v4();
    this.setUUID(hash);
    request.get(`${constants.api}/search_airport/${searchString}`)
      .end(res => {
        this.airportList(res.body, hash);
      });
  }

  async fetchAirport(airport) {
    request.get(`${constants.googleMapsAPI}/json?address=${airport.airportCode} ${airport.name} ${airport.country} airport&sensor=false`)
      .end(res => {
        let airportWithLocations = _.clone(airport);
        airportWithLocations.location = res.body.results[0].geometry.location;
        this.setAirport(airportWithLocations);
      });
  }

  createJourney() {
    return uuid.v4();
  }

  connectIo() {
    return 'connect-io';
  }

  getFlickrImage(date, lat, long, fallback) {
    let query = `https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=f07305911011fb8f88eb92e9d2ab1749&privacy_filter=1&accuracy=4&safe_search=1&content_type=1&media=photos&lat=${lat}&lon=${long}&sort=interestingness-desc&format=json&nojsoncallback=1`;
    if(!fallback) query += `&is_getty=true`;
    request.get(query)
      .end(res => {
        if (res.ok) {
          let photo = res.body.photos.photo[0];
          if(photo) {
            this.setImage(date, `https://farm${photo.farm}.staticflickr.com/${photo.server}/${photo.id}_${photo.secret}_c.jpg`);
          }
          else {
            getFlickrImage(date, lat, long, true);
          }
        } else {
          console.log('Flickr API Error: ' + res.text);
      }
    });
  }

  setImage(date, url) {
    return {date, url};
  }
}

export default FlightActions;
{'fraction_non_alphanumeric': 0.15399468983828143, 'fraction_numerical': 0.014965001206854936, 'mean_word_length': 3.2854188210961737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4316704', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1418, 'n_words': 224}