|
|
@@ -297,14 +297,11 @@ def construct_dynamic_title(raw_data,selected_pt):
|
|
|
@login_required
|
|
|
def title_creator_view(request):
|
|
|
if request.method == 'POST' and request.FILES.get('file'):
|
|
|
- scraper = cloudscraper.create_scraper()
|
|
|
excel_file = request.FILES['file']
|
|
|
selected_pt = request.POST.get('product_type')
|
|
|
fs = FileSystemStorage()
|
|
|
filename = fs.save(excel_file.name, excel_file)
|
|
|
file_path = fs.path(filename)
|
|
|
-
|
|
|
-
|
|
|
|
|
|
try:
|
|
|
# 1. Read Excel
|
|
|
@@ -316,7 +313,13 @@ def title_creator_view(request):
|
|
|
|
|
|
headers = {"User-Agent": "Mozilla/5.0"}
|
|
|
results_for_ui = []
|
|
|
-
|
|
|
+ # Specific Headers for the Item# API
|
|
|
+ api_headers = {
|
|
|
+ "accept": "application/json, text/plain, */*",
|
|
|
+ "authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJERVYifQ.uOFB7h7_Aw6jbA1HSqVJ44tKMO7E1ljz1kV_JddeKL64YCOH57-l1ZX2Lly-Jnhdnxk3xMAeW5FawAgymEaMKA",
|
|
|
+ "client_id": "GEC",
|
|
|
+ "referer": "https://www.globalindustrial.com/"
|
|
|
+ }
|
|
|
|
|
|
# 3. Process each row
|
|
|
for index, row in df.iterrows():
|
|
|
@@ -329,16 +332,6 @@ def title_creator_view(request):
|
|
|
if pd.notna(url) and str(url).startswith('http'):
|
|
|
final_url = url
|
|
|
elif pd.notna(item_number):
|
|
|
- # Specific Headers for the Item# API
|
|
|
- dynamic_token = get_fresh_token(scraper)
|
|
|
-
|
|
|
- api_headers = {
|
|
|
- "accept": "application/json, text/plain, */*",
|
|
|
- "authorization": f"Bearer {dynamic_token}",
|
|
|
- # "authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJERVYifQ.uOFB7h7_Aw6jbA1HSqVJ44tKMO7E1ljz1kV_JddeKL64YCOH57-l1ZX2Lly-Jnhdnxk3xMAeW5FawAgymEaMKA",
|
|
|
- "client_id": "GEC",
|
|
|
- "referer": "https://www.globalindustrial.com/"
|
|
|
- }
|
|
|
# Call API to get URL from Item#
|
|
|
api_url = f"https://www.globalindustrial.com/catalogApis/catalog/autosuggest?key={item_number}&features=true"
|
|
|
try:
|
|
|
@@ -440,7 +433,14 @@ async def process_excel_task(file_path, selected_pt, task_id):
|
|
|
df['New_Generated_Title'] = ""
|
|
|
|
|
|
headers = {"User-Agent": "Mozilla/5.0"}
|
|
|
-
|
|
|
+ # dynamic_token = await get_fresh_token(scraper)
|
|
|
+ # Specific Headers for the Item# API
|
|
|
+ api_headers = {
|
|
|
+ "accept": "application/json, text/plain, */*",
|
|
|
+ "authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJERVYifQ.uOFB7h7_Aw6jbA1HSqVJ44tKMO7E1ljz1kV_JddeKL64YCOH57-l1ZX2Lly-Jnhdnxk3xMAeW5FawAgymEaMKA", #f"Bearer {dynamic_token}",
|
|
|
+ "client_id": "GEC",
|
|
|
+ "referer": "https://www.globalindustrial.com/"
|
|
|
+ }
|
|
|
|
|
|
# 3. Process each row
|
|
|
for index, row in df.iterrows():
|
|
|
@@ -452,14 +452,6 @@ async def process_excel_task(file_path, selected_pt, task_id):
|
|
|
if pd.notna(url) and str(url).startswith('http'):
|
|
|
final_url = url
|
|
|
elif pd.notna(item_number):
|
|
|
- dynamic_token = await get_fresh_token(scraper)
|
|
|
- # Specific Headers for the Item# API
|
|
|
- api_headers = {
|
|
|
- "accept": "application/json, text/plain, */*",
|
|
|
- "authorization": f"Bearer {dynamic_token}",#"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJERVYifQ.uOFB7h7_Aw6jbA1HSqVJ44tKMO7E1ljz1kV_JddeKL64YCOH57-l1ZX2Lly-Jnhdnxk3xMAeW5FawAgymEaMKA",
|
|
|
- "client_id": "GEC",
|
|
|
- "referer": "https://www.globalindustrial.com/"
|
|
|
- }
|
|
|
# Call API to get URL from Item#
|
|
|
api_url = f"https://www.globalindustrial.com/catalogApis/catalog/autosuggest?key={item_number}&features=true"
|
|
|
try:
|