コード例 #1
0
def leggi_amount(bot, update):
    text = update.message.text
    try:
        amt = int(text)
    except ValueError:
        update.message.reply_text(
            "Attenzione! Valore non valido. Inserire un numero!")
        return LEGGI_AMOUNT

    content["amount"] = amt
    utils.save_content(content)

    update.message.reply_text("*Valore salvato* 👍", parse_mode="Markdown")
    return ConversationHandler.END
コード例 #2
0
def leggi_generale(bot, update, tipo: str):
    global content

    text = update.message.text

    # se ho degli hashtag li voglio tutti minuscoli
    if tipo == "hashtag":
        text = text.lower()

    if text == "#":
        update.message.reply_text("*{} salvati* 😎".format(tipo.capitalize()),
                                  parse_mode="Markdown")
        return ConversationHandler.END

    content[tipo][cartella_corrente[tipo]].append(text)
    utils.save_content(content)
コード例 #3
0
def leggi_cartella_generale(bot, update, tipo: str, return_value_edit):
    """
    Richiesta all'utente della cartella generale
    :param tipo: il nome del tipo di cartella "hashtag" oppure "commenti"
    :param return_value_edit: il valore di ritorno (il nuovo stato della conversazione)
    :return: lo stato del ritorno definito da return_value
    """

    global cartella_corrente
    global content

    # errore nel passaggio dei parametri, finisco la conversazione
    if (tipo != "commenti") and (tipo != "hashtag"):
        return fine_conversazione(bot, update)

    # imposto la cartella corrente come il messaggio che ho appena letto
    cartella_corrente[tipo] = update.message.text

    # se la cartella esiste (non devo crearla) procedo ad elencare tutti i valori che contiene
    if cartella_corrente[tipo] in list(content[tipo].keys()):
        risposta = "*Cartella di {}*:\n  🔥 {}".format(tipo,
                                                      cartella_corrente[tipo])

        risposta += "\n\n*{} salvati*:".format(tipo.capitalize())
        for item in content[tipo][cartella_corrente[tipo]]:
            risposta += "\n▫️ {}".format(item)

        # mando il messaggio e chiedo all'utente che cosa vuole fare di questa cartella
        update.message.reply_text(
            risposta,
            parse_mode="Markdown",
            reply_markup=telegram.ReplyKeyboardMarkup(
                [["🔄  Riscrivi", "✏️ Aggiungi"], ["❌  Elimina", "✅ Fine"]],
                resize_keyboard=True))
        return return_value_edit

    # se la cartella nel messaggio non esiste la creo e poi passo alla return_value
    else:
        content[tipo][cartella_corrente[tipo]] = []
        utils.save_content(content)
        update.message.reply_text(
            "Nuova cartella *{}* creata. La troverai in /{}".format(
                cartella_corrente[tipo], tipo),
            parse_mode="Markdown")
        return fine_conversazione(bot, update)
コード例 #4
0
def main():
    config_path = get_arguments_dict(sys.argv[1:])['config']
    config = get_config(config_path)
    res = requests.get(config.get('remote_url'))
    json_result = res.json().get('images')
    save_content(json.dumps(json_result, indent=2), config.get('output_path'),
                 'result.json')
    print(
        Fore.GREEN +
        f'saved api result in "{config.get("output_path")}" with name "result.json"'
    )

    first = True
    for item in json_result:
        full_image_name = item['url'].split('/')[-1]
        extension = full_image_name.split('.')[-1]
        image_name = full_image_name.split('_')[0]
        save_image(f'http://www.bing.com/{item["url"]}',
                   config.get('output_path'), image_name + '.' + extension)
        if first:
            save_image(f'http://www.bing.com/{item["url"]}',
                       config.get('output_path'), '_latest.' + extension)
            first = False
コード例 #5
0
def modifica_cartella_generale(bot, update, tipo: str, return_value_read):
    global content
    comando = update.message.text.lower()

    if (tipo != "commenti") and (tipo != "hashtag"):
        # se ho un errore nel passaggio dei parametri finisco la conversazione
        return fine_conversazione(bot, update)

    elif "riscrivi" in comando:
        update.message.reply_text(
            "🔄  Riscrivi *{}* (cartella di *{}*)\nManda *#* per terminare".
            format(cartella_corrente[tipo], tipo),
            parse_mode="Markdown",
            reply_markup=telegram.ReplyKeyboardRemove())
        # resetto il contetnuto della cartella prima di leggere (leggere eseguirà .append())
        content[tipo][cartella_corrente[tipo]] = []
        return return_value_read

    elif "aggiungi" in comando:
        update.message.reply_text(
            "✏️ Aggiungi a *{}* (cartella di *{}*)\nManda *#* per terminare".
            format(cartella_corrente[tipo], tipo),
            parse_mode="Markdown",
            reply_markup=telegram.ReplyKeyboardRemove())
        return return_value_read

    elif "elimina" in comando:
        update.message.reply_text("❌  Cartella di {} *{}* eliminata!".format(
            tipo, cartella_corrente[tipo]),
                                  parse_mode="Markdown",
                                  reply_markup=telegram.ReplyKeyboardRemove())
        del content[tipo][cartella_corrente[tipo]]
        utils.save_content(content)
        return ConversationHandler.END
    else:
        return fine_conversazione(bot, update)
コード例 #6
0
ファイル: main.py プロジェクト: emileae/aandewijnlanden
    def post(self):

        request = self.request

        list_items = self.request.get("list_items")

        if list_items:
            logging.error(". . . . . . . . . . ---- multiple")
            content_id = utils.save_list_content( request )
        else:
            logging.error(". . . . . . . . . . ---- NOT multiple")
            content_id = utils.save_content( request )

        self.render_json({
            "message": "success",
            "content_id": content_id
            })
コード例 #7
0
 def finalize(self):
     save_json(self.key, self.data)
     save_content(self.key, self.data)