-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonversion.py
More file actions
144 lines (130 loc) · 4.83 KB
/
pythonversion.py
File metadata and controls
144 lines (130 loc) · 4.83 KB
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
def signup():
b = raw_input('Host or Guest? ')
if b == 'Host':
c = raw_input('Sign in or Sign Up? ')
if c == 'Sign in':
username = raw_input('Username = ')
password = raw_input('Password = ')
if verify_username_and_password(username, password, database) == "no":
print "incorrect username, Sign up"
username = raw_input('Username = ')
password = raw_input('Password = ')
database[username] = password
names[username] = raw_input('Name = ')
address[username] = raw_input('Address = ')
max_limit[username] = raw_input('Max Limit of Bags per day = ')
contact_number[username] = raw_input("Contact number")
email[username] = raw_input("Email")
rating[username] = 5
price[username] = raw_input("price per hour")
#return database, names, address, max_limit
else:
username = raw_input('Username = ')
password = raw_input('Password = ')
database[username] = password
names[username] = raw_input('Name = ')
address[username] = raw_input('Address = ')
max_limit[username] = raw_input('Max Limit of Bags per day = ')
contact_number[username] = raw_input("Contact number")
email[username] = raw_input("Email")
current_limit[username] = 0
rating[username] = 5
price[username] = raw_input("price per hour")
#return database, names, address, max_limit
else:
print "Sign Up Guest"
username = raw_input('Username = ')
password = raw_input('Password = ')
database[username] = password
namesguest[username] = raw_input('Name = ')
currentaddress[username] = raw_input("Current address = ")
jj = currentaddress[username]
NumberOfBags[username] = raw_input("NumberOfBags = ")
numb = NumberOfBags[username]
suitableusernames = []
rating[username] = 5
for username in names:
p = int(current_limit[username]) + int(numb)
if p <= int(max_limit[username]):
print username
suitableusernames.append(username)
print len(suitableusernames)
if len(suitableusernames) > 0:
rankingoflist(suitableusernames, jj)
def verify_username_and_password(username, password, database):
if username in database:
pass1 = database[username]
if database[username] == password:
return "Signed In"
else:
return "no"
def listprint():
print "database list"
print database
print "names list"
print names
print "address list"
print address
print "max_limit list"
print max_limit
print "email list"
print email
print "current_limit list"
print current_limit
print "rating"
print rating
def reverse_geocoding(place):
import requests
#place = "amherst massachusetts"
place = place.replace(" ","+")
link = 'https://maps.googleapis.com/maps/api/geocode/json?address='+place
response = requests.get(link)
resp_json_payload = response.json()
return resp_json_payload['results'][0]['geometry']['location']['lat'], resp_json_payload['results'][0]['geometry']['location']['lng']
def distance_in_time(place1, place2):
import simplejson, urllib
import geopy.distance
orig_coord = reverse_geocoding(place1)
dest_coord = reverse_geocoding(place2)
return geopy.distance.vincenty(orig_coord, dest_coord).km
def rankingoflist(usernames, currentguestaddress):
new_list = {}
dist = {}
print "ok"
for username in usernames:
host_Address = address[username]
distance = distance_in_time(host_Address, currentguestaddress)
dist[username] = distance
ranking_Score = float(rating[username])*float(distance)*float(price[username])
ranking_Score = ranking_Score/10
new_list[username] = ranking_Score
p = sorted([(value,key) for (key,value) in new_list.items()])
print "Suggestions listed nearby"
for u in p:
x = u[1]
print "username : " + str(x)
print "address : " + str(address[x])
print "contact number : " + str(contact_number[x])
print "distance from this location : " + str(dist[x])
print "\n"
print "Welcome to Bagdrop"
print "----------------------"
database = {}
#database['abc'] = 'xyz'
names = {}
address = {}
max_limit = {}
currentaddress = {}
NumberOfBags = {}
namesguest = {}
current_limit = {}
contact_number = {}
email = {}
rating = {}
price = {}
#current_limit['abc'] = 0
signup()
print "----------------"
print "new list"
print "---------------"
listprint()