Skip to content

Commit

Permalink
feat: use specific User-Agent (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumit-158 authored Jul 20, 2023
1 parent 38d7c6c commit e71c713
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/off.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
from .i18n import translate as _
from .wikidata_utils import get_wikidata_entity, image_thumbnail, wikidata_props

# User-Agent header to use for all requests
# This is to ingore the logs
# As it doing a lot of requests to OpenFoodFacts
header = {"User-Agent": "Facets-Knowledge-Panels"}


async def fetch_quality(source_url):
"""Function to fetch data-quality"""
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers=header) as session:
quality_url = f"{source_url}/data-quality-errors.json"
async with session.get(quality_url) as resp:
return await resp.json()
Expand Down Expand Up @@ -91,7 +96,7 @@ async def last_edit(url, query):
Helper function to return data for last-edits
"""

async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers=header) as session:
search_url = f"{url}/api/v2/search"
async with session.get(search_url, params=query) as resp:
data = await resp.json()
Expand Down Expand Up @@ -165,7 +170,7 @@ async def wikidata_helper(query, value):
Helper function to return wikidata eg:label,description,image_url
"""
lang = get_current_lang()
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers=header) as session:
url = settings().TAXONOMY
async with session.get(url, params=query) as resp:
data = await resp.json()
Expand Down

0 comments on commit e71c713

Please sign in to comment.