Exemplo n.º 1
0
 def delete(self, id):
     try:
         countries.Capitals().delete_capital(id)
         return 'ok', 200
     except Exception as e:
         logging.exception("Delete failed")
         return 'failed to delete', 404
Exemplo n.º 2
0
    def put(self, id):
        data = {}
        try:
            country_from_input = request.get_json()
            if country_from_input == None:
                return {}, 400

            # print("hi")
            if 'id' in country_from_input:
                payloadid = country_from_input['id']
            if 'country' in country_from_input:
                countryName = country_from_input['country']
            if 'name' in country_from_input:
                name = country_from_input['name']
            if 'countryCode' in country_from_input:
                countryCode = country_from_input['countryCode']
            if 'continent' in country_from_input:
                continent = country_from_input['continent']
            if 'location' in country_from_input:
                location = country_from_input['location']
                if location is not None:
                    if 'latitude' in location:
                        latitude = location['latitude']
                    if 'longitude' in location:
                        longitude = location['longitude']
            # print(name)
            capitals = countries.Capitals()
            capitals.store_capital(id, payloadid, countryName, name,
                                   countryCode, continent, latitude, longitude)
            return "hi", 200

        except Exception as e:
            # swallow up exceptions
            logging.exception('Oops!')
Exemplo n.º 3
0
 def post(self, id):
     try:
         capital = countries.Capitals().get_by_id(id)
         logging.info('badaboom::capital is {}'.format(capital))  ####
         print('badaboom::capital is {}'.format(capital))  ####
         if capital is None:
             logging.info('badaboom::capital not found')  ####
             print('badaboom::capital not found')  ####
             return {"code": 0, "message": "capital not found"}, 404
         topic_name = request.get_json()['topic']
         meow = topic_name.split('/')
         pubsub_client = pubsub.Client(meow[1])
         print('badaboom::nyaaa? {}'.format(meow[1]))  ####
         logging.info('badaboom::nyaaa? {}'.format(meow[1]))  ####
         topic_name = meow[3]
         print('badaboom::topic name is {}'.format(topic_name))  ####
         logging.info('badaboom::topic name is {}'.format(topic_name))  ####
         #            print(topic_name)
         topic = pubsub_client.topic(topic_name)
         #            print('ok...')
         #topic.create() #... don't create a topic, you misunderstand =/...
         #            print('yeah??')
         #            return {}, 200  ### no need to return right?
         try:
             topic.create()
             print('badaboom::topic created!!!')
             logging.info('badaboom::topic created!!!')
         except:
             logging.info(
                 'probably topic {} already exists'.format(topic_name))
             print('probably topic {} already exists'.format(topic_name))
         logging.info('publishing... {}'.format(
             json.dumps(countries.Capitals.nest_geopoint(capital))))
         print('publishing... {}'.format(
             json.dumps(countries.Capitals.nest_geopoint(capital))))
         return_shi = {
             "messageId":
             int(
                 topic.publish(
                     json.dumps(countries.Capitals.nest_geopoint(capital))))
         }, 200
         logging.info('returned shi is {}'.format(return_shi))
         print('returned shi is {}'.format(return_shi))
         return return_shi
     except:
         logging.exception(
             "something went wrong, maybe already existing with this name not consumed?"
         )
         print(
             "something went wrong, maybe already existing with this name not consumed?"
         )
         return {
             "code":
             0,
             "message":
             "something went wrong, maybe already existing with this name not consumed?"
         }, 404  # should be some other error?
Exemplo n.º 4
0
    def get(self):
        args = capitals_request_parser.parse_args()
        query_string = args['query']
        search_string = args['search']
        if search_string is not None:
            capitals = countries.Capitals().search_captial(search_string)
            if len(capitals) < 1:
                return [], 404
            return capitals, 200

        if query_string is not None:
            splitted_query_string = query_string.split(':')
            if len(splitted_query_string) != 2:
                return 'wrong query format', 400

            return countries.Capitals().query_capital(
                splitted_query_string[0], splitted_query_string[1]), 200
        return countries.Capitals().fetch_capitals(), 200
Exemplo n.º 5
0
def polymer_mapll(map_lat, map_lng):
    caps_w_dups = countries.Capitals().fetch_capitals()
    caps_wo_dups = set(
        (cap['location']['latitude'], cap['location']['longitude'],
         cap['country'], cap['name']) for cap in caps_w_dups)
    return render_template('index.html',
                           map_lat=map_lat,
                           map_lng=map_lng,
                           lat_longs=caps_wo_dups)
Exemplo n.º 6
0
 def get(self, id):
     try:
         results = countries.Capitals().fetch_capital(id)
         if results is None:
             return 'record not found', 404
         return results, 200
     except Exception as e:
         logging.exception(e)
         return 'failed to fetch record', 404
Exemplo n.º 7
0
    def post(self, id):
        data = {}
        try:
            bucket_info = request.get_json()
            if bucket_info == None:
                return {}, 400

            if 'bucket' in bucket_info:
                bucket_name = bucket_info['bucket']

            capital_record = countries.Capitals().fetch_capital(id)
            gcs = cloud_storage.CloudStorage()
            # gcs.create_bucket(capital_record, bucket_name, id)
            mesg, code = gcs.store_file_to_gcs(bucket_name,
                                               json.dumps(capital_record), id)
            return mesg, code

        except Exception as e:
            # swallow up exceptions
            logging.exception('Oops!')
            return 'failed to store capital', 404
Exemplo n.º 8
0
def google_map():
    caps_w_dups = countries.Capitals().fetch_capitals()
    caps_wo_dups = set(
        (cap['location']['latitude'], cap['location']['longitude'])
        for cap in caps_w_dups)
    return render_template('google_map.html', lat_longs=caps_wo_dups)
Exemplo n.º 9
0
def list():
    caps_w_dups = countries.Capitals().fetch_capitals()
    caps_wo_dups = sorted(
        set((cap['country'], cap['name']) for cap in caps_w_dups))
    return render_template('welcome.html', capitals=caps_wo_dups)