-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathride.py
98 lines (71 loc) · 1.95 KB
/
ride.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
import os
import codecs
import subprocess
import click
from terminaltables import AsciiTable
from taxi import snapp
config = os.path.join(os.path.expanduser("~") + '/.config/snapp-cli/')
if not os.path.exists(config):
os.mkdir(config)
def read_path():
sp, dp = None, None
path_file = open(config + 'path.csv', 'r')
path = path_file.read()
if path:
return [(float(i), float(j)) for i,j in [d.split(',') for d in path.split('\n')[:2]]]
path_file.close()
return sp, dp
sp, dp = read_path()
@click.group()
def cli():
pass
@click.command()
@click.option('--username', '-u', type=str)
@click.option('--password', '-p', type=str)
def login(username, password):
'''
Login to your Snapp account
'''
ok = snapp.login(username=username, password=password)
if ok:
click.echo('Successful login.')
@click.command()
@click.option('--source', '-s', nargs=2, type=float)
@click.option('--destination', '-d', nargs=2, type=float)
@click.option('--map', '-m', is_flag=True)
def price(source, destination, map):
'''
Calculate price of a trip
'''
if map:
subprocess.call(['mapscii'])
source, destination = sp, dp
else:
pass
r = snapp.price(source[0], source[1], destination[0], destination[1])
t = AsciiTable([['S', 'Description', 'Price']] + r)
click.echo('\n')
click.echo(t.table)
service_number = click.prompt('Please send your chosen service number', type=int)
request_ride(service_number)
def request_ride(serivce_nubmer):
import time
click.echo('Waiting...')
time.sleep(2)
click.echo('Find a driver')
@click.command()
def ride():
'''
Compelete this function to take a ride with snapp
Note:
- Use chrome or firefox
- Please PEP8!!
- Dynamic path file
Your homework
'''
request_ride(0)
cli.add_command(login)
cli.add_command(price)
cli.add_command(ride)
if __name__ == '__main__':
cli()