-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient.py
41 lines (34 loc) · 1017 Bytes
/
client.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
import json
import os
# import from the 21 Developer Library
from two1.commands.config import Config
from two1.lib.wallet import Wallet
from two1.lib.bitrequests import BitTransferRequests
# set up bitrequest client for BitTransfer requests
wallet = Wallet()
username = Config().username
requests = BitTransferRequests(wallet, username)
# server address
SERVER_URL = 'http://localhost:5000/'
def cmd_btc_quote():
url = SERVER_URL + 'btc_quote'
r = requests.get(url)
print(r.text)
def cmd_price_quote():
url = SERVER_URL + 'quote'
r = requests.get(url)
print(r.text)
def cmd_buy(action):
url = SERVER_URL + 'buy?action=%s&payout_address=%s' % \
(action, wallet.get_payout_address())
r = requests.get(url)
print(r.text)
if __name__ == '__main__':
if len(sys.argv) == 0:
cmd_btc_quote()
elif sys.argv[0] == 'quote':
cmd_price_quote()
elif sys.argv[0] == 'buy':
cmd_buy(sys.argv[1])
else:
cmd_price_quote()