Skip to content

Commit

Permalink
Removed MPP and made routes dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
adityabindal committed Apr 6, 2017
2 parents a7e455a + 383621b commit 969e872
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions scraper.py
Expand Up @@ -30,32 +30,32 @@ def getPrice(start_latitude,start_longitude,end_latitude,end_longitude,productID
url='https://api.uber.com/v1.2/requests/estimate'
headers={'Authorization':"Bearer %s" % accessToken,"Content-Type": "application/json"}
params={
'start_latitude':gps_MPP.latitude,
'start_longitude':gps_MPP.longitude,
'end_latitude':gps_Harper.latitude,
'end_longitude':gps_Harper.longitude,
'start_latitude':start_latitude,
'start_longitude':start_longitude,
'end_latitude':end_latitude,
'end_longitude':end_longitude,
'seat_count':2,
'product_id':productIDs['uberX']}
requestx=requests.post(url,json=params,headers=headers).json()
scraperwiki.sqlite.save(
unique_keys=['timestamp','product_id'],
data=dict(params,**{'price':requestx['fare']['value'],'timestamp':time.strftime('%Y-%m-%d %H:%M:%S')}))
params={
'start_latitude':gps_MPP.latitude,
'start_longitude':gps_MPP.longitude,
'end_latitude':gps_Harper.latitude,
'end_longitude':gps_Harper.longitude,
'start_latitude':start_latitude,
'start_longitude':start_longitude,
'end_latitude':end_latitude,
'end_longitude':end_longitude,
'seat_count':1,
'product_id':productIDs['uberPOOL']}
requestp1=requests.post(url,json=params,headers=headers).json()
scraperwiki.sqlite.save(
unique_keys=['timestamp','product_id'],
data=dict(params,**{'price':requestp1['fare']['value'],'timestamp':time.strftime('%Y-%m-%d %H:%M:%S')}))
params={
'start_latitude':gps_MPP.latitude,
'start_longitude':gps_MPP.longitude,
'end_latitude':gps_Harper.latitude,
'end_longitude':gps_Harper.longitude,
'start_latitude':start_latitude,
'start_longitude':start_longitude,
'end_latitude':end_latitude,
'end_longitude':end_longitude,
'seat_count':2,
'product_id':productIDs['uberPOOL']}
requestp2=requests.post(url,json=params,headers=headers).json()
Expand All @@ -66,32 +66,25 @@ def getPrice(start_latitude,start_longitude,end_latitude,end_longitude,productID
def main():
#Get GPS Coords;
accessToken=os.environ['MORPH_ACCESS_TOKEN']
gps_MPP=getGPS('151 N Michigan Ave, Chicago, IL 60601');
gps_Shoreham=getGPS('400 East South Water St, Chicago, IL 60601');
gps_Harper=getGPS('5807 S Woodlawn Ave, Chicago, IL 60637');
productIDs=getProducts(accessToken,gps_Shoreham.latitude,gps_Shoreham.longitude)

while time.localtime().tm_hour<18:
if time.localtime().tm_hour<9:
getPrice(productIDs,gps_MPP.latitude,gps_MPP.longitude,gps_Harper.latitude,gps_Harper.longitude)
getPrice(productIDs,gps_Shoreham.latitude,gps_Shoreham.longitude,gps_Harper.latitude,gps_Harper.longitude)
getPrice(productIDs,gps_Harper.latitude,gps_Harper.longitude,gps_MPP.latitude,gps_MPP.longitude)
getPrice(productIDs,gps_Harper.latitude,gps_Harper.longitude,gps_Shoreham.latitude,gps_Shoreham.longitude)
time.sleep(60*5)
elif time.localtime().tm_hour<11:
time.sleep(60*30)
elif time.localtime().tm_hour<14:
getPrice(productIDs,gps_MPP.latitude,gps_MPP.longitude,gps_Harper.latitude,gps_Harper.longitude)
getPrice(productIDs,gps_Shoreham.latitude,gps_Shoreham.longitude,gps_Harper.latitude,gps_Harper.longitude)
getPrice(productIDs,gps_Harper.latitude,gps_Harper.longitude,gps_MPP.latitude,gps_MPP.longitude)
getPrice(productIDs,gps_Harper.latitude,gps_Harper.longitude,gps_Shoreham.latitude,gps_Shoreham.longitude)
time.sleep(60*5)
elif time.localtime().tm_hour<16:
time.sleep(60.30)
else:
getPrice(productIDs,gps_MPP.latitude,gps_MPP.longitude,gps_Harper.latitude,gps_Harper.longitude)
getPrice(productIDs,gps_Shoreham.latitude,gps_Shoreham.longitude,gps_Harper.latitude,gps_Harper.longitude)
getPrice(productIDs,gps_Harper.latitude,gps_Harper.longitude,gps_MPP.latitude,gps_MPP.longitude)
getPrice(productIDs,gps_Harper.latitude,gps_Harper.longitude,gps_Shoreham.latitude,gps_Shoreham.longitude)
time.sleep(60*10);

Expand Down

0 comments on commit 969e872

Please sign in to comment.