-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeckofcards.py
More file actions
27 lines (19 loc) · 744 Bytes
/
deckofcards.py
File metadata and controls
27 lines (19 loc) · 744 Bytes
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
import requests
import pprint as pp
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
new_deck_url = "https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1"
response = requests.get(new_deck_url, verify=False)
api_data = response.json()
deck_id = api_data["deck_id"]
draw_card_url = f"https://deckofcardsapi.com/api/deck/{deck_id}/draw/?count=2"
response = requests.get(draw_card_url, verify = False)
api_data = response.json()
print("Deck ID = ", deck_id)
pp.pprint(api_data)
while api_data["remaining"] > 0:
print("Curent Pair:")
response = requests.get(draw_card_url, verify = False)
api_data = response.json()
for code in api_data["cards"]:
pp.pprint(code["code"])