def __initPoll(cls, user): """ Tries to reinitialize poll if needed in 10 times (each 10 seconds) As soon as poll initialized user will be removed from buffer """ for x in xrange(10): if user.source not in Transport: logger.debug("longpoll: while we were wasting our time" ", the user has left (jid: %s)" % user.source) with cls.__lock: if user in cls.__buff: cls.__buff.remove(user) return None if Transport[user.source].vk.initPoll(): with cls.__lock: logger.debug("longpoll: successfully initialized longpoll (jid: %s)" % user.source) if user not in cls.__buff: return None cls.__buff.remove(user) # Check if user still in transport when we finally came down here if user.source in Transport: cls.__add(Transport[user.source]) break time.sleep(10) else: with cls.__lock: if user not in cls.__buff: return None cls.__buff.remove(user) logger.error("longpoll: failed to add user to poll in 10 retries (jid: %s)" % user.source)
def upload(temp_t,dest_t,connection,algnmt,algnmt_col,field_sep='\t',line_sep=None): cursor = connection.cursor() check_sql="select Accession_Number,'' from {} where {} is null" cursor.execute(check_sql.format(dest_t)) rows=dict(cursor.fetchall()) cnt0 = [] for k,v in rows.iteritems(): cnt0.append(k) if line_sep: sql = "load data local infile '{}' ignore into table {} fields terminated by {} {} (Header,{})" logger.debug('load alignment data statement: {}'.format(sql.format(algnmt,temp_t,field_sep,line_sep,algnmt_col))) cursor.execute(sql.format(algnmt,temp_t,field_sep,line_sep)) else: sql = "load data local infile '{}' ignore into table {} fields terminated by {} (Header,{})" logger.debug('load alignment data statement: {}'.format(sql.format(algnmt,temp_t,field_sep,algnmt_col))) cursor.execute(sql.format(algnmt,temp_t,field_sep)) connection.commit() sql = "update {} a, {} b set a.{}=b.{} where a.Accession_Number=b.Accession_Number" logger.debug('update aligned seqs to table statement: {}'.format(sql.format(dest_t,temp_t,algnmt_col,algnmt_col))) cursor.execute(sql.format(dest_t,temp_t)) connection.commit() cursor.execute(check_sql.format(dest_t)) rows=dict(cursor.fetchall()) cnt1 = [] for k,v in rows.iteritems(): cnt1.append(k) updated = len(cnt1) - len (cnt0) if 0 >= updated: logger.error('alignment upload failed.') return else: logger.info('{} aligned sequences uploaded into table {}'.format(updated,dest_t)) cursor.execute("truncate {}".format(temp_t)) connection.commit()
def format_algnmt(algnmt, inform, outext): com = "convalign -i {} {} {}".format(inform, outext, algnmt) logger.debug('convert alignment command: {}'.format(com)) p = sp.Popen([com], stderr=sys.stderr, stdout=sys.stdout) p.wait() algnmt = glob.glob(os.path.split(algnmt)[0] + '*.' + outext) if len(algnmt): logger.info('alignment conversion successful') return algnmt else: logger.error('conversion failed') return
def format_algnmt(algnmt,inform,outext): com = "convalign -i {} {} {}".format(inform,outext,algnmt) logger.debug('convert alignment command: {}'.format(com)) p = sp.Popen([com],stderr=sys.stderr,stdout=sys.stdout) p.wait() algnmt = glob.glob(os.path.split(algnmt)[0] + '*.' + outext) if len(algnmt): logger.info('alignment conversion successful') return algnmt else: logger.error('conversion failed') return
def process(cls): """ Processes poll sockets by select.select() As soon as socket will be ready to be read will be called user.processPollResult() function Read processPollResult.__doc__ to learn more about status codes """ while ALIVE: socks = cls.__list.keys() if not socks: time.sleep(0.02) continue try: ready, error = select.select(socks, [], socks, 2)[::2] except (select.error, socket.error) as e: logger.error("longpoll: %s" % (e.message)) # debug? for sock in error: with cls.__lock: # We will just re-add the user to poll # in case if anything weird happen to the socket try: cls.__add(cls.__list.pop(sock)[0]) except KeyError: continue for sock in ready: with cls.__lock: try: user, opener = cls.__list.pop(sock) except KeyError: continue # Check if user is still in the memory user = Transport.get(user.source) if not user: continue # Check if the user haven't left yet if not user.vk.online: continue utils.runThread(cls.processResult, (user, opener), "poll.processResult-%s" % user.source) with cls.__lock: for sock, (user, opener) in cls.__list.items(): if not user.vk.online: logger.debug("longpoll: user is not online, so removing their from poll" " (jid: %s)" % user.source) try: del cls.__list[sock] except KeyError: pass
async def query(self, ctx, Query): 'Queries if a film is avaliable in your countries' name = "Query" print(f"{ctx.author} running command {name}") try: Query = str(Query) r = requests.get( f"https://unogs.com/search/{Query}?country_andorunique=and&start_year=1900&end_year=2021&end_rating=10&genrelist=&audiosubtitle_andor=or&countrylist=39,46" ) print(r.text) soup = bs(r, "html.parser") except (Exception) as Exc: logger.error( f"Uncaught Exception in Module : `{name}`, ErrorType : `{type(Exc)}` : {Exc}" )
def __add(cls, user): """ Issues readable socket to use it in select() Adds user in buffer on error occurred Adds user in self.__list if no errors """ try: opener = user.vk.makePoll() except Exception as e: if not isinstance(e, api.LongPollError): crashLog("poll.add") logger.error("longpoll: failed to make poll (jid: %s)" % user.source) cls.__addToBuff(user) return False else: cls.__list[opener.sock] = (user, opener) return opener
def upload(temp_t, dest_t, connection, algnmt, algnmt_col, field_sep='\t', line_sep=None): cursor = connection.cursor() check_sql = "select Accession_Number,'' from {} where {} is null" cursor.execute(check_sql.format(dest_t)) rows = dict(cursor.fetchall()) cnt0 = [] for k, v in rows.iteritems(): cnt0.append(k) if line_sep: sql = "load data local infile '{}' ignore into table {} fields terminated by {} {} (Header,{})" logger.debug('load alignment data statement: {}'.format( sql.format(algnmt, temp_t, field_sep, line_sep, algnmt_col))) cursor.execute(sql.format(algnmt, temp_t, field_sep, line_sep)) else: sql = "load data local infile '{}' ignore into table {} fields terminated by {} (Header,{})" logger.debug('load alignment data statement: {}'.format( sql.format(algnmt, temp_t, field_sep, algnmt_col))) cursor.execute(sql.format(algnmt, temp_t, field_sep)) connection.commit() sql = "update {} a, {} b set a.{}=b.{} where a.Accession_Number=b.Accession_Number" logger.debug('update aligned seqs to table statement: {}'.format( sql.format(dest_t, temp_t, algnmt_col, algnmt_col))) cursor.execute(sql.format(dest_t, temp_t)) connection.commit() cursor.execute(check_sql.format(dest_t)) rows = dict(cursor.fetchall()) cnt1 = [] for k, v in rows.iteritems(): cnt1.append(k) updated = len(cnt1) - len(cnt0) if 0 >= updated: logger.error('alignment upload failed.') return else: logger.info('{} aligned sequences uploaded into table {}'.format( updated, dest_t)) cursor.execute("truncate {}".format(temp_t)) connection.commit()
def add(cls, some_user): """ Adds the User class object to poll """ if DEBUG_POLL: logger.debug("longpoll: adding user to poll (jid: %s)", some_user.source) with cls.__lock: if some_user in cls.__buff: return None for sock, (user, opener) in cls.__list.iteritems(): if some_user == user: break else: try: cls.__add(some_user) except Exception as e: if not isinstance(e, api.LongPollError): crashLog("poll.add") logger.error("longpoll: failed to make poll (jid: %s)", some_user.source) cls.__addToBuff(some_user)