Repository: alltheplaces/alltheplaces

Issue:
Rema 1000 (Custom API/Wordpress)


----
### Brand name

REMA 1000

supermarket chain

### Wikidata ID

Q28459
https://www.wikidata.org/wiki/Q28459
https://www.wikidata.org/wiki/Special:EntityData/Q28459.json

### Store finder url(s)
https://www.rema.no/butikker/

Official Url(s): https://rema.no
- [x] I have run the below and if anything in generated, added it.
- [ ] I have manually checked for a storefinder
- [ ] This is not a manufacturer listing outlets operating under their own brands / this will not create duplicates
`pipenv run scrapy sf --brand-wikidata=Q28459 https://rema.no`
```
```
Official Url(s): https://www.rema1000.dk/
- [x] I have run the below and if anything in generated, added it.
- [ ] I have manually checked for a storefinder
- [ ] This is not a manufacturer listing outlets operating under their own brands / this will not create duplicates
`pipenv run scrapy sf --brand-wikidata=Q28459 https://www.rema1000.dk/`
```
```


Discussion:
curl 'https://www.rema.no/ajaxProxy.php' \
  -H 'authority: www.rema.no' \
  -H 'accept: */*' \
  -H 'accept-language: en-GB,en;q=0.9,en-US;q=0.8,de;q=0.7,es;q=0.6,fr;q=0.5' \
  -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'cookie: __cf_bm=UgInhZr9ldb.GmqEk9JdGjbKirJTlAS867SSO8bscGg-1710971843-1.0.1.1-g.qyynBUX_y4ASdFSH.mqbe4g5ehw.CXd5t1XGl396LuFovENBv4t7HNLVAX7smujDX2h4wW.F8xFqhFTUjhJg; _cfuvid=apAZH67UvZIaRJvaS1liLn9_ZROvtNTSS6YXXK6_mX0-1710971843236-0.0.1.1-604800000; cf_clearance=pPbkUCvwDDeGF7gxx7H4gXyqD9u5LCQbMstDfLq4m4I-1710972081-1.0.1.1-9mNta_PLZjtxD4H2Cidxpe5yElBuen__knG4P1ZaiOxU6N5pPRqhyvIPN4pskV8Lu.Pyp8CCnrykMZiHZcIIQQ' \
  -H 'dnt: 1' \
  -H 'origin: https://www.rema.no' \
  -H 'referer: https://www.rema.no/butikker/nordland/oksnes/rema-1000-myre' \
  -H 'sec-ch-ua: "Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'sec-gpc: 1' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' \
  -H 'x-requested-with: XMLHttpRequest' \
  --data-raw 'task=zpin_get_store_with_region_slug&store_id=2091917'
https://www.rema.no/wp-json/rema-stores/v1/get-stores-data

Resolving patch:
diff --git a/locations/spiders/rema_1000_dk.py b/locations/spiders/rema_1000_dk.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/rema_1000_dk.py
@@ -0,0 +1,39 @@
+from scrapy import Spider
+from scrapy.http import JsonRequest
+
+from locations.categories import Categories
+from locations.dict_parser import DictParser
+from locations.hours import DAYS_NO, OpeningHours
+
+
+class REMA1000DKSpider(Spider):
+    name = "rema_1000_dk"
+    item_attributes = {
+        "brand": "REMA 1000",
+        "brand_wikidata": "Q115768834",
+        "extras": Categories.SHOP_SUPERMARKET.value,
+    }
+    allowed_domains = ["www.rema1000.dk"]
+    start_urls = ["https://www.rema1000.dk/api/v2/stores"]
+
+    def start_requests(self):
+        for url in self.start_urls:
+            yield JsonRequest(url)
+
+    def parse(self, response):
+        for location in response.json()["data"]:
+            if location.get("permanently_closed") or location.get("temporarily_closed_until"):
+                continue
+
+            item = DictParser.parse(location)
+            item["website"] = location.get("store_link")
+
+            hours_string = ""
+            for day_hours in location.get("opening_hours", {}).values():
+                hours_string = "{} {}: {} - {}".format(
+                    hours_string, day_hours.get("day"), day_hours.get("open"), day_hours.get("close")
+                )
+            item["opening_hours"] = OpeningHours()
+            item["opening_hours"].add_ranges_from_string(hours_string, days=DAYS_NO)
+
+            yield item


Test patch: