def main(): ###### set this to a file you don't upload to github before you upload (.gitignore) creds = pickle.load(open("api_config.p", "rb")) api_key = creds['api_key'] api_secret = creds['api_secret'] zip_code = sys.argv[1] #change to input # Instantiate the client with your credentials. api = petfinder.PetFinderClient(api_key=api_key, api_secret=api_secret) image_detect = 0 #how many cats actually have detectable faces cat = 0 for pet in api.pet_find(animal="cat", location=zip_code, output="full"): cat += 1 try: line = pet['photos'][0]['url'] #detect picture URL except IndexError: line = 'null' sub_image_detect = 0 if line != 'null': #if no picture, skip record sub_image_detect = run_algo(pet) if sub_image_detect > 0: write_DescTable(pet) write_nameTable(pet, sub_image_detect) write_contactInfo(pet) image_detect += 1 if image_detect % 10 == 0: print 'images detected: ' + str(image_detect) print 'cats looped: ' + str(cat) if image_detect == 500: quit()
def setUp(self): """ This is executed for every unit test. """ self.api = petfinder.PetFinderClient( api_key=API_DETAILS['API_KEY'], api_secret=API_DETAILS['API_SECRET'])
def post(self): try: # Parse the arguments parser = reqparse.RequestParser() parser.add_argument('url', type=str) # parser.add_argument('breed', type=str) parser.add_argument('location', type=str) args = parser.parse_args() url= args['url'] location = args['location'] #breed = args['breed'] breed = 'Beagle' # Download the image from the url urllib.urlretrieve(url,"image.png") # Search Wikipedia for info search = wikipedia.summary(breed, sentences =5) # Instantiate the client with your credentials. api = petfinder.PetFinderClient(api_key='90999df88cd81af6e271a7a661ee5bf6', api_secret='57d9d3da742d84021f892c623667db77') # search for pets pet = api.pet_getrandom(animal="dog", location=location,breed=breed, output = "basic") # Package Info in dict/json object data = {} data['breed'] = breed data['name'] = pet['name'] data['shelterId'] = pet['shelterId'] data['sex'] = pet['sex'] data['age'] = pet['age'] data['size'] = pet['size'] data['breed_info'] = search data['shelter Contact'] = pet['contact'] data['photos'] = pet['photos'] return data except Exception as e: return {'error': str(e)}
import petfinder #petfinder API from sqlalchemy import exc # this handles Integrity Errors import json import newrelic.agent #add password hash using sha256_crypt from passlib.hash import sha256_crypt # Google Maps api key maps_api_key = os.environ["GOOGLEMAPS_API_KEY"] # Petfinder API credentials api_key = os.environ["PETFINDER_API_KEY"] api_secret = os.environ["PETFINDER_API_SECRET"] # Instantiate petfinder api with my credentials api = petfinder.PetFinderClient(api_key=api_key, api_secret=api_secret) app = Flask(__name__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Required to use Flask sessions and the debug toolbar app.secret_key = "LGkjsdFlfkjaBldsmDasVfd36p9!9u0m43qlnXalrCd1f43aB" # Normally, if you use an undefined variable in Jinja2, it fails silently. # This is horrible. Fix this so that, instead, it raises an error. app.jinja_env.undefined = StrictUndefined @app.route("/") def index():
def post(self): try: # Instantiate the client with your credentials. api = petfinder.PetFinderClient( api_key='90999df88cd81af6e271a7a661ee5bf6', api_secret='57d9d3da742d84021f892c623667db77') data = {} # Parse the arguments parser = reqparse.RequestParser() parser.add_argument('url', type=str) #parser.add_argument('breed', type=str) parser.add_argument('location', type=str) #get args in memory args = parser.parse_args() url = args['url'] location = args['location'] #query model, if no result return model error result, prob = mManager().queryModel(url) if result == 'Model cannot identify the breed': data['model_error'] = 'Model cannot identify the breed' return data #format the way wiki wants if '_' in result: breed = result.replace("_", " ").title() else: breed = result.title() # Search Wikipedia for info, if no result return wiki error try: search = wikipedia.summary(breed, sentences=5) except Exception: data['breed'] = breed data['prob'] = prob data['wikipedia_error'] = 'cannot find info about ' + breed return data # search for pets try: found = 0 for pet in api.pet_find( animal="dog", location=location, output="basic", breed=breed, count=4, ): if found != 1: contact = pet['contact'] for key, val in contact.items(): if key == 'address1': if val != None: found = 1 break if found == 1: break if not pet is None: data['name'] = pet['name'] data['sex'] = pet['sex'] data['age'] = pet['age'] data['size'] = pet['size'] data['shelter_contact'] = pet['contact'] data['photos'] = pet['photos'] else: data['name'] = 'none' data['sex'] = 'none' data['age'] = 'none' data['size'] = 'none' data['shelter_contact'] = 'none' data['photos'] = 'none' data['breed'] = breed data['prob'] = prob data['breed_info'] = search return data except Exception as e: data['breed'] = breed data['prob'] = prob data['breed_info'] = search data['petfinder_error'] = 'Breed not in PF Database' return data # Package Info in dict/json object #data['breed'] = breed #data['prob'] = prob #data['name'] = pet['name'] #data['sex'] = pet['sex'] #data['age'] = pet['age'] #data['size'] = pet['size'] #data['breed_info'] = search #data['shelter_contact'] = pet['contact'] #data['photos'] = pet['photos'] #return data except Exception as e: return {'server_error': 'if you are seeing this, save the picture'}
from django.contrib.auth.models import User from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse from django.views import View from django.utils import timezone from django.contrib.auth import authenticate, login, logout from django.contrib import messages import requests, json, googlemaps, petfinder, datetime from .forms import UserForm gmaps = googlemaps.Client(key='AIzaSyDWRoV2ae3J-BCp0LKXcoFdmpHxIEQnXXE') petapi = petfinder.PetFinderClient( api_key='b41019e06145925caa78884c95a3f60e', api_secret='0a2d8f1549b50a91fb47bb707f3663d2') # Create your views here. def toCleanedTime(str): return ' '.join(str.split('T')) class Home(View): def get(self, request): if request.user.is_authenticated(): return render(request, 'pets/index.html') form = UserForm() return render(request, 'pets/index.html', {'form': form})
from django.shortcuts import render from django.http import HttpResponse, HttpRequest, HttpResponseRedirect from django.contrib.auth import authenticate, login, logout from friendFinder import settings from django.contrib.auth.decorators import login_required import urllib2 import models # import yaml import re import json from django.http import JsonResponse import petfinder import config # Instantiate the client with your credentials. api = petfinder.PetFinderClient(api_key=config.API_KEY, api_secret=config.API_SECRET) def login(request): # next = request.GET.get('next', '/home/') if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: login(request, user) return HttpResponseRedirect('/') else: HttpResponseRedirect(settings.LOGIN_URL)
# This Python file uses the following encoding: utf-8 import os, sys import petfinder # Instantiate the client with your credentials. api = petfinder.PetFinderClient(api_key="3edba6cadbd9d8fcdc5864a85e648862", api_secret="e3be377653ead49c13322f42134370d0") # Query away! # zip_code = int(raw_input("Enter your zip code to find a shelter near you: ")) # try: # for shelter in api.shelter_find(location=zip_code, count=500): # import pdb; pdb.set_trace() # ability to pause program, for debugging # print(shelter["name"]) # except petfinder.exceptions.LimitExceeded: # pass # species = raw_input("Would you like to adopt a dog or a cat? ") # # age = raw_input("Enter an age: ") # # gender = raw_input("Enter a gender: ") # # Search for pets. # for pet in api.pet_find(animal=species, location='94132', output="basic", # breed="German Shepherd", count=200,): species = raw_input("Would you like to adopt a dog or a cat? ") location = raw_input("Enter your zip code or city/State to find the animal nearest you: ") age = raw_input("Would you like to adopt a Baby, Young, Adult or Senior pet? ") gender = raw_input("Male, Female? ")
from flask import Flask, request, session from twilio import twiml import os import petfinder # The session object makes use of a secret key. SECRET_KEY = 'a_secret_key' app = Flask(__name__) app.config.from_object(__name__) api = petfinder.PetFinderClient(api_key=os.environ['api_key'], api_secret=os.environ['api_secret'] ) @app.route("/", methods=['GET','POST']) def shelter_or_pet(): if request.values.get('Body', None): text = request.values.get('Body', None).encode('utf-8') else: text = 'default' if text is not None and session.get('shelterId'): if 'I want to adopt' in text: return send_shelter() elif 'next' in text or 'more' in text or 'pass' in text: return send_pet() else: resp = twiml.Response()
import petfinder api = petfinder.PetFinderClient(api_key='710fb86300ed19f143a1671a3c171456', api_secret='64e4de99d362e6b4b1b53bda89c65296') #Getting pet's dictionary id id = api.pet_getrandom( animal="dog", location="02912", output="basic", breed="Golden Retriever") photo = id['photos'][0]['url'] name = id['name'] breed = id['breeds'] contact = id'contact'] print photo + name + breed + shelter