This commit is contained in:
@@ -1,44 +1,40 @@
|
||||
|
||||
from global_conf import CONFIG
|
||||
|
||||
#### https://docs.python-arango.com/en/main/
|
||||
from arango import ArangoClient
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
def get_dicks_collection():
|
||||
def get_dicks_collection():
|
||||
try:
|
||||
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'] )
|
||||
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'] )
|
||||
pipisa_db = arango_client.db(
|
||||
CONFIG['databaso']['base'],
|
||||
CONFIG['databaso']['base'],
|
||||
username=os.environ['ARANGO_USR'],
|
||||
password=os.environ['ARANGO_PWD'],
|
||||
#username=CONFIG['databaso']['user'],
|
||||
#password=CONFIG['databaso']['pass']
|
||||
)
|
||||
dicks_collection = pipisa_db.collection(CONFIG['databaso']['collection'])
|
||||
)
|
||||
dicks_collection = pipisa_db.collection(CONFIG['databaso']['collection'])
|
||||
|
||||
return dicks_collection
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB при взятии коллекции пипис')
|
||||
logging.error(e)
|
||||
logging.error(e)
|
||||
|
||||
|
||||
def get_posts_removal_collection():
|
||||
def get_posts_removal_collection():
|
||||
try:
|
||||
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'] )
|
||||
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'])
|
||||
pipisa_db = arango_client.db(
|
||||
CONFIG['databaso']['base'],
|
||||
CONFIG['databaso']['base'],
|
||||
username=os.environ['ARANGO_USR'],
|
||||
password=os.environ['ARANGO_PWD'],
|
||||
#username=CONFIG['databaso']['user'],
|
||||
#password=CONFIG['databaso']['pass']
|
||||
)
|
||||
posts_removal_collection = pipisa_db.collection(CONFIG['databaso']['posts_removal_collection'])
|
||||
)
|
||||
posts_removal_collection = pipisa_db.collection(CONFIG['databaso']['posts_removal_collection'])
|
||||
|
||||
return posts_removal_collection
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB при взятии коллекции постов-на-удаление')
|
||||
logging.error(e)
|
||||
|
||||
@@ -2,22 +2,20 @@ from db_logic import collections
|
||||
import datetime, logging
|
||||
|
||||
|
||||
|
||||
def append_post_to_cleaning_sequence(message, type=None):
|
||||
try:
|
||||
novenkiy = {
|
||||
'msg_id': message.message_id,
|
||||
'chat_id': message.chat.id,
|
||||
'type': type,
|
||||
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
'msg_id': message.message_id,
|
||||
'chat_id': message.chat.id,
|
||||
'type': type,
|
||||
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
}
|
||||
metadata = collections.get_posts_removal_collection().insert(novenkiy, overwrite_mode='update')
|
||||
|
||||
logging.debug('Успешно добавлен пост на удаление')
|
||||
except Exception as e2:
|
||||
logging.error('ошибка DB :: добавление нового поста на удаление')
|
||||
logging.error(e2)
|
||||
|
||||
logging.error(e2)
|
||||
|
||||
def get_posts_to_be_removed(chat_id, type=None, max_id=None):
|
||||
# собираем
|
||||
@@ -29,10 +27,10 @@ def get_posts_to_be_removed(chat_id, type=None, max_id=None):
|
||||
else:
|
||||
posts = [p for p in collections.get_posts_removal_collection().find({'chat_id': chat_id}, skip=0, limit=1100) ]
|
||||
|
||||
posts_ret = [ p for p in posts ]
|
||||
# # for p in posts:
|
||||
# # last_time = datetime.datetime.strptime(p['datetimes'], '%Y-%m-%d %H:%M:%S')
|
||||
# # timediff = (datetime.datetime.now() - last_time).total_seconds()
|
||||
posts_ret = [ p for p in posts ]
|
||||
# # for p in posts:
|
||||
# # last_time = datetime.datetime.strptime(p['datetimes'], '%Y-%m-%d %H:%M:%S')
|
||||
# # timediff = (datetime.datetime.now() - last_time).total_seconds()
|
||||
|
||||
# # if timediff > 60:
|
||||
# # posts_ret.append(p)
|
||||
@@ -42,34 +40,31 @@ def get_posts_to_be_removed(chat_id, type=None, max_id=None):
|
||||
else:
|
||||
posts_ret = [ p for p in posts_ret if p['msg_id'] != max([pp['msg_id'] for pp in posts_ret])]
|
||||
|
||||
|
||||
#### TODO удалять все предыдущие без учёта времени
|
||||
|
||||
return posts_ret
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB :: получение постов на удаление')
|
||||
logging.error(e)
|
||||
|
||||
|
||||
def del_post(msg_id, chat_id):
|
||||
# удаляем из базы
|
||||
try:
|
||||
|
||||
try:
|
||||
candidate_cursor = collections.get_posts_removal_collection().find(
|
||||
{
|
||||
'msg_id': msg_id,
|
||||
'chat_id': chat_id,
|
||||
},
|
||||
skip = 0,
|
||||
skip = 0,
|
||||
limit = 1488
|
||||
)
|
||||
if candidate_cursor.count() > 0:
|
||||
if candidate_cursor.count() > 0:
|
||||
pp = candidate_cursor.pop()
|
||||
else:
|
||||
pp = None
|
||||
|
||||
collections.get_posts_removal_collection().delete(pp)
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB :: удаление поста на удаление')
|
||||
logging.error(e)
|
||||
logging.error(e)
|
||||
|
||||
@@ -4,36 +4,34 @@ import logging
|
||||
|
||||
|
||||
def get_tops(top_ = False, glob_ = False, chat_id = None):
|
||||
|
||||
if top_:
|
||||
if top_:
|
||||
try:
|
||||
dicks = [d for d in collections.get_dicks_collection().find({'chat_id': chat_id}, skip=0, limit=1100)]
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB в /topdick')
|
||||
logging.error(e)
|
||||
elif glob_:
|
||||
logging.error(e)
|
||||
elif glob_:
|
||||
try:
|
||||
dicks = [d for d in collections.get_dicks_collection().all( ) if d['user_id'] != d['chat_id']]
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB в /globaldick')
|
||||
logging.error(e)
|
||||
else:
|
||||
logging.error('вызывают хз что!')
|
||||
logging.error('вызывают хз что!')
|
||||
|
||||
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
|
||||
top_dicks = top_dicks[:( min(len(top_dicks), 10) )]
|
||||
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
|
||||
top_dicks = top_dicks[:(min(len(top_dicks), 10))]
|
||||
|
||||
dickos = ''
|
||||
emo = ['🏆','🚀','🍆','🍌','🐍','🐎','🌭','🌶','👌','💩']
|
||||
|
||||
if len(top_dicks) > 0:
|
||||
for i in range(len(top_dicks)):
|
||||
for i in range(len(top_dicks)):
|
||||
dickos += f' {emo[i]} {i+1}. {top_dicks[i]["user_fullname"]}: {top_dicks[i]["dick_size"]}см\n'
|
||||
i += 1
|
||||
|
||||
return dickos
|
||||
|
||||
|
||||
def get_antitops(top_ = False, glob_ = False, chat_id = None):
|
||||
dicks = []
|
||||
if top_:
|
||||
@@ -62,4 +60,4 @@ def get_antitops(top_ = False, glob_ = False, chat_id = None):
|
||||
dickos += f' {emo[i]} {i+1}. {antitop_dicks[i]["user_fullname"]}: {antitop_dicks[i]["dick_size"]}см\n'
|
||||
i += 1
|
||||
|
||||
return dickos
|
||||
return dickos
|
||||
|
||||
@@ -4,7 +4,6 @@ import datetime, logging
|
||||
|
||||
|
||||
def store_new_user(message, result ):
|
||||
|
||||
try:
|
||||
novenkiy = {
|
||||
'user_id': message.from_user.id,
|
||||
@@ -17,12 +16,11 @@ def store_new_user(message, result ):
|
||||
metadata = collections.get_dicks_collection().insert(novenkiy, overwrite_mode='update')
|
||||
|
||||
metric_wrap(message.chat.id, message.from_user.full_name, abs(result), 1)
|
||||
logging.debug(f'Успешно добавлен нового пользователь @{message.from_user.username}')
|
||||
logging.debug(f'Успешно добавлен нового пользователь @{message.from_user.username}')
|
||||
except Exception as e2:
|
||||
logging.error(f'ошибка DB в /dick :: добавление нового пользователя @{message.from_user.username}')
|
||||
logging.error(e2)
|
||||
|
||||
|
||||
def update_attempts(message, user ):
|
||||
try:
|
||||
metadata = collections.get_dicks_collection().insert(
|
||||
@@ -39,14 +37,12 @@ def update_attempts(message, user ):
|
||||
)
|
||||
|
||||
metric_wrap(message.chat.id, message.from_user.full_name, user['dick_size'], user['attempts'] + 1)
|
||||
logging.debug(f'Успешно апдейтнули попытку крутить пипису @{message.from_user.username}')
|
||||
logging.debug(f'Успешно апдейтнули попытку крутить пипису @{message.from_user.username}')
|
||||
except Exception as e2:
|
||||
logging.error(f'ошибка DB в /dick :: обновление попытки крутить пипису @{message.from_user.username}')
|
||||
logging.error(e2)
|
||||
|
||||
|
||||
def update_dick_size(message, user, updatedDick ):
|
||||
|
||||
try:
|
||||
metadata = collections.get_dicks_collection().insert(
|
||||
{
|
||||
@@ -62,12 +58,11 @@ def update_dick_size(message, user, updatedDick ):
|
||||
)
|
||||
|
||||
metric_wrap(message.chat.id, message.from_user.full_name, updatedDick, user['attempts'] + 1)
|
||||
logging.info(f'Успешно апдейтнули пипису @{message.from_user.username}')
|
||||
logging.info(f'Успешно апдейтнули пипису @{message.from_user.username}')
|
||||
except Exception as e2:
|
||||
logging.error(f'ошибка DB в /dick :: обновление пиписы @{message.from_user.username}')
|
||||
logging.error(e2)
|
||||
|
||||
|
||||
def get_user(message):
|
||||
try:
|
||||
#### Чекнуть есть ли юзер в базе
|
||||
@@ -76,15 +71,15 @@ def get_user(message):
|
||||
'user_id': message.from_user.id,
|
||||
'chat_id': message.chat.id
|
||||
},
|
||||
skip = 0,
|
||||
skip = 0,
|
||||
limit = 1488
|
||||
)
|
||||
if candidate_cursor.count() > 0:
|
||||
if candidate_cursor.count() > 0:
|
||||
user = candidate_cursor.pop()
|
||||
else:
|
||||
user = None
|
||||
|
||||
return user
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
logging.error('ошибка DB в /dick :: поиск юзера')
|
||||
logging.error(e)
|
||||
logging.error(e)
|
||||
|
||||
Reference in New Issue
Block a user