-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconfig.py
More file actions
40 lines (30 loc) · 1.64 KB
/
Copy pathconfig.py
File metadata and controls
40 lines (30 loc) · 1.64 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
36
37
38
39
40
"""Configuration for the Amazon Scraper. Everything can be set with an
environment variable; the defaults work out of the box.
PORT port the API listens on (default 8000)
AMAZON_PROXY proxy URL for every request, e.g. http://user:pass@host:port
(default: none — direct). The US, UK, German, French,
Indian, Canadian … storefronts answer direct requests, so you
very likely don't need this. Two exceptions: amazon.co.jp and
amazon.com.au only serve visitors from their own country —
for country=JP / country=AU set a proxy that exits in Japan /
Australia. A residential proxy also helps if you run very
high volumes from one IP.
Everything else below is a plain constant with a working default — edit it
here if you need to.
"""
import os
PORT = int(os.environ.get("PORT", "8000"))
# Retry policy for transport errors and blocks (every request).
MAX_RETRIES = 3
RETRY_BACKOFF = 2 # seconds, multiplied by the attempt number
AMAZON_PROXY = os.environ.get("AMAZON_PROXY") or None
# With a proxy set, every session goes through it (the package asks for a
# per-country exit; one proxy serves them all). Without it: direct.
AMAZON_PROXY_COUNTRY = "any" if AMAZON_PROXY else None
AMAZON_DIRECT_COOLDOWN = 300 # seconds a blocked marketplace stays on the proxy
def amazon_country_proxy(country):
"""The proxy for a session (None = direct)."""
return AMAZON_PROXY
def amazon_fallback_proxy(country):
"""The proxy a marketplace moves to after repeated blocks (None = none)."""
return AMAZON_PROXY