for obj in items:
print(obj)
a = Artists(artist_id=obj['artists_id'],
artist_name=obj['name'],
genres=obj['genres'],
artist_url=obj['artists_url'],
artist_img_url=obj['artists_img_url'])
db.session.add(a)
from flask import g
def get_db():
if 'db' not in g:
g.db = connect_to_database()
return g.db
def get_normal_from_super(x):
normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-=()"
super_s = "ᴬᴮᶜᴰᴱᶠᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾQᴿˢᵀᵁⱽᵂˣʸᶻᵃᵇᶜᵈᵉᶠᵍʰᶦʲᵏˡᵐⁿᵒᵖ۹ʳˢᵗᵘᵛʷˣʸᶻ⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾"
res = x.maketrans(''.join(super_s), ''.join(normal))
return x.translate(res)
>>> get_normal_from_super('¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸')
'1 2 3 4 5 6 7 8'
def loopfunc():
while 1:
while 1:
if condition:
return
from base64 import b64decode
import imghdr
encoded_string = 'image base64 encoded'
decoded_string = b64decode(encoded_string)
extension = imghdr.what(None, h=decoded_string)
import itertools
struct_resale = struct.pop(0)
lst = []
for x, y in itertools.product(struct, struct_resale['sub_cats']):
if x['cat_name'] == y['cat_name']:
c = x.copy()
c.update(y)
c['goods_inside'] = x['goods_inside'] + y['goods_inside']
lst.append(c)
print(lst)
def get_sub_ids(parent, arr):
for sub in my_list:
if sub['parent'] == parent:
arr.append(sub['id'])
get_sub_ids(sub['id'], arr)
return arr
for item in my_list:
item['sub_ids'] = get_sub_ids(item['id'], [])
[{'id': 1, 'parent': '', 'sub_ids': [2, 3, 4, 5]}, {'id': 2, 'parent': 1, 'sub_ids': []}, {'id': 3, 'parent': 1, 'sub_ids': [4, 5]}, {'id': 4, 'parent': 3, 'sub_ids': []}, {'id': 5, 'parent': 3, 'sub_ids': []}]
>>> arr = [
... [1,2,3,4,5],
... [1,3,5,6],
... [7, 3, 5, 8],
... ]
>>> arr = [set(a) for a in arr]
>>> list(set.intersection(*arr))
[3, 5]
>>>
def login():
form = LoginForm()
if form.validate_on_submit():
if form.username.data == 'Login' and form.password.data == 'Password':
flash('Вы вошли')
return redirect('/index')
else:
flash('Неверный логин или пароль')
return render_template('login.html', title='Sign In', form=form)
if form.validate_on_submit():
if request.method == 'POST' and form.validate_on_submit():
from flask import request
In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.
For triple-quoted strings, always use double quote characters to be consistent with the docstring convention in PEP 257.
a = soup.findAll("div", {"class": "webinar-block"})
a = soup.findAll("a", {"class": "webinar-block__title"})
from bs4 import BeautifulSoup
import urllib.request
from urllib.parse import urlparse
resp = urllib.request.urlopen("https://toster.ru")
soup = BeautifulSoup(resp, from_encoding=resp.info().get_param('charset'))
for link in soup.find_all('a', href=True):
href = link['href']
if not urlparse(href).netloc or 'toster.ru' in href:
print(href)