-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathget_deliveroo_olo.py
83 lines (51 loc) · 2.42 KB
/
get_deliveroo_olo.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
import requests
from bs4 import BeautifulSoup
import pandas as pd
import datetime
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# Get all deliveroo orders
def get_deliveroo_orders(orders):
url = "https://deliveroo.com.sg/orders"
cookies = {
'cookie': 'your cookies here',
}
resp = requests.get(url, cookies=cookies)
html = resp.content
soup = BeautifulSoup(html, 'html.parser')
order_history = soup.find("div", {"class": "user user--history mbottom30"})
order_entry = order_history.findAll("li")
for order in order_entry:
if order is not None:
items = []
vendor = order.find("span", {"class": "history-restaurant"}).getText().strip()
order_date = order.find("span", {"class": "history-col-date"}).getText().strip()
cost = order.find("span", {"class": "history-col-amount"}).getText().strip()
order_endp = order.find(href=True)
order_url = url + "/" + order_endp['href'].split("/")[2]
resp = requests.get(order_url, cookies=cookies)
html = resp.content
soup = BeautifulSoup(html, 'html.parser')
inner_order_entry = soup.find("div", {"class": "order-list-inner"})
if inner_order_entry is None:
continue
detailed_orders = inner_order_entry.findAll("div", {"class":"oi-inner"})
for detail in detailed_orders:
if detail is not None:
qnt = detail.find("div", {"class": "oi-quantity"}).getText().strip()
items.append(qnt + " " + detail.find("div", {"class": "oi-title"}).getText().strip())
sides = detail.findAll("li")
for side in sides:
items.append(side.getText())
orders.append({'Restaurant': vendor,
'Date': datetime.datetime.strptime(order_date, "%d %B %Y %H:%M").date(),
'Cost': cost, 'Items': items, 'Service': 'deliveroo'})
return orders
if __name__ == "__main__":
# Store all orders in a list
orders = []
deliveroo_orders = get_deliveroo_orders(orders)
# Convert orders to pandas dataframe
df = pd.DataFrame(orders)
# Export dataframe into csv file
df.to_csv("deliveroo_orders.csv", index=False)