import pyowm
from pyowm.commons.enums import SubscriptionTypeEnum
from pyowm.utils.measurables import kelvin_to_celsius
city = 'Moscow'
config = {
'subscription_type': SubscriptionTypeEnum.FREE,
'language': 'ru',
'connection': {
'use_ssl': True,
'verify_ssl_certs': True,
'use_proxy': False,
'timeout_secs': 5
},
'proxies': {
'http': 'http://user:pass@host:port',
'https': 'socks5://user:pass@host:port'
}
}
owm = pyowm.OWM('', config=config)
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
print("В городе " + city + " сейчас температура: " + str(kelvin_to_celsius(w.temp['temp'])) + " по Цельсию.")
print('Погода в указанном городе: ' + observation.location.name)
import pyowm
from pyowm.commons.enums import SubscriptionTypeEnum
from pyowm.utils.measurables import kelvin_to_celsius
city = 'Krasnodar'
config = {
'subscription_type': SubscriptionTypeEnum.FREE,
'language': 'ru',
'connection': {
'use_ssl': True,
'verify_ssl_certs': True,
'use_proxy': False,
'timeout_secs': 5
},
'proxies': {
'http': 'http://user:pass@host:port',
'https': 'socks5://user:pass@host:port'
}
}
owm = pyowm.OWM('a99967bc9ee70d5b4bd387902982f400', config=config)
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
print("В городе " + city + " сейчас температура: " + str(kelvin_to_celsius(w.temp['temp'])) + " по Цельсию.")
print('Погода в указаном городе: ' + observation.location.name)
import cv2
img1 = cv2.imread("1.png")
img2 = cv2.imread("2.png", 1)
psnr = cv2.PSNR(img1, img2)
print(psnr)
26.633679839968654
Process finished with exit code 0
import sys
this_module = sys.modules[__name__]
def square(x):
return x * x
print(getattr(this_module, 'square')(10))
Foo
Process finished with exit code 0
def square(x):
return x * x
functions = {
'square': square
}
print(functions['square'](10))
100
Process finished with exit code 0
sp_with_follow = ['one', 'two', 'three', 'four', 'five']
res_list = ['1', 2, '3', 4, 5]
out = []
for el in sp_with_follow:
res_copy = res_list[:]
res_copy.insert(4,el)
out.extend(res_copy)
print(out)
['1', 2, '3', 4, 'one', 5, '1', 2, '3', 4, 'two', 5, '1', 2, '3', 4, 'three', 5, '1', 2, '3', 4, 'four', 5, '1', 2, '3', 4, 'five', 5]
Process finished with exit code 0
find_element_by_xpath("//div[@class='c-games__item']").text
teams = driver.find_elements_by_xpath("//div[@class='c-games__item']")
for i in teams:
print(i.text)
от чего такая разница ?
и как делать более компактные приложения ??
import clipboard
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
driver = webdriver.Chrome()
# Загружаем страницу
driver.get("https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-1472-4e50-a926-602807a6ef94")
balloons_xpath = "//div[contains(@class, 'yamb-message-balloon')]"
WebDriverWait(driver, 10).until(ec.presence_of_all_elements_located((By.XPATH, balloons_xpath)))
# Выбираем посты в канале
balloons = driver.find_elements_by_xpath(balloons_xpath)
# Кликаем на пост #4
actionChains = ActionChains(driver)
actionChains.context_click(balloons[4]).perform()
get_link_text = 'Get message link'
driver.find_element_by_xpath(f"//span[text()='{get_link_text}']/..").click()
# Получаем буфер обмена
text = clipboard.paste() # text will have the content of clipboard
print(text)
driver.quit()
https://yandex.ru/chat/#/join/33a66c77-0c4d-45be-80f6-cae89e95d765/1591340550272042
Process finished with exit code 0
from pygrok import Grok
text = 'gary is male, 25 years old and weighs 68.5 kilograms'
pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms'
grok = Grok(pattern)
print grok.match(text)
# {'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'}
def is_digit(n):
try:
int(n)
return True
except ValueError:
return False
blocks = driver.find_elements_by_xpath("//*[contains(@class, 'd-inline-block')]")
for i, block in enumerate(blocks):
with open(file=f'{i}.png', mode='wb') as f:
f.write(block.screenshot_as_png)
and i+1 <= length
print(list(set(source_list)))
source_list = [1, 4, 2, 3, 4, 5, 6]
print(source_list)
print(list(set(source_list)))
[1, 4, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
Process finished with exit code 0
import requests
import json
content = requests.get("http://rzhunemogu.ru/RandJSON.aspx?CType=1")
response_json = json.loads(content.text.replace('\r\n', '\\r\\n'))
print(response_json)
{'content': 'Смотpишь по телевизоpу pекламу - в ней pекламиpуют жуpнал. Покупаешь жуpнал - а там pеклама магазина. Идёшь в магазин - а там пpодают телевизоpы. Покупаешь телевизоp, включаешь - а там опять pеклама того же жуpнала. Где же выход?!'}
from filelock import Timeout, FileLock
lock = FileLock("high_ground.txt.lock")
with lock:
open("high_ground.txt", "a").write("You were the chosen one.")