import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('delete_coupon_by_code', 'delete')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def delete_coupon_by_code():
    parser = argparse.ArgumentParser()
    parser.add_argument("coupon_code", help="Coupon code")
    args = parser.parse_args()
    coupon_code = args.coupon_code

    logger.info(f'START with args: coupon_code={coupon_code}')

    duration_time = mongo_db.delete_coupon_by_code(coupon_code)
    logger.info(f"[Mongo] delete coupon: {duration_time.total_seconds()}")

    duration_time = postgres_db.delete_coupon_by_code(coupon_code)
    logger.info(f"[Postgres] delete coupon: {duration_time.total_seconds()}")


if __name__ == "__main__":
    delete_coupon_by_code()
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('update_order_price', 'update')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def set_order_price():
    parser = argparse.ArgumentParser()
    parser.add_argument("order_code", help="Order code")
    parser.add_argument("price", help="Order price", type=float)
    args = parser.parse_args()
    order_code = args.order_code
    price = args.price

    logger.info(f'START with args: order_code={order_code}, price={price}')

    duration_time = mongo_db.set_order_price(order_code, price)
    logger.info(f"[Mongo] set order price: {duration_time.total_seconds()}")

    duration_time = postgres_db.set_order_price(order_code, price)
    logger.info(f"[Postgres] set order price: {duration_time.total_seconds()}")


if __name__ == "__main__":
    set_order_price()
Пример #3
0
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('delete_order_by_code', 'delete')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def delete_order_by_code():
    parser = argparse.ArgumentParser()
    parser.add_argument("order_code", help="Order code")
    args = parser.parse_args()
    order_code = args.order_code

    logger.info(f'START with args: order_code={order_code}')

    duration_time = mongo_db.delete_order_by_code(order_code)
    logger.info(f"[Mongo] delete order: {duration_time.total_seconds()}")

    duration_time = postgres_db.delete_order_by_code(order_code)
    logger.info(f"[Postgres] delete order: {duration_time.total_seconds()}")


if __name__ == "__main__":
    delete_order_by_code()
Пример #4
0
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('orders_by_coupon', 'select')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def orders_by_coupon():
    parser = argparse.ArgumentParser()
    parser.add_argument("coupon_code", help="Coupon code")
    args = parser.parse_args()
    coupon_code = args.coupon_code

    logger.info(f'START with args: coupon_code={coupon_code}')

    orders, duration_time = mongo_db.orders_by_coupon(coupon_code)
    logger.info(f"[Mongo] orders by coupon: {duration_time.total_seconds()}")
    for order in orders:
        logger.info(f"order: {order}")

    orders, duration_time = postgres_db.orders_by_coupon(coupon_code)
    logger.info(
        f"[Postgres] orders by coupon: {duration_time.total_seconds()}")
    for order in orders:
        logger.info(f"order: {order}")
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('user_coupons', 'select')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def user_coupons():
    parser = argparse.ArgumentParser()
    parser.add_argument("user_email", help="User email")
    args = parser.parse_args()
    user_email = args.user_email

    logger.info(f'START with args: user_email={user_email}')

    coupons, duration_time = mongo_db.user_coupons(user_email)
    logger.info(f"[Mongo] user coupons: {duration_time.total_seconds()}")
    for coupon in coupons:
        logger.info(f"coupon: {coupon}")

    coupons, duration_time = postgres_db.user_coupons(user_email)
    logger.info(f"[Postgres] user coupons: {duration_time.total_seconds()}")
    for coupon in coupons:
        logger.info(f"coupon: {coupon}")

Пример #6
0
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('top_bestsellers', 'select')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def top_bestsellers():
    parser = argparse.ArgumentParser()
    parser.add_argument("top_limit", type=int, help="Record limit")
    args = parser.parse_args()
    top_limit = args.top_limit

    logger.info(f'START with args: top_limit={top_limit}')

    users, duration_time = mongo_db.top_bestsellers(top_limit)
    logger.info(f"[Mongo] top bestsellers: {duration_time.total_seconds()}")
    for user in users:
        logger.info(f"user: {user}")

    users, duration_time = postgres_db.top_bestsellers(top_limit)
    logger.info(f"[Postgres] top bestsellers: {duration_time.total_seconds()}")
    for user in users:
        logger.info(f"user: {user}")

import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('delete_user_by_email', 'delete')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def delete_user_by_email():
    parser = argparse.ArgumentParser()
    parser.add_argument("user_email", help="User email")
    args = parser.parse_args()
    user_email = args.user_email

    logger.info(f'START with args: user_email={user_email}')

    duration_time = mongo_db.delete_user_by_email(user_email)
    logger.info(f"[Mongo] delete user: {duration_time.total_seconds()}")

    duration_time = postgres_db.delete_user_by_email(user_email)
    logger.info(f"[Postgres] delete user: {duration_time.total_seconds()}")


if __name__ == "__main__":
    delete_user_by_email()
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('update_user_active', 'update')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def set_user_active():
    parser = argparse.ArgumentParser()
    parser.add_argument("user_email", help="User email")
    parser.add_argument("active", type=bool, help="Active flag")
    args = parser.parse_args()
    user_email = args.user_email
    active = args.active

    logger.info(f'START with args: user_email={user_email}, active={active}')

    duration_time = mongo_db.set_user_active(user_email, active)
    logger.info(f"[Mongo] set user active: {duration_time.total_seconds()}")

    duration_time = postgres_db.set_user_active(user_email, active)
    logger.info(f"[Postgres] set user active: {duration_time.total_seconds()}")


if __name__ == "__main__":
    set_user_active()
import argparse
import random
import uuid
from datetime import datetime, timedelta
import hashlib
from collections import namedtuple

import names

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('generate_user_data', 'insert')

User = namedtuple("User", ['email', 'password_hash', 'user_name', 'active'])

AffiliateOrder = namedtuple("AffiliateOrder", [
    'order_code', 'product_code', 'coupon_code', 'coupon_percentage', 'date',
    'price'
])


def generate_user_data():
    parser = argparse.ArgumentParser()
    parser.add_argument("user_count", type=int, help="User count")
    parser.add_argument("product_count", type=int, help="Product count")
    args = parser.parse_args()
    user_count = args.user_count
    product_count = args.product_count
Пример #10
0
import argparse

from models.mongo_db import MongoDB
from models.postgres_db import PostgresDB
from base import get_info_logger

logger = get_info_logger('update_coupon_percentage', 'update')

mongo_db = MongoDB()
postgres_db = PostgresDB()


def set_coupon_percentage():
    parser = argparse.ArgumentParser()
    parser.add_argument("coupon_code", help="Coupon code")
    parser.add_argument("percentage", type=float, help="Coupon percentage",)
    args = parser.parse_args()
    coupon_code = args.coupon_code
    percentage = args.percentage

    logger.info(f'START with args: coupon_code={coupon_code}, percentage={percentage}')

    duration_time = mongo_db.set_coupon_percentage(coupon_code, percentage)
    logger.info(f"[Mongo] set coupon percentage: {duration_time.total_seconds()}")

    duration_time = postgres_db.set_coupon_percentage(coupon_code, percentage)
    logger.info(f"[Postgres] set coupon percentage: {duration_time.total_seconds()}")


if __name__ == "__main__":
    set_coupon_percentage()