raena-crawler-engine/noon_crawler_engine/noon_raw_product.py

62 lines
1.7 KiB
Python
Raw Permalink Normal View History

2024-01-24 13:05:07 +00:00
import json
import logging
import requests
# import random
# import string
# import uuid
# import time
# import jwt
from urllib.parse import urlparse, quote
##### Looger ######
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S")
def get_product_info_raw(url):
#parsed_url = urlparse(url)
parsed_url = url.replace("noon.com/uae-en/", "noon.com/_svc/catalog/api/v3/u/")
print(parsed_url)
encoded_url = quote(parsed_url, safe='')
api_url= 'http://localhost:3090/rcs/v1/noon/'
print(url)
print(api_url+encoded_url)
response = requests.request("GET", api_url+encoded_url)
logging.info(response)
print(api_url+encoded_url)
data = json.loads(response.text)
return data['data']
# def generate_sentry_trace():
# trace_id = ''.join(random.choices(string.ascii_lowercase + string.digits, k=32))
# span_id = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16))
# sampling_decision = random.randint(0, 1)
#
# sentry_trace = f'{trace_id}-{span_id}-{sampling_decision}'
# return sentry_trace
#
# def generate_x_visitor_id():
# x_visitor_id = str(uuid.uuid4())
# return x_visitor_id
#
# def generate_cookie():
# payload = {
# 'raId': 'd1e3f451135d40958672d78da1f8c612',
# 'iat': int(time.time()),
# 'exp': int(time.time()+60)
# }
# # Generate the cookie string without a secret key
# cookie = jwt.encode(payload, '', algorithm='HS256')
#
# return cookie
# url = 'https://www.noon.com/uae-en/niacinamide-10-and-zinc-1-clear-30ml/N23772548A/p/?o=cbd635fab2298abe'
# #
# print(get_product_info_raw(url))