forked from alltheplaces/alltheplaces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopapps.py
More file actions
35 lines (28 loc) · 1.37 KB
/
shopapps.py
File metadata and controls
35 lines (28 loc) · 1.37 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
from scrapy import Spider
from scrapy.http import JsonRequest, Response
from locations.dict_parser import DictParser
from locations.items import Feature
# This is an undocumented application forming part of the ShopApps
# suite of Shopify apps mentioned at https://shopapps.in/
#
# To use this spider, specify the "key" parameter that is unique
# to the brand. If additional fields need to be parsed, or some
# data needing to be cleaned, override the parse_item function.
class ShopAppsSpider(Spider):
dataset_attributes = {"source": "api", "api": "shopapps.site"}
key: str = ""
custom_settings = {"ROBOTSTXT_OBEY": False}
def start_requests(self):
yield JsonRequest(
url=f"https://stores.shopapps.site/front-end/get_surrounding_stores.php?shop={self.key}&latitude=0&longitude=0&max_distance=0&limit=10000"
)
def parse(self, response: Response):
for location in response.json()["stores"]:
item = DictParser.parse(location)
item.pop("addr_full", None)
item["street_address"] = ", ".join(filter(None, [location.get("address"), location.get("address2")]))
item["postcode"] = location.get("postal_zip")
item["state"] = location.get("prov_state")
yield from self.parse_item(item, location) or []
def parse_item(self, item: Feature, location: dict):
yield item