package main
import (
"fmt"
"encoding/xml"
)
type Body struct {
XMLName xml.Name
Status string `xml:"methodResponse>responseData>status"`
}
type Envelope struct {
XMLName xml.Name
Body Body `xml:"Body"`
}
func main() {
var envelope Envelope
raw := []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:methodResponse>
<responseData>
<status>OK</status>
</responseData>
</SOAP-ENV:methodResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
`)
err := xml.Unmarshal(raw, &envelope)
if err != nil {
fmt.Printf("something wrong %s", err)
}
fmt.Printf("Status: %s", envelope.Body.Status)
}
Status: OK
Process finished with exit code 0
source = 'St\n\n\nri\nng test\n123 ... H.el.lo'
print(f'Before: {source}')
symbols_to_replace = {
'\n\n\n': ' ',
'\n': ' ',
'.': '',
}
for search, replace in symbols_to_replace.items():
source = source.replace(search, replace)
print(f'After: {source}')
Before: St
ri
ng test
123 ... H.el.lo
After: St ri ng test 123 Hello
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'}
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get("https://rublix.best/")
prev_bet = 0
while True:
all_bets = driver.find_elements_by_xpath("//div[contains(@class, 'history-line')]")
if all_bets:
last_bet = all_bets[0].text
if last_bet != prev_bet:
prev_bet = last_bet
print(f'Last bet: {last_bet}')
sleep(1)