# scripts/delete_all_questions.py
# *coding: utf-8*

from backoffice.models import Place
import requests
import urllib
import time
import logging,json
logger = logging.getLogger('django')

def run():
    # Fetch all places
    allPlaces = Place.objects.filter(valid=True)
    for place in allPlaces:
        if place.googlePlaceId:
            url="https://maps.googleapis.com/maps/api/place/details/json?place_id="+place.googlePlaceId+"&key=AIzaSyC2StTKAdCeCl2zUwzNhLxR8kWWyqOQjYQ"
            try:
                print("On doit checker " + url)
                response = requests.get(url)
                data = response.json()
                if data["status"] == "OK":
                    place.googlePlaceJson=json.dumps(data["result"])
                    result = data["result"]
                    print(result)
                    if "photos" in result:
                        print("Photos %s"%result["photos"])
                    place.save()
            except Exception as e:
                print(e)
        break




