Пример #1
0
 def p_pop(self):
     self.response.headers["Content-Type"] = "application/json"
     if users.is_current_user_admin():
         storage.delete(self.request.get('key'))
         self.response.out.write(json.dumps({'status': 'done'}))
     else:
         self.response.out.write(json.dumps({'status': 'forbidden'}))
Пример #2
0
def update_set(item_name, expiry_time, base_query=None, item_ids=None, get_item_method=None):

	# Find item_type
	if item_name in items_apis:
		api_to_use = items_apis[item_name]
	else:
		raise Exception("Unknown item name")

	# Validate input to this function
	if api_to_use == "woocommerce":
		if base_query is None:
			raise Exception("Please supply a base query")
	elif api_to_use == "gravityforms":
		if item_ids is None:
			raise Exception("Please supply all current item IDs")
		if get_item_method is None:
			raise Exception("Please supply a method that retrieves a single item based on its ID")
	else:
		raise Exception("Unknown API")

	# Save new data and remove data that is no longer present
	ids_before = get_item_ids(item_name)
	if api_to_use == "woocommerce":
		download_paginated_set(item_name, base_query, expiry_time)
	elif api_to_use == "gravityforms":
		download_items_from_ids(item_name, expiry_time, item_ids, get_item_method)
	else:
		raise Exception("Unknown API")
	ids_after = get_item_ids(item_name)
	deleted_ids = list_diff(ids_before, ids_after)
	for item_id in deleted_ids:
		storage.delete(get_single_item_storage_key(item_name, item_id))
Пример #3
0
 def p_pop(self):
     self.response.headers["Content-Type"] = "application/json"
     if users.is_current_user_admin():
         storage.delete(self.request.get('key'))
         self.response.out.write(json.dumps({'status':'done'}))
     else:
         self.response.out.write(json.dumps({'status':'forbidden'}))
Пример #4
0
def cleaning_fb():
    if request.headers['X-Appengine-Cron']:
        # here we check how long passed after last message to akinator
        # if it is long enough delete the document from collection
        docs = storage.coll_content(bot_akinator.AKINATOR_COLLECTION)
        for doc in docs:
            get_doc = storage.get(bot_akinator.AKINATOR_COLLECTION, doc)
            # if more than 5 min passed we delete aki history
            if (datetime.now(timezone.utc) - get_doc['last_active']).seconds > 300:
                storage.delete(bot_akinator.AKINATOR_COLLECTION, doc)
    return 'ok'
Пример #5
0
    def test_delete(self):
        storage.insert(Age("mouse", 20))
        storage.delete(Age)

        saved_objects = storage.find(Age)
        self.assertEqual(len(saved_objects), 0)

        model = storage.put(Person(name="alabama"))
        storage.put(Person(name="orm"))
        storage.delete(Person, uuid=model.uuid)

        saved_objects = storage.find(Person)
        self.assertEqual(len(saved_objects), 1)
Пример #6
0
def delete_blob(blob_key):
  """Delete a blob key."""
  blob_info = get_blob_info(blob_key)
  if not blob_info:
    return False

  return storage.delete(blob_info.gcs_path)
Пример #7
0
def game(from_id, text, time, returning):
    if text.lower() == 'stop':  # deleting the saved game
        storage.delete(AKINATOR_COLLECTION, str(from_id))
        return {"text": "Thank you for playing! If you want to play again just type and send Akinator!",
                "image_url": None, 'win': True}
    if returning:  # resuming the game
        fields = storage.get(AKINATOR_COLLECTION, str(from_id))  # getting saved game
        aki = load(fields)  # creating akinator instance
        if text.lower() in ['back', 'b']:  # we need to go back
            try:
                response = {"text": aki.back(), "image_url": None, 'win': False}
                aki.last_active = time
                storage.update(AKINATOR_COLLECTION, str(from_id), dump(aki))
                return response
            except akinator.exceptions.CantGoBackAnyFurther:
                return {"text": "Cannot go back! If you want to stop send Stop", "image_url": None, 'win': False}
        try:
            response = {"text": aki.answer(text), "image_url": None, 'win': False}  # passing users answer to akinator
        except akinator.exceptions.InvalidAnswerError:
            return {"text": """You put "{}", which is an invalid answer.
                The answer must be one of these:
                    - "yes" OR "y" OR "0" for YES
                    - "no" OR "n" OR "1" for NO
                    - "i" OR "idk" OR "i dont know" OR "i don't know" OR "2" for I DON'T KNOW
                    - "probably" OR "p" OR "3" for PROBABLY
                    - "probably not" OR "pn" OR "4" for PROBABLY NOT
                If you want to stop playing send word Stop.
                """.format(text), 'win': False, "image_url": None}
        #  checking if we are close to make prediction
        if aki.progression >= 90:  # we can make a prediction
            aki.win()
            response = {'text': "It's {} ({})!".format(aki.name, aki.description), 'win': True}
            if aki.picture:
                response['image_url'] = aki.picture
            storage.delete(AKINATOR_COLLECTION, str(from_id))  # deleting document when the game is over
        else:  # we need to save current progression
            aki.last_active = time
            d = dump(aki)
            storage.update(AKINATOR_COLLECTION, str(from_id), d)
    else:  # creating the new game
        aki = akinator.Akinator()
        # starting game and asking user first question
        response = {"text": aki.start_game(), "image_url": None, 'win': False}
        # save current progress
        aki.last_active = time
        storage.add(AKINATOR_COLLECTION, str(from_id), dump(aki))
    return response
Пример #8
0
def delete():
    ''' Deletes the posted data by looking up the posted timestamp '''
    jsonAsDict = getDictFromPost(request)
    listName = jsonAsDict.get('listName')
    postId = jsonAsDict.get('id')
    if listName != None and listName != '' and listName != 'undefined' and postId != None and postId != '' and postId != 'undefined':
        if storage.delete(listName, current_identity, postId):
            return Response('OK', 200)
        return Response('List is locked, cannot delete', 409)
    return Response('Not found', 404)
Пример #9
0
def command_delete(id_=None):
    storage.delete('commands', int(id_))
    return "ok"
Пример #10
0
def alarm_delete(id_):
    storage.delete('alarms', int(id_))
    alarms.set_alarms(storage.read('alarms'))
    return "ok"
Пример #11
0
            text_labels = rekognition.get_text_labels(text_result, ct)
            draw.annotate_text(image, text_result)
            if text_labels and not face_labels:
                draw.display_text(text_labels)
                audio.play_mp3("text_comment.mp3")
                polly.speak(text_labels)
            # Step 4. What else is in the picture?
            label_result = rekognition.detect_labels_api(s3)
            labels = rekognition.get_labels(label_result, ct)
            draw.annotate_labels(image, label_result)
            if labels and not face_labels:
                os.system('clear')
                draw.display_text(labels)
                database.inc(labels)
                audio.play_mp3("labels_comment.mp3")
                polly.speak(labels)
            draw.save_image(image, temp_file)
            # Upload annotated image to S3
            storage.upload(temp_file)
            audio.play_mp3("closure_comment.mp3")
            storage.delete(s3['S3Object']['Name'])
            draw.preview_image(temp_file, button)
            os.system('clear')
            print(ready_message)
        time.sleep(0.1)
except KeyboardInterrupt:
    print("...request to stop program...")
finally:
    audio.play_mp3("exception_comment.mp3")
    print("[PiCeDoFi-IMAPI-RU] process ended")
Пример #12
0
def delete(file_hash):
    storage.delete(file_hash)
    return web.Response(text='File deleted')
Пример #13
0
                    # log.debug("geofence is already in db and has not been updated.")

            # Find deleted vegobjekter in NVDB by getting a list of ID's from our
            # cache database and list all ID's missing in our JSON from NVDB.
            vegobjekter = storage.vegobjekter().all()
            for v in vegobjekter:
                # log.debug("inspecting v: {}".format(v.get("id")))
                if v.get("id") not in vegobjekt_ids:
                    msg = "Vegobjekt with ID '{}' removed from NVDB: {}".format(
                        v.get("id"), v)
                    log.warn(msg)
                    slack_notify(msg, slack_url)
                    datex_obj = datex2.create_delete_doc_from_db(v)
                    ic.send_obj(datex_obj)
                    log.debug(datex_obj)
                    storage.delete(v.get("id"))
                    log.warn("Delete geofence id: {}".format(v.get("id")))

        except ConnectionError:
            # Interchange lost its connection
            log.debug(
                "Interchange connection error. Trying to re-connect. URI: {}".
                format(cfg.get("broker_url")))
            #while True:
            #    try:
            #        ic.connect()
            #        log.debug("Successfully re-connected to {}".format(cfg.get("broker_url")))
            #    except ConnectionError:
            #        log.debug("")
            #        time.sleep(5)
            #        continue
Пример #14
0
from servicebus import enqueue
from storage import delete, upload

delete('file1.txt')
delete('file2.txt')
delete('file3.txt')

upload('./sample_file.txt', 'file1.txt')
upload('./sample_file.txt', 'file2.txt')
upload('./sample_file.txt', 'file3.txt')

data1 = '{"timestamp": "2019-09-25 00:00:00.000000", "filename": "file1.txt", "device_id": "device1"}'
data2 = '{"timestamp": "2019-09-25 00:00:00.000000", "filename": "file2.txt", "device_id": "device2"}'
data3 = '{"timestamp": "2019-09-25 00:00:00.000000", "filename": "file3.txt", "device_id": "device3"}'

enqueue(data1, 'SERVICE_BUS_INPUT_QUEUE')
enqueue(data2, 'SERVICE_BUS_INPUT_QUEUE')
enqueue(data3, 'SERVICE_BUS_INPUT_QUEUE')