Пример #1
0
from pricehunter.models import BrowseNode, session

for browse_node in session.query(BrowseNode).all():
    node = browse_node
    print(node.id, end=': ')
    while node is not None:
        print('{} ({})'.format(node.name, len(node.items.all())), end=', ')
        node = node.ancestors.first() if len(
            node.ancestors.all()) > 0 else None
    print()
Пример #2
0
from pricehunter.models import BrowseNode, session


def print_browse_nodes(out, browse_nodes, min_items=None):
    for browse_node in browse_nodes:
        items_count = browse_node.items.count()
        if min_items is None or items_count > min_items:
            name = browse_node.name if browse_node.name else "<null>"
            out.write('\t{} [label="{} ({})\n{}"];\n'.format(
                browse_node.id, name, items_count, browse_node.id))

            print_browse_nodes(out, browse_node.ancestors)

            for ancestor in browse_node.ancestors:
                out.write('\t{} -> {};\n'.format(browse_node.id, ancestor.id))


if __name__ == "__main__":
    out = open('browse_nodes.dot', 'w')
    out.write("strict digraph browse_nodes {\n")
    print_browse_nodes(out, session.query(BrowseNode).all(), 100)
    out.write("}")
from pricehunter.models import Item, session
from .browse_nodes_to_graphviz import print_browse_nodes

out = open('browse_nodes.dot', 'w')
out.write("digraph browse_nodes {\n")

for item in session.query(Item).all():
    out.write('\t"{}" [label="{}\n{}"];\n'.format(
        item.asin, item.title.replace('"', '\\"'), item.asin))
    for browse_node in item.browse_nodes:
        out.write('\t"{}" -> "{}";\n'.format(item.asin, browse_node.id))

out.write('\t{ rank=same; ')
for item in session.query(Item).all():
    out.write('"{}" '.format(item.asin))
out.write('}\n')

print_browse_nodes(out)

out.write("}")
from collections import defaultdict
from sqlalchemy import func
from pricehunter.models import Domain, DatafeedrPrice, Item, ItemSalesRank, BrowseNode, session

max_layers = 3
print('Trusted,Items in all layers,Items in top layers,{},Name'.format(
    ','.join('Layer {} items'.format(i) for i in range(max_layers + 1))))

for domain in session.query(Domain).order_by(Domain.name.asc()):
    if len(domain.name) > 0:
        result = (session.query(Item).select_from(Domain, DatafeedrPrice).join(
            DatafeedrPrice, Item).filter(Domain.name == domain.name))

        layer_counts = defaultdict(int)

        for item in result:
            item_result = (session.query(
                func.min(BrowseNode.layer)).select_from(
                    Item, ItemSalesRank, BrowseNode).join(
                        ItemSalesRank,
                        BrowseNode).filter(Item.asin == item.asin).one()[0])
            if item_result != None:
                layer_counts[item_result] += 1

        top_layers = [layer_counts[i] for i in range(max_layers + 1)]
        print(','.join([
            'y' if domain.trusted else '',
            str(sum(layer_counts.values())),
            str(sum(top_layers)), *[str(l) for l in top_layers], domain.name
        ]))
from pricehunter import datafeedr
from pricehunter.models import DatafeedrPrice, Item, session


items = session.query(Item).filter(Item.upc != None).filter(Item.upc > "619125629036").order_by(Item.upc.asc()).all()

for item in items:
    if item.upc:
        datafeedr_prices = datafeedr.get_prices_for_upc(item.upc)
        for price in datafeedr_prices:
            price.item = item
            if not session.query(DatafeedrPrice).filter_by(_id=price._id).first():
                session.add(price)

        session.commit()