Skip to content

Commit

Permalink
feat: add locale header to request to fetch content based on system l…
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Feb 22, 2021
1 parent 3f00ed8 commit 58c9e40
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion archivy/models.py
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urljoin

import frontmatter
import locale
import requests
import validators
from attr import attrs, attrib
Expand Down Expand Up @@ -92,7 +93,15 @@ def process_bookmark_url(self):
return None

try:
url_request = requests.get(self.url)
try:
lc = locale.getdefaultlocale()[0].replace('_', '-')
if lc == "C":
# fall back to en-US
lc == "en-US"
headers = {"Accept-Language": lc}
except Exception:
headers = None
url_request = requests.get(self.url, headers=headers)
except Exception:
flash(f"Could not retrieve {self.url}\n", "error")
self.wipe()
Expand Down

0 comments on commit 58c9e40

Please sign in to comment.