chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
from selenium.common.exceptions import TimeoutException
...
except TimeoutException:
...
source venv/bin/activate
, находясь при этом в папке с проектомresult = '{} and {} likes this'.format(', '.join(names[:-1]), names[-1])
result = f'{", ".join(names[:-1])} and {names[-1]} likes this'
from itertools import groupby
source = [
{'code': 'AA01', 'group': 'U01', 'user': '1375', },
{'code': 'AA01', 'group': 'U01', 'user': '1575', },
{'code': 'AA03', 'group': 'U02', 'user': '1375', },
{'code': 'AA02', 'group': 'U02', 'user': '1345', },
{'code': 'AA02', 'group': 'U03', 'user': '1315', },
{'code': 'AA01', 'group': 'U04', 'user': '1615', },
]
result = {}
for key, group in groupby(source, lambda x: x['group']):
subgroup = {}
for item in group:
subgroup[item['code']] = item['user']
result[key] = subgroup
{
'U01': {'AA01': '1575'},
'U02': {'AA03': '1375',
'AA02': '1345'},
'U03': {'AA02': '1315'},
'U04': {'AA01': '1615'}
}
# -*- coding: utf-8 -*-
from collections import Counter
from collections import OrderedDict
fileName = "text.txt" # отсюда берем текст для анализа
outFileName = "result.txt" # сюда записываем результат
letters = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'
with open(fileName, encoding='utf-8') as f:
text = f.read().replace('\n', '')
text = ''.join([x.upper() for x in text if x.upper() in letters])
occurs = {key: value / len(text) for key, value in Counter(text).items()}
occurs_sorted = OrderedDict(reversed(sorted(occurs.items(), key=lambda x: x[1])))
with open(outFileName, "wt", encoding="utf8") as f:
f.write(f'{len(text)}\n')
for k, v in occurs_sorted.items():
f.write(f'{k}:{v:.3f}\n')
import random
from collections import Counter
n = 5
m = 5
matrix = [[random.randrange(0, 10) for y in range(n)] for x in range(m)]
print(*matrix, sep='\n')
most_common = [(i, Counter(x).most_common(1)[0]) for i, x in enumerate(matrix, start=1)]
print('(row_number, (element, count))')
print(*sorted(most_common, key=lambda x: int(x[1][1]), reverse=True), sep='\n')
bot.clear_step_handler_by_chat_id(chat_id=call.message.chat.id)
@bot.message_handler(commands=['start'])
def process_start(message):
board = types.InlineKeyboardMarkup()
cancel = types.InlineKeyboardButton(text="Отмена", callback_data="Отмена")
board.add(cancel)
text = 'start'
msg = bot.send_message(message.chat.id, text, reply_markup=board)
bot.register_next_step_handler(msg, process_mid)
def process_mid(message):
board = types.InlineKeyboardMarkup()
cancel = types.InlineKeyboardButton(text="Отмена", callback_data="Отмена")
board.add(cancel)
text = 'mid'
msg = bot.send_message(message.chat.id, text, reply_markup=board)
bot.register_next_step_handler(msg, process_end)
def process_end(message):
text = 'end'
bot.send_message(message.chat.id, text)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == "Отмена":
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Отменено.')
bot.clear_step_handler_by_chat_id(chat_id=call.message.chat.id)
bot.polling(none_stop=True)
from selenium import webdriver
driver = webdriver.Firefox()