Ejemplo n.º 1
0
 async def handle_reaction_remove(reaction, user):
     global emojis, count
     chn = reaction.message.channel
     try:
         if user.id == bot.user.id:
             return
         msg = reaction.message
         if str(reaction.emoji) in emojis:
             # Count all stars
             cc = 0
             for r in msg.reactions:
                 cc += r.count if str(r.emoji) in emojis else 0
             # Check if above threshold
             if count <= cc and count > 0:
                 await plug_starboard(msg, emojis)
             # Check if below threshold
             elif count > 0 and count > cc:
                 stars = msg.guild.get_channel(channel_id)
                 stars_id = dbman.get('starboard',
                                      'starboard_id',
                                      message_id=msg.id)
                 if stars_id:
                     stars_msg = await stars.fetch_message(stars_id)
                     await stars_msg.delete()
                     dbman.remove('starboard',
                                  starboard_id=stars_id,
                                  message_id=msg.id)
     except IndexError:
         pass
     except Exception as ex:
         await chn.send(f"`{ex}` line {ex.__traceback__.tb_lineno}")
Ejemplo n.º 2
0
async def on_raw_message_delete(payload):
    # Clean out the starboard database in case it gets unstarred
    stars_id = dbman.get('starboard', 'starboard_id', message_id = payload.message_id)
    if stars_id:
        dbman.remove('starboard', starboard_id = stars_id, message_id = payload.message_id)
        return
    msg_id = dbman.get('starboard', 'message_id', starboard_id = payload.message_id)
    if msg_id:
        dbman.remove('starboard', starboard_id = payload.message_id, message_id = msg_id)
        return
Ejemplo n.º 3
0
def clean_from_wrong_proteins(soft=True):
    """Removes proteins with premature or lacking stop codon.

    Args:
        soft: use if the faulty proteins were not committed yet (expunge instead of delete)

    """
    print('Removing proteins with misplaced stop codons:')
    from database import remove

    proteins = get_proteins()

    stop_inside = 0
    lack_of_stop = 0
    no_stop_at_the_end = 0

    to_remove = set()

    for protein in tqdm(proteins.values()):
        hit = False
        if '*' in protein.sequence[:-1]:
            stop_inside += 1
            hit = True
        if protein.sequence[-1] != '*':
            no_stop_at_the_end += 1
            hit = True
        if '*' not in protein.sequence:
            lack_of_stop += 1
            hit = True
        if hit:
            to_remove.add(protein)

    with db.session.no_autoflush:
        removed = set()
        for protein in to_remove:
            removed.add(protein.refseq)

            gene = protein.gene
            gene.preferred_isoform = None

            remove(protein, soft)

            # remove object
            del proteins[protein.refseq]

    select_preferred_isoforms()

    print('Removed proteins of sequences:')
    print('\twith stop codon inside (excluding the last pos.):', stop_inside)
    print('\twithout stop codon at the end:', no_stop_at_the_end)
    print('\twithout stop codon at all:', lack_of_stop)
Ejemplo n.º 4
0
def handle_text(message):
    try:
        arguments = parsing.find_arguments(message.text)
        record_id = parsing.get_id(arguments[0])
        database.remove(message.chat.id, record_id)
        bot.send_message(message.chat.id, quotes.REMOVE_OK)
    except exceptions.WrongNumberOfArgumentsException as exception:
        bot.send_message(message.chat.id, exception.value)
    except exceptions.NoSuchRecordException as exception:
        bot.send_message(message.chat.id, exception.value)
    except exceptions.InvalidArgumentFormatException as exception:
        bot.send_message(message.chat.id, exception.value)
    except OSError as exception:
        logging.critical(exception)
        bot.send_message(message.chat.id, quotes.BACKEND_ERROR)
        raise
    except Exception as exception:
        logging.error(exception)
        bot.send_message(message.chat.id, quotes.UNEXPECTED_ERROR)
        raise
Ejemplo n.º 5
0
def testDB():
	# new store
	database.store = {}
	# add to database
	database.addToDB("sec", fid = "test")
	database.addToDB("sec", msg = "anotherone")
	# get from database
	assert len(database.get("sec", database.getDate())) == 2
	assert (database.get("sec", database.getDate()))[0]['fid'] == "test"
	assert (database.get("sec", database.getDate()))[1]['msg'] == "anotherone"
	assert (database.get("oth", database.getDate())) == []
	# save database to pickle
	database.save("temp.pickle")
	# remove from database
	database.remove(database.getDate())
	assert database.get("sec", database.getDate()) == []
	# load database from pickle
	database.store = database.load("temp.pickle")
	# get from database
	assert (database.get("sec", database.getDate()))[0]['fid'] == "test"
	assert (database.get("sec", database.getDate()))[1]['msg'] == "anotherone"
	os.remove("temp.pickle")
Ejemplo n.º 6
0
 def delete(self, bookId):
   database.remove(bookId);
   self.response.write(bookId);
Ejemplo n.º 7
0
#! This program can keep your passwords encrypted
""" With this program, you can keep all your passwords in safety.

    Commands: help, add, remove, find, change, showall, clear """

import database as data

while True:
    task = str(input("Enter a command here: "))
    if task == 'help':
        print(__doc__)
    elif task == 'add':  # Добавления данных в словарь
        a = input(str("Enter resource: "))
        b = input(str("Enter password: "******"Enter a key: "))
        data.remove(a)
    elif task == 'find':  # Поиск данных в словаре
        a = input(str("Enter a key:"))
        data.find(a)
    elif task == 'change':  # Изменение данных в словаре
        a = input(str("Enter a key you want to rename: "))
        data.change(a)
    elif task == 'showall':  # Показать все данные в словаре
        data.showall()
    elif task == 'clear':
        data.clear()
    else:
        print("No such command %30s" % task)