rcon.execute("echo Hello, world!")
import telebot
from requests import get
bot = telebot.TeleBot("TOKEN")
@bot.message_handler(commands=["start"])
def start(message):
bot.send_message(message.chat.id, "ТЕСТ")
bot.send_photo(message.chat.id, get("https://i0.wampi.ru/2019/11/12/image.png").content)
bot.polling()
from termcolor import colored
from colored import back
print(back.YELLOW)
print('{blue} Программа запущена!{endcolor}'.format(blue='\033[96m', endcolor='\033[0m'))
d = input( "Выбери действие: (+,-)")
a = float(input("Введи первое число: "))
b = float(input("Введи второе число: "))
if d == "+":
c = a + b
print("Ответ:" + str(c))
elif d == "-" and a > b:
c = a - b
print("Ответ:" + str(c))
elif d == "-" and b > a:
c = b - a
print("Ответ:" + str(c))
else:
print("Выбрана неверная операция!")
def printArray(array):
for i in range(0, len(array)):
print(str(array[i]) + "-" + str(i))
def main():
array = ["first", "second"]#НЕльзя называть массив list потому что это уже зарезервированное имя в питоне
printArray(array)
item = int(input("> "))
if item in range(0, len(array)):
print(array[item])
else:
print("Элемента с таким индексом не существует")
if __name__ == '__main__':
main()
from sys import argv
argv[0]#Имя файла, но в live режиме просто "".
def isKey(plainDict, key):
try:
plainDict[key]
return True
except KeyError:
return False
def main():
wordsAmount = {}
with open('input.txt') as f:
lines = [lines.split(" ") for lines in f.read().strip().split("\n")]
for line in lines:
for word in line:
if not isKey(wordsAmount, word):
wordsAmount.update({word : 1})
else:
wordsAmount[word] += 1
print(max(wordsAmount))
if __name__ == '__main__':
main()
open("FILENAME", "MODE", encoding='utf-8-sig') - для русского языка :)
import io
io.open("FILENAME", "MODE", encoding='utf-8-sig')
s = {"oid":"1455","link":"https://vk.com/id248376867?w=wall248376867_531","orid":19282},{"oid":"1497","link":"https://vk.com/wall59628_30351","orid":19283}
print(s[1])
{'oid': '1497', 'link': 'https://vk.com/wall59628_30351', 'orid': 19283}
# -*- coding: utf-8 -*-
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
import requests
import json
import time
import sys
from random import randint
vk = vk_api.VkApi(token="xxxx")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, xxx)
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
# print(event.object.text)
# print()
text = event.object.text;
if text.lower() == "вики":
wiki_url = 'https://ru.wikipedia.org/w/api.php?action=opensearch&redirects=resolve&limit=1&format=json&search=';
try:
wiki_url = wiki_url + str(event.object.reply_message['text'])
wiki_response = requests.get(wiki_url)
wiki_json = json.loads(wiki_response.text)
wiki_subj = wiki_json[2][0]
wiki_link = wiki_json[3][0]
if wiki_subj == '':
wiki_message = "Нет такого на вики!";
else:
wiki_message = wiki_subj + "\n Подробнее: " + wiki_link
except TypeError:
wiki_message = 'Что виковать?'
except IndexError:
wiki_message = 'Нет этого на вики!!!'
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": wiki_message,
"random_id": randint(1, 9999)})
elif text.lower() == "баш":
bash_url = "https://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=ru"
bash_response = requests.get(bash_url)
bash_json = json.loads(bash_response.text)
bash_message = bash_json['quoteText']
try:
bash_message = bash_message + "\n Автор: " + bash_json['quoteAuthor']
except TypeError:
bash_message = bash_message + ' '
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": bash_message,
"random_id": randint(1, 9999)})
elif text.lower() == "текст":
text_url = "https://fish-text.ru/get"
text_response = requests.get(text_url)
text_json = json.loads(text_response.text)
text_message = text_json["text"]
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": text_message,
"random_id": randint(1, 9999)})
time.sleep(0.01)