-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptcgodb-server.py
executable file
·160 lines (139 loc) · 3.32 KB
/
ptcgodb-server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python2.7
import json
from flask import Flask, render_template, request
from flask.ext.mongokit import MongoKit, Document
app = Flask(__name__)
app.config.update(dict(
DEBUG=True,
MONGODB_DATABASE='ptcgodb',
))
class Card(Document):
structure = {
'id': int,
'name': unicode,
'type': unicode,
'set': unicode
}
required_fields = ['id', 'name', 'type', 'set']
db = MongoKit(app)
db.register([Card])
@app.route("/")
def deckbuilder():
return render_template('deckbuilder.html')
@app.route('/api/cards/<set_id>')
def api_cards(set_id):
results = db['cards'].Card.find({
'set': set_id
}, {
'_id': 0,
'name': 1,
'type': 1,
'id': 1,
'set': 1,
})
cards = []
for card in results:
cards.append(card)
return json.dumps(cards)
@app.route('/api/cards/<set_id>/<card_id>')
def api_single_card(set_id, card_id):
results = db['cards'].Card.find_one({
'set': set_id,
'id': card_id,
}, {
'_id': 0,
'name': 1,
'type': 1,
'id': 1,
'set': 1,
})
return json.dumps(results)
@app.route('/api/sets')
def api_sets():
card_sets = {
'bw-series': [
['bwp', 'BW Black Star Promos'],
['bw1', 'Black and White'],
['bw2', 'Emerging Powers'],
['bw3', 'Noble Victories'],
['bw4', 'Next Destinies'],
['bw5', 'Dark Exploreres'],
['bw6', 'Dragons Exalted'],
['dv1', 'Dragon Vault'],
['bw7', 'Boundaries Crossed'],
['bw8', 'Plasma Storm'],
['bw9', 'Plasma Freeze'],
['bw10', 'Plasma Blast'],
['bw11', 'Legendary Treasures'],
],
'xy-series': [
['xyp', 'XY Black Star Promos'],
['xy0', 'Kalos Starter Set'],
['xy1', 'XY'],
['xy2', 'Flashfire'],
['xy3', 'Furious Fists'],
['xy4', 'Phantom Forces'],
['xy5', 'Primal Clash'],
['dc1', 'Double Crisis'],
['xy6', 'Roaring Skies'],
['xy7', 'Ancient Origins'],
['xy8', 'BREAKthrough'],
],
}
format = request.args.get('format')
if format == 'flat':
flat_sets = {}
for series in card_sets:
for set in card_sets[series]:
set_key = set[0]
flat_sets[set_key] = set[1]
return json.dumps(flat_sets)
else:
return json.dumps(card_sets)
@app.route('/api/sets/standard')
def api_sets_standard():
card_sets = [
'xyp',
'xy0',
'xy1',
'xy2',
'xy3',
'xy4',
'xy5',
'dc1',
'xy6',
'xy7',
'xy8',
]
return json.dumps(card_sets)
@app.route('/api/sets/expanded')
def api_sets_expanded():
card_sets = [
'bwp',
'bw1',
'bw2',
'bw3',
'bw4',
'bw5',
'bw6',
'dv1',
'bw7',
'bw8',
'bw9',
'bw10',
'bw11',
'xyp',
'xy0',
'xy1',
'xy2',
'xy3',
'xy4',
'xy5',
'dc1',
'xy6',
'xy7',
'xy8',
]
return json.dumps(card_sets)
if __name__ == '__main__':
app.run()