autopep8 formatting

This commit is contained in:
Your Name 2024-12-18 21:45:33 +03:00
parent 6939c1d76c
commit f1c00107a9
5 changed files with 36 additions and 18 deletions

View file

@ -109,7 +109,8 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
u2url = r[0][1] u2url = r[0][1]
u1id = await get_id(u1url) u1id = await get_id(u1url)
u2id = await get_id(u2url) u2id = await get_id(u2url)
bio_excludes = [x[0] for x in c.execute('select user_id from avocado_exclude').fetchall()] bio_excludes = [x[0] for x in c.execute(
'select user_id from avocado_exclude').fetchall()]
# print(f'{u1url} [@{u1id}] подверг(ла) {u2url} [@{u2id}]')#показать # print(f'{u1url} [@{u1id}] подверг(ла) {u2url} [@{u2id}]')#показать
when = int(datetime.timestamp(m.date)) when = int(datetime.timestamp(m.date))
days = int(re.findall(bio_attack_themes[trying_theme_index][2], t)[ days = int(re.findall(bio_attack_themes[trying_theme_index][2], t)[
@ -214,10 +215,12 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
f"SELECT COUNT(*) FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchone()[0]) f"SELECT COUNT(*) FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchone()[0])
patients = list(c.execute( patients = list(c.execute(
f"SELECT * FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchall()) f"SELECT * FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchall())
bio_excludes = [x[0] for x in c.execute('select user_id from avocado_exclude').fetchall()] bio_excludes = [x[0] for x in c.execute(
'select user_id from avocado_exclude').fetchall()]
for p in patients: for p in patients:
if p[0] in bio_excludes: if p[0] in bio_excludes:
logger.warning(f'skipping patient {p[0]}, excluded from bioebinng') logger.warning(
f'skipping patient {p[0]}, excluded from bioebinng')
patients.remove(p) patients.remove(p)
return count, patients return count, patients
@ -258,7 +261,8 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
logger.debug( logger.debug(
f'latency avocado reply: {delta_avocado} secs') f'latency avocado reply: {delta_avocado} secs')
if delta_avocado > states.avocado_reply_timeout: if delta_avocado > states.avocado_reply_timeout:
interval_with_lag = rs + random.uniform(9.18299148, 40.9201412499) interval_with_lag = rs + \
random.uniform(9.18299148, 40.9201412499)
logger.debug( logger.debug(
f'bioeb sleep [increased, because avocado have lag]: {interval_with_lag}s') f'bioeb sleep [increased, because avocado have lag]: {interval_with_lag}s')
await asyncio.sleep(interval_with_lag) await asyncio.sleep(interval_with_lag)
@ -297,12 +301,14 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
t = reply.raw_text t = reply.raw_text
h = utils.sanitize_parse_mode( h = utils.sanitize_parse_mode(
'html').unparse(t, reply.entities) # HTML 'html').unparse(t, reply.entities) # HTML
r = re.findall(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">', h) r = re.findall(
r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">', h)
insertion_status = [] insertion_status = []
for link in r: for link in r:
user_id = await get_id(link) user_id = await get_id(link)
try: try:
c.execute("INSERT INTO avocado_exclude(user_id, reason) VALUES (?, ?)", (user_id, reason)) c.execute(
"INSERT INTO avocado_exclude(user_id, reason) VALUES (?, ?)", (user_id, reason))
insertion_status.append(f'{user_id}: ok') insertion_status.append(f'{user_id}: ok')
except: except:
insertion_status.append(f'{user_id}: exists') insertion_status.append(f'{user_id}: exists')
@ -324,7 +330,8 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
h = utils.sanitize_parse_mode( h = utils.sanitize_parse_mode(
'html').unparse(t, reply.entities) # HTML 'html').unparse(t, reply.entities) # HTML
r_as_list = [] r_as_list = []
r = re.findall(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">|(@\d+)', h) r = re.findall(
r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">|(@\d+)', h)
for x in r: for x in r:
r_as_list.extend(x) r_as_list.extend(x)
r = r_as_list r = r_as_list
@ -334,11 +341,13 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
return return
def filter_bioeb(victims_ids): def filter_bioeb(victims_ids):
bio_excludes = [x[0] for x in c.execute('SELECT user_id FROM avocado_exclude').fetchall()] bio_excludes = [x[0] for x in c.execute(
'SELECT user_id FROM avocado_exclude').fetchall()]
filted_victims = [] filted_victims = []
for v in victims_ids: for v in victims_ids:
if v in bio_excludes: if v in bio_excludes:
logger.warning(f'skipping patient {v}, excluded from bioebinng') logger.warning(
f'skipping patient {v}, excluded from bioebinng')
elif c.execute(f'SELECT user_id FROM avocado WHERE expr_int >= {when} and user_id == {v}').fetchone(): elif c.execute(f'SELECT user_id FROM avocado WHERE expr_int >= {when} and user_id == {v}').fetchone():
logger.warning(f'skipping patient {v}, already eaten') logger.warning(f'skipping patient {v}, already eaten')
else: else:

View file

@ -33,10 +33,12 @@ async def automine_avocado_task(client):
wait_before_mine = 1 wait_before_mine = 1
minutes = 0 minutes = 0
if states.latest_successfull_mine: if states.latest_successfull_mine:
wait_before_mine = (time.time() - states.latest_successfull_mine) + random.uniform(240 * 60, 242 * 60) wait_before_mine = (
time.time() - states.latest_successfull_mine) + random.uniform(240 * 60, 242 * 60)
minutes = wait_before_mine / 60 minutes = wait_before_mine / 60
elif states.wait_before_next_mine: elif states.wait_before_next_mine:
wait_before_mine = random.uniform(states.wait_before_next_mine, states.wait_before_next_mine + 3) wait_before_mine = random.uniform(
states.wait_before_next_mine, states.wait_before_next_mine + 3)
minutes = wait_before_mine / 60 minutes = wait_before_mine / 60
logger.debug(f'Waiting {minutes} minutes before mining of gems') logger.debug(f'Waiting {minutes} minutes before mining of gems')

View file

@ -13,16 +13,21 @@ async def git_notifications_update():
logger.info('Checking for updates...') logger.info('Checking for updates...')
fetching_git = os.system('git fetch') fetching_git = os.system('git fetch')
if fetching_git == 0: if fetching_git == 0:
commits = os.popen("git log --pretty=format:'%h %s%n%b' HEAD..origin/$(git rev-parse --abbrev-ref HEAD)").read() commits = os.popen(
"git log --pretty=format:'%h %s%n%b' HEAD..origin/$(git rev-parse --abbrev-ref HEAD)").read()
if len(commits) <= 5: if len(commits) <= 5:
logger.info('updates not found, nothing to do') logger.info('updates not found, nothing to do')
else: else:
os.system(f"termux-notification --title 'ub4tg: update avalaible!' --content 'For apply tap button Get update and restart bot\nChanges:\n{commits}' --button1 'Get update' --button1-action 'cd {cwd}; git pull'") os.system(
f"termux-notification --title 'ub4tg: update avalaible!' --content 'For apply tap button Get update and restart bot\nChanges:\n{commits}' --button1 'Get update' --button1-action 'cd {cwd}; git pull'")
else: else:
os.system("termux-toast '[ub4tg]: failed fetching update, maybe connection error, check console log for more info'") os.system(
"termux-toast '[ub4tg]: failed fetching update, maybe connection error, check console log for more info'")
else: else:
logger.warning('For getting updates via notifications, you should:') logger.warning(
'For getting updates via notifications, you should:')
logger.warning('pkg install termux-api') logger.warning('pkg install termux-api')
logger.warning('download the apk: https://f-droid.org/repo/com.termux.api_51.apk') logger.warning(
'download the apk: https://f-droid.org/repo/com.termux.api_51.apk')
logger.debug('next update will be check after 6 hours') logger.debug('next update will be check after 6 hours')
await asyncio.sleep(6 * 60 * 60) await asyncio.sleep(6 * 60 * 60)

View file

@ -95,7 +95,8 @@ async def bio_backup_stealing(client, c, conn, default_directory):
logger.success('backup success stealed') logger.success('backup success stealed')
if cmd == 'me': if cmd == 'me':
my_victims_ids = tuple(my_victims_ids) my_victims_ids = tuple(my_victims_ids)
result = c.execute(f'UPDATE avocado SET expr_int = 0 WHERE user_id NOT IN {my_victims_ids}').fetchall() result = c.execute(
f'UPDATE avocado SET expr_int = 0 WHERE user_id NOT IN {my_victims_ids}').fetchall()
conn.commit() conn.commit()
logger.success('database rebased') logger.success('database rebased')
del my_victims_ids del my_victims_ids

View file

@ -83,7 +83,8 @@ async def main():
if is_termux: if is_termux:
conn = sqlite3.connect(f"{default_directory}/{my_id}.sqlite") conn = sqlite3.connect(f"{default_directory}/{my_id}.sqlite")
else: else:
conn = sqlite3.connect(f"{my_id}.sqlite") # покласти базу рядом # покласти базу рядом
conn = sqlite3.connect(f"{my_id}.sqlite")
c = conn.cursor() c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS avocado ( c.execute('''CREATE TABLE IF NOT EXISTS avocado (
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE, user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,