Git Product home page Git Product logo

pymtgoracle's Introduction

pymtgoracle

Python library for MtG:Oracle

Dependencies

  • requests
  • BeautifulSoup
  • SQLAlchemy

Usage

Initial Database Scrape

In order to use mymtgoracle, you must first scrape all of the cards from http://magiccards.info

This can be accomplished by firing up python and issuing the following commands:

>>> from mtgoracle.scraper import scrape_all
>>> scrape_all()

This will pull down everything that magiccards.info knows and store it in a local SQL database. The database is configured in mtgoracle/dbengine.py and defaults to a sqlite database saved at ~/mtgoracle.sqlite

Scraping might take a little while but you should only have to do it once (or no more than once each time that pymtgoracle is updated or a new set is released).

Initialize Session

Fire up python and initialize the session:

>>> from mtgoracle.dbengine import get_engine
>>> from mtgorale.model import *
>>> init_model(get_engine())

issue queries/get objects

For now most of the functionality exists by issuing SQLAlchemy queries but a few of the classes have some utility methods to fetch cards. Once you have a card, you can examine its attributes.

>>> pd = Card.by_name(u'Phyrexian Dreadnought')
>>> print pd.rules
Trample
When Phyrexian Dreadnought enters the battlefield, sacrifice it unless you
sacrifice any number of creatures with total power 12 or greater.
>>> Card.with_subtype(u'Island')
[<Card: Hallowed Fountain>,
 <Card: Steam Vents>,
 <Card: Island>,
 <Card: Moonring Island>,
 <Card: Snow-Covered Island>,
 <Card: Breeding Pool>,
 <Card: Watery Grave>,
 <Card: Tropical Island>,
 <Card: Tundra>,
 <Card: Underground Sea>,
 <Card: Volcanic Island>]
>>> cmc0s = DBSession.query(Card).filter_by(cost=u'0').all()
>>> len(cmc0s)
49
>>> cmc0s[0]
<Card: Darksteel Relic>
>>> cmc0s[-1]
<Card: Urza's Contact Lenses>

pymtgoracle's People

Contributors

gwax avatar

Watchers

Ben McGraw avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.