├── README.md ├── Simple datediff calculator ├── Study TG Bot for Merrion ├── TGBot_v2.py ├── Weather checker ├── fibo on python ├── jokes.py ├── messages.py ├── my_filters.py └── polindrom checker on C /README.md: -------------------------------------------------------------------------------- 1 | # simple-code -------------------------------------------------------------------------------- /Simple datediff calculator: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | # input of calculated dates 4 | f_date_input = input("input first date in format (YYYY-MM-DD-HH-mm-ss): ") 5 | f_date = datetime.datetime(*map(int, f_date_input.split('-'))) 6 | 7 | e_date_input = input("input last date in format (YYYY-MM-DD-HH-mm-ss): ") 8 | e_date = datetime.datetime(*map(int, e_date_input.split('-'))) 9 | 10 | gap_l = e_date - f_date 11 | print('Difference: ', gap_l) 12 | 13 | h = divmod(gap_l.total_seconds(), 3600)[0] 14 | print('Difference in hours: ', h) 15 | -------------------------------------------------------------------------------- /Study TG Bot for Merrion: -------------------------------------------------------------------------------- 1 | import random 2 | from io import StringIO 3 | 4 | from telebot import TeleBot, types 5 | 6 | import config #token and photo url are kept here 7 | import jokes #list of jokes 8 | import messages #list of text for replies 9 | 10 | token = config.bot_token 11 | bot = TeleBot(token) 12 | 13 | #reply to /start 14 | @bot.message_handler(commands=['start']) 15 | def reply_to_start(message: types.Message): 16 | bot.send_message( 17 | message.chat.id, 18 | messages.welcome 19 | ) 20 | 21 | #reply to /help 22 | @bot.message_handler(commands=['help']) 23 | def reply_to_help(message: types.Message): 24 | bot.send_message( 25 | message.chat.id, 26 | messages.help_menu 27 | ) 28 | 29 | #reply to /joke 30 | @bot.message_handler(commands=['joke']) 31 | def send_joke(message: types.Message): 32 | bot.send_message( 33 | message.chat.id, 34 | random.choice(jokes.jl) 35 | ) 36 | 37 | #reply to /dogs 38 | @bot.message_handler(commands=['dogs']) 39 | def send_dogs(message: types.Message): 40 | bot.send_photo( 41 | message.chat.id, 42 | config.photo_url, 43 | 'Here is a power dog to you!', 44 | reply_to_message_id=message.id 45 | ) 46 | 47 | #reply to sticker 48 | @bot.message_handler(content_types=['sticker']) 49 | def reply_to_sticker(message: types.Message): 50 | bot.send_message( 51 | message.chat.id, 52 | 'Шикарный стикер пак!!!', 53 | reply_to_message_id=message.id 54 | ) 55 | 56 | #reply to gif 57 | @bot.message_handler(content_types=['animation']) 58 | def reply_to_gif(message: types.Message): 59 | bot.send_message( 60 | message.chat.id, 61 | 'Обожаю гифки!', 62 | reply_to_message_id=message.id 63 | ) 64 | 65 | 66 | #checker for 'cat' in caption to the photo 67 | def cats_in_caption_check(message: types.Message): 68 | return message.caption and 'кот' in message.caption.lower() 69 | 70 | #reply to a photo of a cat 71 | @bot.message_handler(content_types=['photo'], func=cats_in_caption_check) 72 | def send_reply_to_cats(message: types.Message): 73 | if cats_in_caption_check: 74 | bot.send_message( 75 | message.chat.id, 76 | 'Шикарный котик!', 77 | reply_to_message_id=message.message_id 78 | ) 79 | else: 80 | photo_file_id = message.photo[-1].file_id 81 | bot.send_photo( 82 | message.chat.id, 83 | photo_file_id, 84 | reply_to_message_id=message.message_id 85 | ) 86 | 87 | #reply to any photo 88 | @bot.message_handler(content_types=['photo']) 89 | def send_photo_reply(message: types.Message): 90 | photo_file_id = message.photo[-1].file_id 91 | bot.send_photo( 92 | message.chat.id, 93 | photo_file_id, 94 | reply_to_message_id=message.message_id 95 | ) 96 | 97 | #RANDOM NUMBER GENERATOR AS TXT FILE 98 | @bot.message_handler(commands=['gen_txt']) 99 | def send_generated_txt(message: types.Message): 100 | file = StringIO() 101 | file.write("Your random number: ") 102 | file.write(str(random.randint(a=1, b=100))) 103 | file.seek(0) 104 | gen = types.InputFile(file) 105 | bot.send_document( 106 | message.chat.id, 107 | document=gen, 108 | visible_file_name="Your random number.txt" 109 | ) 110 | 111 | #reply to text msg 112 | @bot.message_handler() 113 | def echo_meaasge(message: types.Message): 114 | text = message.text 115 | text_lower = text.lower() 116 | if 'привет' in text_lower: 117 | bot.send_message( 118 | message.chat.id, 119 | messages.privet 120 | ) 121 | elif 'как дела' in text_lower: 122 | bot.send_message( 123 | message.chat.id, 124 | messages.how 125 | ) 126 | elif 'пока' in text_lower or 'до свидания' in text_lower: 127 | bot.send_message( 128 | message.chat.id, 129 | messages.bb 130 | ) 131 | bot.send_message(message.chat.id, text) 132 | 133 | #this keeps your bot alive till u shut it down 134 | bot.infinity_polling(skip_pending=True) 135 | -------------------------------------------------------------------------------- /TGBot_v2.py: -------------------------------------------------------------------------------- 1 | import random 2 | from io import StringIO 3 | 4 | from telebot import TeleBot, types, formatting 5 | from telebot import custom_filters 6 | 7 | import config 8 | import jokes 9 | import messages 10 | import my_filters 11 | 12 | token = config.bot_token 13 | bot = TeleBot(token) 14 | bot.add_custom_filter(custom_filters.TextMatchFilter()) 15 | # bot.add_custom_filter(custom_filters.TextContainsFilter()) 16 | bot.add_custom_filter(custom_filters.ForwardFilter()) 17 | bot.add_custom_filter(custom_filters.IsReplyFilter()) 18 | bot.add_custom_filter(my_filters.IsBotAdmin()) 19 | bot.add_custom_filter(my_filters.ContainWord()) 20 | 21 | 22 | @bot.message_handler(commands=['start']) 23 | def reply_to_start(message: types.Message): 24 | bot.send_message( 25 | message.chat.id, 26 | messages.welcome 27 | ) 28 | 29 | 30 | @bot.message_handler(commands=['help']) 31 | def reply_to_help(message: types.Message): 32 | bot.send_message( 33 | message.chat.id, 34 | messages.help_menu 35 | ) 36 | 37 | 38 | @bot.message_handler(commands=['joke']) 39 | def send_joke(message: types.Message): 40 | bot.send_message( 41 | message.chat.id, 42 | formatting.hcite(jokes.get_rand_joke_text()), 43 | parse_mode='HTML' 44 | ) 45 | 46 | 47 | @bot.message_handler(commands=['joke2']) 48 | def send_two_part_joke(message: types.Message): 49 | setup, delivery = jokes.get_two_part_joke() 50 | j_text = formatting.format_text( 51 | formatting.escape_html(setup), 52 | formatting.hspoiler(delivery) 53 | ) 54 | bot.send_message( 55 | message.chat.id, 56 | j_text, 57 | parse_mode='HTML' 58 | ) 59 | 60 | 61 | @bot.message_handler(commands=['dogs']) 62 | def send_dogs(message: types.Message): 63 | bot.send_photo( 64 | message.chat.id, 65 | config.photo_url, 66 | 'Here is a power dog to you!', 67 | reply_to_message_id=message.id 68 | ) 69 | 70 | 71 | @bot.message_handler(commands=['spaceman']) 72 | def send_spaceman(message: types.Message): 73 | bot.send_photo( 74 | message.chat.id, 75 | config.spaceman_pic_url 76 | ) 77 | 78 | 79 | @bot.message_handler(commands=['spaceman_file']) 80 | def send_spaceman_file(message: types.Message): 81 | photo_file = types.InputFile(config.spaceman_pic_file) 82 | bot.send_document( 83 | message.chat.id, 84 | photo_file 85 | ) 86 | 87 | 88 | @bot.message_handler(commands=['me']) 89 | def send_my_info(message: types.Message): 90 | data = StringIO() 91 | data.write(f'Ваше username:{message.from_user.username}\n') 92 | data.write(f'Ваше полное имя: {message.from_user.full_name}\n') 93 | data.write(f'Ваш ID: {message.from_user.id}\n') 94 | data.seek(0) 95 | bot.send_document( 96 | message.chat.id, 97 | types.InputFile(data), 98 | visible_file_name='your-info.txt', 99 | caption=messages.your_info 100 | 101 | ) 102 | 103 | 104 | @bot.message_handler(commands=['chat_id']) 105 | def show_chat_id(message: types.Message): 106 | bot.send_message( 107 | message.chat.id, 108 | f"{message.chat.id}" 109 | ) 110 | 111 | 112 | @bot.message_handler(commands=['secret'], is_bot_admin=True) 113 | def tell_a_secret(message: types.Message): 114 | bot.send_message( 115 | message.chat.id, 116 | text=messages.admin_msg 117 | ) 118 | 119 | 120 | @bot.message_handler(commands=['secret'], is_bot_admin=False) 121 | def keep_this_secret(message: types.Message): 122 | bot.send_message( 123 | message.chat.id, 124 | text=messages.not_admin_msg 125 | ) 126 | 127 | 128 | @bot.message_handler(content_types=['sticker']) 129 | def reply_to_sticker(message: types.Message): 130 | bot.send_message( 131 | message.chat.id, 132 | 'Шикарный стикер пак!!!', 133 | reply_to_message_id=message.id 134 | ) 135 | 136 | 137 | @bot.message_handler(content_types=['animation']) 138 | def reply_to_gif(message: types.Message): 139 | bot.send_message( 140 | message.chat.id, 141 | 'Обожаю гифки!', 142 | reply_to_message_id=message.id 143 | ) 144 | 145 | 146 | def cats_in_caption_check(message: types.Message): 147 | return message.caption and 'кот' in message.caption.lower() 148 | 149 | 150 | @bot.message_handler(contain_word="кот") 151 | def no_cats_allowed(message: types.Message): 152 | bot.send_message( 153 | message.chat.id, 154 | "NO CATS ALLOWED!" 155 | ) 156 | 157 | 158 | @bot.message_handler(content_types=['photo'], func=cats_in_caption_check) 159 | def send_reply_to_cats(message: types.Message): 160 | if cats_in_caption_check: 161 | bot.send_message( 162 | message.chat.id, 163 | 'Шикарный котик!', 164 | reply_to_message_id=message.message_id 165 | ) 166 | else: 167 | photo_file_id = message.photo[-1].file_id 168 | bot.send_photo( 169 | message.chat.id, 170 | photo_file_id, 171 | reply_to_message_id=message.message_id 172 | ) 173 | 174 | 175 | @bot.message_handler(content_types=['photo']) 176 | def send_photo_reply(message: types.Message): 177 | photo_file_id = message.photo[-1].file_id 178 | if message.caption: 179 | bot.send_photo( 180 | message.chat.id, 181 | photo_file_id, 182 | caption='Крутое фото!', 183 | reply_to_message_id=message.message_id 184 | ) 185 | else: 186 | bot.send_photo( 187 | message.chat.id, 188 | photo_file_id, 189 | reply_to_message_id=message.message_id 190 | ) 191 | 192 | 193 | @bot.message_handler(commands=['photofile']) 194 | def send_photo_file(message: types.Message): 195 | photo_file = types.InputFile('pics/simple ghost eating ice cream doodle png white bac.webp') 196 | bot.send_photo( 197 | message.chat.id, 198 | photo_file 199 | ) 200 | 201 | 202 | @bot.message_handler(commands=['doc']) 203 | def send_doc(message: types.Message): 204 | photo_file = types.InputFile('pics/msg379668733-113514.jpg') 205 | bot.send_document( 206 | message.chat.id, 207 | photo_file 208 | ) 209 | 210 | 211 | @bot.message_handler(commands=['document']) 212 | def send_document(message: types.Message): 213 | bot.send_document( 214 | message.chat.id, 215 | document=types.InputFile('text.txt') 216 | ) 217 | 218 | 219 | @bot.message_handler(commands=['gen_txt'], is_forwarded=True) 220 | def no_forward(message: types.Message): 221 | bot.send_message( 222 | message.chat.id, 223 | messages.dont_forward_commands, 224 | ) 225 | 226 | 227 | @bot.message_handler(commands=['gen_txt']) 228 | def send_generated_txt(message: types.Message): 229 | file = StringIO() 230 | file.write("Your random number: ") 231 | file.write(str(random.randint(a=1, b=100))) 232 | file.seek(0) 233 | gen = types.InputFile(file) 234 | bot.send_document( 235 | message.chat.id, 236 | document=gen, 237 | visible_file_name="Your random number.txt" 238 | ) 239 | 240 | 241 | def is_hi(message: types.Message): 242 | return message.text and "привет" in message.text.lower() 243 | 244 | 245 | @bot.message_handler(text=custom_filters.TextFilter( 246 | contains=["погода"], ignore_case=True)) 247 | def weather(message: types.Message): 248 | bot.send_message( 249 | message.chat.id, 250 | 'Nice weather' 251 | ) 252 | 253 | 254 | @bot.message_handler(func=is_hi) 255 | def reply_to_hi(message: types.Message): 256 | bot.send_message( 257 | message.chat.id, 258 | 'Greetings!' 259 | ) 260 | 261 | 262 | @bot.message_handler(is_reply=True) 263 | def reply(message: types.Message): 264 | msg_type = message.reply_to_message.content_type 265 | if msg_type in config.content_types: 266 | msg_type = config.content_types[msg_type] 267 | bot.send_message( 268 | message.chat.id, 269 | f'You replied to {msg_type}', 270 | reply_to_message_id=message.reply_to_message.message_id 271 | ) 272 | 273 | 274 | @bot.message_handler() 275 | def copy_message(message: types.Message): 276 | bot.copy_message( 277 | chat_id=message.chat.id, 278 | from_chat_id=message.chat.id, 279 | message_id=message.id 280 | ) 281 | 282 | 283 | @bot.message_handler() 284 | def echo_message(message: types.Message): 285 | text = message.text 286 | text_lower = text.lower() 287 | if 'как дела' in text_lower: 288 | bot.send_message( 289 | message.chat.id, 290 | messages.how 291 | ) 292 | elif 'пока' in text_lower or 'до свидания' in text_lower: 293 | bot.send_message( 294 | message.chat.id, 295 | messages.bb 296 | ) 297 | else: 298 | bot.send_message(message.chat.id, text) 299 | 300 | 301 | if __name__ == '__main__': 302 | bot.infinity_polling(skip_pending=True) 303 | -------------------------------------------------------------------------------- /Weather checker: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | def get_weather(city_name, api_key): 4 | base_url = "http://api.openweathermap.org/data/2.5/weather?" 5 | complete_url = base_url + "q=" + city_name + "&appid=" + api_key + "&units=metric" 6 | response = requests.get(complete_url) 7 | 8 | if response.status_code == 200: 9 | data = response.json() 10 | main = data['main'] 11 | weather = data['weather'][0] 12 | 13 | temperature = main['temp'] 14 | pressure = main['pressure'] 15 | humidity = main['humidity'] 16 | weather_description = weather['description'] 17 | 18 | print(f"Температура: {temperature}°C") 19 | print(f"Атмосферное давление: {pressure} hPa") 20 | print(f"Влажность: {humidity}%") 21 | print(f"Описание: {weather_description}") 22 | else: 23 | print("Город не найден. Пожалуйста, проверьте правильность написания.") 24 | 25 | if __name__ == "__main__": 26 | city_name = input("Введите название города: ") 27 | api_key = "ВАШ_API_КЛЮЧ" 28 | get_weather(city_name, api_key) 29 | -------------------------------------------------------------------------------- /fibo on python: -------------------------------------------------------------------------------- 1 | def main(): 2 | n = 152124 3 | # n = int(input("Введите число: ")) 4 | print(n % 10000) 5 | 6 | if __name__ == "__main__": 7 | main() 8 | -------------------------------------------------------------------------------- /jokes.py: -------------------------------------------------------------------------------- 1 | joke_base_url = 'https://v2.jokeapi.dev/joke/Programming,Pun?' 2 | 3 | 4 | def get_joke(joke_type: str | None = None): 5 | params = {} 6 | if joke_type: 7 | params["type"] = joke_type 8 | response = requests.get(joke_base_url, params) 9 | if response.status_code != 200: 10 | return 11 | js_data = response.json() 12 | if js_data.get("error"): 13 | return 14 | return js_data 15 | 16 | def get_rand_joke_text(): 17 | js_data = get_joke("single") 18 | if not js_data: 19 | return "Error" 20 | return js_data["joke"] 21 | 22 | 23 | def get_two_part_joke(): 24 | js_data = get_joke("twopart") 25 | if not js_data: 26 | return "Error" 27 | 28 | return js_data["setup"], js_data["delivery"] 29 | -------------------------------------------------------------------------------- /messages.py: -------------------------------------------------------------------------------- 1 | welcome = ('Приветствую тебя!' 2 | 'Выбери команду и мы начнём...') 3 | 4 | help_menu = """ 5 | Вот что умеет этот бот: 6 | /start - Начать общение 7 | /help - вызвать меню 8 | /joke - рассказать шутку 9 | 10 | В остальных случаях бот будет повторять за вами 11 | """ 12 | 13 | privet = 'И тебе привет!' 14 | how = 'Хорошо! А у вас как?' 15 | bb = 'До новых встреч!' 16 | 17 | dont_forward_commands = "Pls, dont forward commands" 18 | replier = "Повторюша!" 19 | 20 | your_info = "Вот информация о вас!" 21 | 22 | admin_msg = "Вам доступны тайные знания!" 23 | not_admin_msg = "Вы не готовы!" -------------------------------------------------------------------------------- /my_filters.py: -------------------------------------------------------------------------------- 1 | from telebot.types import Message 2 | from telebot.custom_filters import (SimpleCustomFilter, AdvancedCustomFilter) 3 | import config 4 | 5 | 6 | class IsBotAdmin(SimpleCustomFilter): 7 | key = "is_bot_admin" 8 | 9 | def check(self, message: Message): 10 | return message.from_user.id in config.chat_admin 11 | 12 | 13 | class ContainWord(AdvancedCustomFilter): 14 | key = "contain_word" 15 | 16 | def check(self, message: Message, word: str): 17 | text = message.text or message.caption 18 | if not text: 19 | return False 20 | 21 | return word in text.lower() 22 | -------------------------------------------------------------------------------- /polindrom checker on C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char str1[500]; 5 | char str2[500]; 6 | scanf("%s", str1); 7 | int length; 8 | int count = 0; 9 | int flag = 0; 10 | while (str1[length] != '\0') { 11 | length++; 12 | } 13 | int l = length - 1; 14 | for (int i = l; 0 < i; i--) { 15 | str2[count] = str1[i]; 16 | count++; 17 | } 18 | for (int i = 0; i < l; i++) { 19 | if(str1[i] != str2[i]) 20 | { 21 | flag = 1; 22 | } 23 | } 24 | if (flag == 0) { 25 | printf("polindrom"); 26 | } else { 27 | printf("net"); 28 | } 29 | return 0; 30 | } 31 | --------------------------------------------------------------------------------