def zapros(): """Собирает найденые товар из таблицы для найденого и чистит ее""" app = create_app() with app.app_context(): products = Product_all_check.query.all() if products == []: return False else: all_mail = [] for product in products: all_mail.append(product.email) set_list_mail = (set(all_mail)) dict_for_mail = {} for mail in set_list_mail: info = Product_all_check.query.filter_by(email=mail).all() list_one_check = {} for one_check in info: if one_check.int_product == '': size = 'б/р' url = one_check.url list_one_check[size] = url else: size = one_check.int_product url = one_check.url list_one_check[size] = url dict_for_mail[mail] = list_one_check clear_table_mail(dict=dict_for_mail) print(dict_for_mail) return dict_for_mail
def add_to_products_all_butik(): """ Функция добавляет в базу данных Product все товары Бутик.ру """ app = create_app() with app.app_context(): get_full_butik()
def add_to_products_all_randevu(): """ Функция добавляет в базу данных Product все товары Рандеву """ app = create_app() with app.app_context(): get_full_randevu()
def add_to_products_url_randevu(url): """ Функция добавляет в базу данных Product товар Рандеву по ссылке """ app = create_app() with app.app_context(): dict = get_randevu_product(url) save_data_product(dict)
def add_to_products_url_butik(url): """ Функция добавляет в базу данных Product товар Бутик.ру по ссылке """ app = create_app() with app.app_context(): dict = get_butik_product(url) save_data_product(dict)
def butik(): app = create_app() with app.app_context(): butik_status = get_butik_data() if butik_status is not False: get_full_butik() save_data_product(get_full_butik()) else: print('Бутик был недоступен, обновление базы не выполнено') pass
def rand(): app = create_app() with app.app_context(): randezvous_status = get_randevu_data() if randezvous_status is not False: get_full_randevu() save_data_product(get_full_randevu()) else: print('Рандеву был недоступен, обновление базы не выполнено') pass
def ali(): app = create_app() with app.app_context(): ali_status = get_ali_data() if ali_status is not False: ali = Aliexpress() ali.page_ali() else: print('Алиекспрес был недоступен, обновление базы не выполнено') pass
def reset_pass_mail(e_mail, url): app = create_app() mail = Mail(app) with app.app_context(): msg = Message("Перейдите по ссылке для смены вашего пароля", sender="*****@*****.**", recipients=[e_mail]) msg.body = render_template('email/reset_mail.txt', url=url) msg.html = render_template('email/reset_mail.html', url=url) mail.send(msg) print("__________Сообщение отправлено____________")
def add_interesting_product(url, email=None, price_interesting=None, color_interesting=None, size_interesting=None): """ Функция сохраняет товар, интересный клиенту, в базу InterestingProduct """ app = create_app() with app.app_context(): dict = get_info(url) # print(dict) save_interesting_product(dict, email=email, price_interesting=price_interesting, color_interesting=color_interesting, size_interesting=size_interesting)
def insteresting_product_check(): """ Функция проверяет наличие товров для клиента (база InterestingProduct) и отрпавляет уведомление """ app = create_app() with app.app_context(): all_interesting_products = create_dict_interesting_products() for id, url in all_interesting_products.items(): all_interesting_products[id] = get_info(url) for id, info in all_interesting_products.items(): check_product(info, id)
def email(): app = create_app() mail = Mail(app) with app.app_context(): dict = zapros() print(dict) if dict is False: print('Сообшений для отправки нет') else: for email, list in dict.items(): # print(email) # print(list) msg = Message("Ура мы возможно нашли что вы искали", sender="*****@*****.**", recipients=[email]) msg.body = render_template('email/message.txt', list=list) msg.html = render_template('email/message.html', list=list) mail.send(msg) print("__________Сообщение отправлено____________")
from getpass import getpass # ВВод пароля из командной строки import sys from webapp_stores import create_app from webapp_stores.stores.model import db from webapp_stores.user.model import User app = create_app() with app.app_context(): name = input('input name: ') surname = input('input surname: ') username = input('input login: '******'Input e-mail: ') if User.query.filter(User.username == username, User.name == name, User.surname == surname).count(): print('User is exist') sys.exit(0) i = 3 while i!=0: password_1 = getpass('Input password: '******'Confirm password: '******'password is not confirm. Try agene') i-=1 print(f'You have {i} attempt') continue else: sys.exit(0) new_user = User(username=username, role='admin', is_active=True, name=name, surname=surname, email=email) new_user.save_password(password_1) db.session.add(new_user) db.session.commit()
def clear_table_mail(dict): app = create_app() with app.app_context(): for mail, list in dict.items(): Product_all_check.query.filter_by(email=mail).delete() db.session.commit()
from webapp_stores import db, create_app from webapp_stores.user.model import InterestingProduct, User from sqlalchemy import create_engine from webapp_stores.config import SQLALCHEMY_DATABASE_URI #delete one table # engine=create_engine(SQLALCHEMY_DATABASE_URI) # User.__table__.drop(engine) # InterestingProduct.__table__.drop(engine) #delete all tables #db.drop_all(app=create_app()) #create all tables db.create_all(app=create_app())
from celery import Celery from webapp_stores import create_app from webapp_stores.parsing_run import butik, randevy, ali from celery.schedules import crontab from webapp_stores.proxy import proxy, curs from webapp_stores.mail.views import email, reset_pass_mail from webapp_stores.check.check_product import insteresting_product_check from webapp_stores.config import CELERY_BROKER_URL import celeryconfig celery = Celery() #'tasks', broker= CELERY_BROKER_URL celery.config_from_object(celeryconfig) flask = create_app() @celery.task def proxy_1(): with flask.app_context(): proxy.proxy() @celery.task def curs_today(): with flask.app_context(): curs.get_curs_usd() @celery.task def randevys(): with flask.app_context(): randevy.rand()