try except
.from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 2, # disable all notice
"profile.default_content_setting_values.media_stream_mic": 2, # disable microphone
"profile.default_content_setting_values.media_stream_camera": 2, # disable camera
"profile.default_content_setting_values.geolocation": 2, # disable geolocations
})
driver = webdriver.Chrome(options=options)
driver.get("https://example.com")
Возможно, можно сам браузер добавить в папку бота, а там указать путь.
Но ничего не получилось=(
# a = input('Введите данные: ').split('\t')
a = "Interpreter is a computer program that performs instructions without previously compiling them into a machine language program\tlinker is a program that takes one or more object files generated by a compiler and combines them into a single executable file library file or another object file\tthe linker also takes care of arranging the objects in a program's address space\tthe linker also takes care of arranging the objects in a program's address space".split('\t')
res = {}
for i in a:
sentence = i.strip()
res[sentence] = res.get(sentence, 0) + 1
print(max(res.values())) # 2
и как это устранить
chrome_options.add_argument("--disable-javascript")
chrome_options.add_argument("--disable-images")
options = Options()
options .add_argument("--headless")
Operand should contain 1 column(s)
cur.execute(f"UPDATE aromki SET photo = {date[3]} WHERE id = '{pg}'")
date[3] # ?
Что делать если про скачивании aiogram, выходить данная команда?
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-buil...
Суть в том, чтобы открывать файл нажатием на него, а не выбором в приложении. (Как при открытии тех же .docx и .txt файлов, но с собственным расширением)
import subprocess # from all OS
# open file win32
filename = 'path/to/file.doc'
subprocess.run(['open', filename])
# subprocess.run(['open', filename]) # macOS
# subprocess.run(['xdg-open', filename]) # linux
Почему переменная all_participants принимает только 10000 значений, а не больше при парсинге?
lst = []
while True:
item = input('Введите 6-значное число: ')
if len(item) != 6:
break
lst.append(int(item))
# sorting
lst.sort()
prev = None
for num in lst:
nums = str(num)[:3] # first 3 numbers
if nums != prev:
print() # print empty row
prev = nums
print(num, end=' ')
а если запустить цикл повторно, файл в котором хранятся просмотренные фильмы перезаписывается
with open('iwatch.txt', 'w', encoding='utf-8') as f:
with open('iwatch.txt', 'a', encoding='utf-8') as f:
import random
import json
# file
try:
with open('films.json', 'r', encoding='utf-8') as f:
films = json.load(f)
except FileNotFoundError:
films = {}
# save
def save(films):
with open('films.json', 'w', encoding='utf-8') as f:
json.dump(films, f, ensure_ascii=False, indent=4)
# main
def main():
while True:
random_film_key = random.choice(list(films))
film_value = films.get(random_film_key).replace(',', '\n')
print("Фильм: " + random_film_key, "Описание фильма: " + film_value, sep='\n')
# а где вариант 3 (ya est' Grut)?
q = input("Ты смотрел этот фильм? да - 1, нет - 0, выход - любая другая клавиша \n")
if q == '1':
with open('iwatch.txt', 'a', encoding='utf-8') as f:
f.write(random_film_key + '\n')
del films[random_film_key]
save(films)
elif q == '0':
continue
else:
break
# run
main()
import os
import glob
# sort by change date
def sort(path, ext="*.jpg"):
files = glob.glob(os.path.join(path, ext))
files.sort(key=os.path.getmtime)
return files
# rename files
def rename(path):
_sorted = sort(path)
for i, file_path in enumerate(_sorted, 1):
folder, old_name = os.path.split(file_path)
new_name = f"{i}.jpg"
new_path = os.path.join(folder, new_name)
os.rename(file_path, new_path)
print(f"Rename {old_name} to {new_name}")
if __name__ == "__main__":
# path to dir with images
folder_path = "/path/to/dir/images"
rename(folder_path)
from telethon import TelegramClient, utils
# config
api_id = 'id'
api_hash = 'hash'
phone = 'phone'
client = TelegramClient('session_name', api_id, api_hash)
async def main():
# authentication
await client.start(phone)
# get group and channel list
dialogs = await client.get_dialogs()
# print group and channel data
for dialog in dialogs:
if dialog.is_group or dialog.is_channel:
print(f"{dialog.name}: {dialog.id}")
# start
client.loop.run_until_complete(main())