Skip to content

Commit ffd5df8

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 3ec8054 according to the output from Autopep8. Details: https://app.deepsource.com/gh/avinashkranjan/Amazing-Python-Scripts/transform/6d82c15e-053b-4cbb-a0fe-c7076fd2e7eb/
1 parent 3ec8054 commit ffd5df8

File tree

1 file changed

+76
-73
lines changed

1 file changed

+76
-73
lines changed

Swiggy_Scraper/main.py

+76-73
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,85 @@
11
import requests
22
from bs4 import BeautifulSoup as bs
33

4+
45
def get_restraunt_details(restraunt_url):
5-
"""
6-
```python
7-
get_restraunt_details(restraunt_url="https://www.swiggy.com/restaurants/pizza-hut-western-extension-area-karol-bagh-delhi-435678")
8-
```
9-
Response
10-
```js
11-
{
12-
"name":"Pizza Hut",
13-
"cuisine":"Pizzas",
14-
"area":"Karol Bagh",
15-
"rating":"3.7",
16-
"rating_count":"1K+ ratings",
17-
"cost_per_person":"₹350 for two",
18-
"offers":[
19-
{
20-
"15% OFF UPTO ₹300":"USE CITIFOODIE | ABOVE ₹1200"
21-
}
22-
...
23-
]
24-
}
25-
```
26-
"""
27-
try:
28-
headers = {
29-
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win 64 ; x64) Apple WeKit /537.36(KHTML , like Gecko) Chrome/80.0.3987.162 Safari/537.36"
6+
"""
7+
```python
8+
get_restraunt_details(restraunt_url="https://www.swiggy.com/restaurants/pizza-hut-western-extension-area-karol-bagh-delhi-435678")
9+
```
10+
Response
11+
```js
12+
{
13+
"name":"Pizza Hut",
14+
"cuisine":"Pizzas",
15+
"area":"Karol Bagh",
16+
"rating":"3.7",
17+
"rating_count":"1K+ ratings",
18+
"cost_per_person":"₹350 for two",
19+
"offers":[
20+
{
21+
"15% OFF UPTO ₹300":"USE CITIFOODIE | ABOVE ₹1200"
3022
}
31-
response = requests.get(restraunt_url, headers=headers).text
32-
soup = bs(response, "lxml")
33-
restaurant_data = []
34-
name = soup.find(
35-
"p", {"class": "RestaurantNameAddress_name__2IaTv"}
36-
).text.strip()
37-
cuisine = soup.find(
38-
"p", {"class": "RestaurantNameAddress_cuisines__mBHr2"}
39-
).text.strip()
40-
area = soup.find(
41-
"p", {"class": "RestaurantNameAddress_area__2P9ib"}
42-
).text.strip()
43-
rating = soup.find(
44-
"span", {"class": "RestaurantRatings_avgRating__1TOWY"}
23+
...
24+
]
25+
}
26+
```
27+
"""
28+
try:
29+
headers = {
30+
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win 64 ; x64) Apple WeKit /537.36(KHTML , like Gecko) Chrome/80.0.3987.162 Safari/537.36"
31+
}
32+
response = requests.get(restraunt_url, headers=headers).text
33+
soup = bs(response, "lxml")
34+
restaurant_data = []
35+
name = soup.find(
36+
"p", {"class": "RestaurantNameAddress_name__2IaTv"}
37+
).text.strip()
38+
cuisine = soup.find(
39+
"p", {"class": "RestaurantNameAddress_cuisines__mBHr2"}
40+
).text.strip()
41+
area = soup.find(
42+
"p", {"class": "RestaurantNameAddress_area__2P9ib"}
43+
).text.strip()
44+
rating = soup.find(
45+
"span", {"class": "RestaurantRatings_avgRating__1TOWY"}
46+
).text.strip()
47+
rating_count = soup.find(
48+
"span", {"class": "RestaurantRatings_totalRatings__3d6Zc"}
49+
).text.strip()
50+
cost_per = soup.find_all("li", {"class": "RestaurantTimeCost_item__2HCUz"})[
51+
-1
52+
].text.strip()
53+
offers = []
54+
offer_box = soup.find_all(
55+
"div", {"class": "RestaurantOffer_infoWrapper__2trmg"}
56+
)
57+
for offer in offer_box:
58+
offer_ = {}
59+
offer_header = offer.find(
60+
"p", {"class": "RestaurantOffer_header__3FBtQ"}
4561
).text.strip()
46-
rating_count = soup.find(
47-
"span", {"class": "RestaurantRatings_totalRatings__3d6Zc"}
62+
offer_content_1 = offer.find("span").text.strip()
63+
offer_content_2 = offer.find(
64+
"span", {"class": "RestaurantOffer_description__1SRJf"}
4865
).text.strip()
49-
cost_per = soup.find_all("li", {"class": "RestaurantTimeCost_item__2HCUz"})[
50-
-1
51-
].text.strip()
52-
offers = []
53-
offer_box = soup.find_all(
54-
"div", {"class": "RestaurantOffer_infoWrapper__2trmg"}
55-
)
56-
for offer in offer_box:
57-
offer_ = {}
58-
offer_header = offer.find(
59-
"p", {"class": "RestaurantOffer_header__3FBtQ"}
60-
).text.strip()
61-
offer_content_1 = offer.find("span").text.strip()
62-
offer_content_2 = offer.find(
63-
"span", {"class": "RestaurantOffer_description__1SRJf"}
64-
).text.strip()
65-
offer_content = offer_content_1 + " | " + offer_content_2
66-
offer_[offer_header] = offer_content
67-
offers.append(offer_)
68-
restaurant_data = {
69-
"name": name,
70-
"cuisine": cuisine,
71-
"area": area,
72-
"rating": rating,
73-
"rating_count": rating_count,
74-
"cost_per_person": cost_per,
75-
"offers": offers,
76-
}
77-
return restaurant_data
78-
except:
79-
return None
66+
offer_content = offer_content_1 + " | " + offer_content_2
67+
offer_[offer_header] = offer_content
68+
offers.append(offer_)
69+
restaurant_data = {
70+
"name": name,
71+
"cuisine": cuisine,
72+
"area": area,
73+
"rating": rating,
74+
"rating_count": rating_count,
75+
"cost_per_person": cost_per,
76+
"offers": offers,
77+
}
78+
return restaurant_data
79+
except:
80+
return None
81+
8082

8183
if __name__ == "__main__":
82-
print(get_restraunt_details("https://www.swiggy.com/restaurants/pizza-hut-western-extension-area-karol-bagh-delhi-435678"))
84+
print(get_restraunt_details(
85+
"https://www.swiggy.com/restaurants/pizza-hut-western-extension-area-karol-bagh-delhi-435678"))

0 commit comments

Comments
 (0)