예제 #1
0
from blessings import Terminal
from tinydb import where
from tqdm import tqdm
import csv

from lib.command import Command, UsageException
from pycollect import db

term = Terminal()
games = db.table('games')
prices = db.table('vgpc_prices')

class VgPriceChartingCommand(Command):
    def __init__(self, *args, **kwargs):
        self.register_command('price_lookup', VgPriceChartingLookupCommand, shortcuts=['pl'])
        self.register_command('price_load', VgPriceChartingLoadCommand, shortcuts=['lp'])


class VgPriceChartingLoadCommand(VgPriceChartingCommand):
    help_command = "price_load"
    help_args = ['Filename of a Price Charting database']
    help_msg = \
        """
        This command loads a given Price Charting database locally.
        """
    import_keys = ('id', 'cib-price', 'loose-price', 'product-name')

    def run(self):
        try:
            with open(self.args[0]) as csvfile:
                reader = csv.DictReader(csvfile)
예제 #2
0
from lib.command import Command
from pycollect import db
from tinydb import where

games = db.table('games')

class DatabaseCommand(Command):
    def __init__(self):
        self.register_command('list', DatabaseListCommand, shortcuts=['ls'])
        self.register_command('delete', DatabaseDeleteCommand, shortcuts=['del'])
        self.register_command('show', DatabaseShowCommand, shortcuts=['sh'])
        self.register_command('edit', DatabaseEditCommand, shortcuts=['ed'])
        self.register_command('find', DatabaseFindComand, shortcuts=['fi'])


class DatabaseFindComand(Command):
    help_command = 'find'
    help_args = ['search terms']
    help_msg = \
        """
        Find a game already in the database, works like search command.
        """

    def run(self):
        local_games = games.search(where('name')
                                   .test(self._regex_search_ignorecase, r'{}'
                                         .format(self.args[0])))
        results = [(g['id'], g['platform'], g['name']) for g in local_games]
        self.show_results(results)

예제 #3
0
import requests
from blessings import Terminal
from tinydb import where

from lib.command import Command, UsageException
from pycollect import db

term = Terminal()
games = db.table('games')


class VgcollectCommand(Command):
    excluded_category_id = [
        '29', '380', '381', '382', '383', '384', '385', '386', '387'
    ]
    api_base_url = "http://api.vgcollect.com"
    api_key = 'abcdefg'

    def __init__(self, *args, **kwargs):
        self.register_command('search',
                              VgcollectSearchCommand,
                              shortcuts=['se'])
        self.register_command('info', VgcollectInfoCommand, shortcuts=['in'])
        self.register_command('add', VgcollectAddCommand, shortcuts=['ad'])

    def search_items(self, args):
        r = requests.get('/'.join(
            [self.api_base_url, 'search', '+'.join(args), self.api_key]))
        if r.status_code == 200 and len(r.json()):
            return r.json()
        else: