-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
125 lines (82 loc) · 2.92 KB
/
main.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
# from dotenv import load_dotenv
#
# load_dotenv()
import pandas as pd
import numpy as np
from woocommerce import API
wcapi = API(
url=os.environ['URL'],
consumer_key=os.environ['CONSUMER_KEY'],
consumer_secret=os.environ['CONSUMER_SECRET'],
version=os.environ['VERSION'],
wp_api=True,
timeout=30
)
def retrieve_needed_data_from_parent_sku(parent_sku, web_scraping):
row = web_scraping.loc[web_scraping['Parent_sku'].str.contains(parent_sku)]
# print()
#
if len(row) == 0:
return None, None, None
else:
print(row)
return row['Title'].iloc[0], row['Description'].iloc[0], parent_sku
def create_dict_for_api_post(name, description, parent_sku):
data_post = {
"name": f"{name} ",
"type": "simple",
"description": f'''{description}''',
"status": "private",
"sku": parent_sku,
"weight": f"0.1",
"categories": [
{
"id": 749,
"id": 762
}
]
,
"images": [
{
"src": f"https://www.equipdirect.com/wp-content/uploads/2021/08/{name}.jpg"
}
]
}
return data_post
def api_post(data_post):
print(data_post)
# print(wcapi.post("products", data_post).json())
radians_catalog = pd.read_excel(r'5036_2021_Radians_Industrial_PriceList_REV01 - FINAL.xlsx', header=78)
web_scraping = pd.read_csv(r'radians_eyewear_web_data.csv')
# capitalize columns for matching rows
radians_catalog['PART'] = radians_catalog['PART'].str.upper()
web_scraping['Parent_sku'] = web_scraping['Parent_sku'].str.upper()
web_scraping['Parent_sku'] = web_scraping['Parent_sku'].str.replace('-', ' ')
web_scraping['Parent_sku'] = web_scraping['Parent_sku'].str.replace(' ', ' ')
# print(web_scraping['Parent_sku'].iloc[0])
web_scraping['Variations'] = web_scraping['Variations'].str.upper()
# print(web_scraping['Parent_sku'])
# print(radians_catalog['PART'])
#
# print(web_scraping['Variations'])
for index, row in radians_catalog.iterrows():
# print(index)
# print(row)
if row['STYLE'] is not np.nan:
row['STYLE'] = row['STYLE'].encode("ascii", "ignore")
# print(row['STYLE'])
row['STYLE'] = "{0}{1}".format(row['STYLE'], '')
# print(row['STYLE'])
row['STYLE'] = row['STYLE'].lstrip('b,\'')
row['STYLE'] = row['STYLE'].rstrip('\'')
print('here')
print(row['STYLE'])
retrieve_needed_data_from_parent_sku(row['STYLE'], web_scraping)
name, description, parent_sku = retrieve_needed_data_from_parent_sku(row['STYLE'], web_scraping)
print(name, description, parent_sku)
dict_for_api_post = create_dict_for_api_post(name, description, parent_sku)
# print(dict_for_api_post)
api_post(dict_for_api_post)
else:
continue