-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patholearyspicker.py
73 lines (56 loc) · 2.04 KB
/
olearyspicker.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
#!/usr/bin/env python
"""
Pretty badass O'learys finder from long/lat and stuff.
Usage:
olearyspicker.py [options]
Options:
--longitude=long Longitude value [default: 18.0388702]
--latitude=lat Latitude value [default: 59.3213309]
--distance=dist Distance in meters [default: 4000]
-h, --help Show this help and exit
-v, --verbose There is no verbose :(
"""
from __future__ import print_function, unicode_literals
import json
import random
import requests
from docopt import docopt
class restaurant(object):
def __init__(self, title, short_title, slug,
address, distance, phone, url):
self.title = title
self.short_title = short_title
self.slug = slug
self.address = address
self.distance = distance
self.phone = phone
self.url = url
def banner(*text):
longest = len(max(text, key=len))
frame = '*' * (longest + 4)
print(frame)
for i, row in enumerate(text):
print('{char} {text} {char}'.format(
char='*',
text=row.ljust(longest)))
print(frame)
def main(args):
api = "http://olearys.se/api/v1/restaurants/?language_code=sv-se&site_id=2"
r = requests.get(
"{api}&point={longitude},{latitude}&dist={distance}".format(api=api,
**args))
restaurants = []
data = json.loads(r.text)
if data['count'] >= 1:
for line in json.loads(r.text)['results']:
restaurants.append(restaurant(
line['title'], line['short_title'], line['slug'],
line['address'], line['distance'], line['phone'], line['url']))
rest = restaurants[random.randrange(len(restaurants))]
banner(rest.title, rest.address, rest.phone)
else:
banner("No restaurants found within that range and coordinates")
if __name__ == "__main__":
args = docopt(__doc__, version='0.1.0-perhaps', help=True)
args = {k[2:]: v for (k, v) in args.items()}
main(args)