From 0cca756b94372bdef7fe7f44a466084f11288605 Mon Sep 17 00:00:00 2001 From: def Date: Mon, 12 Sep 2022 08:58:43 +0200 Subject: [PATCH] update --- bash/kill_switch_off.sh | 7 +++ bash/kill_switch_on.sh | 8 +++ other/bot-for-navalnycom.py | 106 ++++++++++++++++++++++++++++++++++++ other/count-tests.py | 23 ++++++++ other/main.py | 29 ++++++++++ 5 files changed, 173 insertions(+) create mode 100644 bash/kill_switch_off.sh create mode 100644 bash/kill_switch_on.sh create mode 100644 other/bot-for-navalnycom.py create mode 100644 other/count-tests.py create mode 100644 other/main.py diff --git a/bash/kill_switch_off.sh b/bash/kill_switch_off.sh new file mode 100644 index 0000000..896d620 --- /dev/null +++ b/bash/kill_switch_off.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "y" | sudo ufw enable +sudo ufw default deny incoming +sudo ufw default allow outgoing +sudo ufw enable +notify-send 'Kill-switch OFF' 'Maybe, maybe not, or maybe fuck off' --icon=dialog-information diff --git a/bash/kill_switch_on.sh b/bash/kill_switch_on.sh new file mode 100644 index 0000000..7758ec0 --- /dev/null +++ b/bash/kill_switch_on.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "y" | sudo ufw enable +sudo ufw default deny incoming +sudo ufw default deny outgoing +sudo ufw allow out on tun0 from any to any +sudo ufw enable +notify-send 'Kill-switch ON' 'Maybe, maybe not, or maybe fuck off' --icon=dialog-information diff --git a/other/bot-for-navalnycom.py b/other/bot-for-navalnycom.py new file mode 100644 index 0000000..2cd272d --- /dev/null +++ b/other/bot-for-navalnycom.py @@ -0,0 +1,106 @@ +from aiohttp import ClientSession +from logging import basicConfig, DEBUG + +from aiogram import executor +from aiogram import Bot, Dispatcher +from aiogram.types import ParseMode +from aiogram.types import Message, CallbackQuery +from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from aiogram.dispatcher.filters import CommandStart + + +API_URL = "https://free.navalny.com/api/v1/maps/counters/" + +BOT_TOKEN = "token" +BOT_OWNER = [id] + +bot = Bot(token=BOT_TOKEN, parse_mode=ParseMode.HTML) +dp = Dispatcher(bot) + + +async def on_startup_notify(dp: Dispatcher): + for i in BOT_OWNER: + await bot.send_message(i, "started.") + + +def create_session(): + """ + Создание новой сессии + """ + return ClientSession( + headers={ + "User-Agent": "bot" + } + ) + + + +async def get_count(): + + session = create_session() + + response = await session.get(API_URL) + query = await response.json() + await session.close() + + return int(query["persons"]) + + +def get_keyboard(): + + markup = InlineKeyboardMarkup() + + markup.add( + InlineKeyboardButton( + text="Обновить", callback_data="update_info" + ) + ) + + return markup + + + +@dp.message_handler(CommandStart()) +async def check_count_of_members(message: Message): + + count = await get_count() + + await message.reply( + text=( + f"Количество участников акции: {count}" + ), + reply_markup=get_keyboard() + ) + + + +@dp.callback_query_handler(text="update_info") +async def update_info(call: CallbackQuery): + + message = call.message + + new_count = await get_count() + old_count = int(message.text.split()[3]) + + if old_count == new_count: + return await call.answer( + text=( + "Количество участников не изменилось" + ), + show_alert=True + ) + + await message.edit_text( + text=( + f"Количество участников акции: {new_count}" + f"\nСтало больше на: {new_count - old_count}" + ), + reply_markup=get_keyboard() + ) + + await call.answer() + + + +if __name__ == "__main__": + executor.start_polling(dp, on_startup=on_startup_notify) diff --git a/other/count-tests.py b/other/count-tests.py new file mode 100644 index 0000000..45f9b91 --- /dev/null +++ b/other/count-tests.py @@ -0,0 +1,23 @@ +##################################### Первый способ: + +A = [10, 10, 23, 10, 123, 66, 78, 123] +counter = {} + +for elem in A: + counter[elem] = counter.get(elem, 0) + 1 + +doubles = {element: count for element, count in counter.items() if count > 1} + +print(doubles) + +##################################### Второй способ: + +from collections import Counter +counter = Counter(A) + +##################################### Третий способ: + +from collections import defaultdict +counter = defaultdict(int) +for elem in A: + counter[elem] += 1 diff --git a/other/main.py b/other/main.py new file mode 100644 index 0000000..f6119b0 --- /dev/null +++ b/other/main.py @@ -0,0 +1,29 @@ +unique = [] +text = "Вышел зайчик зайчик на крыльцо на крыльцо" + + +words = text.split(' ') # старый +newords = [] # + + + +count = 0 +print('\nStart words list:\n', words, '\n') + + +for w in words: + if w in unique and len(w) > 4: + count += 1 + #print(f'Слово {w} повторяется, позиция:', words.index(w)) + ind = words.index(w) + print(f'Clone: {w} / index:', ind) + #newords.insert(ind, count) + newords.append(count) + + + + else: + unique.append(w) + newords.append(w) + +print('\nNew words list:\n', newords, '\n')