Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,8 @@ from google_auth_oauthlib.flow import InstalledAppFlow
|
|
11 |
from googleapiclient.discovery import build
|
12 |
from googleapiclient.http import MediaIoBaseDownload,MediaFileUpload
|
13 |
from google.oauth2 import service_account
|
14 |
-
|
15 |
-
|
16 |
|
17 |
# Load credentials from environment variables
|
18 |
SERVICE_ACCOUNT_INFO = {
|
@@ -29,6 +29,9 @@ SERVICE_ACCOUNT_INFO = {
|
|
29 |
"universe_domain": "googleapis.com"
|
30 |
}
|
31 |
|
|
|
|
|
|
|
32 |
def authenticate():
|
33 |
# Authenticate using service account credentials
|
34 |
creds = service_account.Credentials.from_service_account_info(SERVICE_ACCOUNT_INFO, scopes=['https://www.googleapis.com/auth/drive'])
|
@@ -117,7 +120,8 @@ def convert_pdf_to_excel(pdf_file):
|
|
117 |
|
118 |
extracted_data_for_mapping = whole_data.drop('Date Qty',axis=1)
|
119 |
extracted_data_for_mapping = extracted_data_for_mapping.drop_duplicates(subset=["Part No.","Part Color Code","Part Name"])
|
120 |
-
extracted_data_for_mapping.columns = ['Customer Part no as per pdf','Customer Part
|
|
|
121 |
|
122 |
whole_data.to_excel(extracted_file, index=False)
|
123 |
extracted_data_for_mapping.to_excel(data_for_mapping, index=False)
|
@@ -204,7 +208,6 @@ def pull_mapping_file_from_drive():
|
|
204 |
fh.close()
|
205 |
return 1
|
206 |
|
207 |
-
print('No Excel files found.')
|
208 |
return 0
|
209 |
|
210 |
def main():
|
@@ -220,13 +223,11 @@ def main():
|
|
220 |
extracted_file,data_for_mapping = convert_pdf_to_excel(uploaded_file)
|
221 |
|
222 |
file_present = pull_mapping_file_from_drive()
|
223 |
-
print(file_present)
|
224 |
|
225 |
if file_present:
|
226 |
mapping_data_from_drive = pd.read_excel(MAPPING_FILENAME)
|
227 |
-
print(mapping_data_from_drive)
|
228 |
extracted_data_for_mapping = pd.read_excel(data_for_mapping)
|
229 |
-
extracted_data_for_mapping = extracted_data_for_mapping.merge(mapping_data_from_drive, on = ['Customer Part no as per pdf','Customer Part name as per pdf','Customer Part color as per pdf'], how='outer')
|
230 |
extracted_data_for_mapping.to_excel(data_for_mapping,index=False)
|
231 |
|
232 |
# Download link for the Excel file
|
@@ -252,14 +253,14 @@ def main():
|
|
252 |
# mapping_data = mapping_data.rename(columns = {'Customer Part no as per pdf':'Part No.'})
|
253 |
data_for_mapping = "Data Mapping.xlsx"
|
254 |
extracted_data_for_mapping = pd.read_excel(data_for_mapping)
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
extracted_data_for_mapping = extracted_data_for_mapping[
|
259 |
unmapped_part_no = extracted_data_for_mapping['Customer Part no as per pdf'].nunique()
|
260 |
if unmapped_part_no>0:
|
261 |
st.markdown("#### There are {} Part No. with No ItemCode present. Upload a new file after mapping them".format(unmapped_part_no))
|
262 |
-
|
263 |
# else:
|
264 |
# st.markdown("#### Using the Mapping file available in Google Drive")
|
265 |
# mapping_uploaded_file = MAPPING_FILENAME
|
|
|
11 |
from googleapiclient.discovery import build
|
12 |
from googleapiclient.http import MediaIoBaseDownload,MediaFileUpload
|
13 |
from google.oauth2 import service_account
|
14 |
+
from dotenv import load_dotenv
|
15 |
+
load_dotenv()
|
16 |
|
17 |
# Load credentials from environment variables
|
18 |
SERVICE_ACCOUNT_INFO = {
|
|
|
29 |
"universe_domain": "googleapis.com"
|
30 |
}
|
31 |
|
32 |
+
SCOPES = ['https://www.googleapis.com/auth/drive']
|
33 |
+
|
34 |
+
|
35 |
def authenticate():
|
36 |
# Authenticate using service account credentials
|
37 |
creds = service_account.Credentials.from_service_account_info(SERVICE_ACCOUNT_INFO, scopes=['https://www.googleapis.com/auth/drive'])
|
|
|
120 |
|
121 |
extracted_data_for_mapping = whole_data.drop('Date Qty',axis=1)
|
122 |
extracted_data_for_mapping = extracted_data_for_mapping.drop_duplicates(subset=["Part No.","Part Color Code","Part Name"])
|
123 |
+
extracted_data_for_mapping.columns = ['Customer Part no as per pdf','Customer Part color as per pdf','Customer Part name as per pdf']
|
124 |
+
extracted_data_for_mapping['Item Code'] = ""
|
125 |
|
126 |
whole_data.to_excel(extracted_file, index=False)
|
127 |
extracted_data_for_mapping.to_excel(data_for_mapping, index=False)
|
|
|
208 |
fh.close()
|
209 |
return 1
|
210 |
|
|
|
211 |
return 0
|
212 |
|
213 |
def main():
|
|
|
223 |
extracted_file,data_for_mapping = convert_pdf_to_excel(uploaded_file)
|
224 |
|
225 |
file_present = pull_mapping_file_from_drive()
|
|
|
226 |
|
227 |
if file_present:
|
228 |
mapping_data_from_drive = pd.read_excel(MAPPING_FILENAME)
|
|
|
229 |
extracted_data_for_mapping = pd.read_excel(data_for_mapping)
|
230 |
+
extracted_data_for_mapping = extracted_data_for_mapping[['Customer Part no as per pdf','Customer Part name as per pdf','Customer Part color as per pdf']].merge(mapping_data_from_drive, on = ['Customer Part no as per pdf','Customer Part name as per pdf','Customer Part color as per pdf'], how='outer')
|
231 |
extracted_data_for_mapping.to_excel(data_for_mapping,index=False)
|
232 |
|
233 |
# Download link for the Excel file
|
|
|
253 |
# mapping_data = mapping_data.rename(columns = {'Customer Part no as per pdf':'Part No.'})
|
254 |
data_for_mapping = "Data Mapping.xlsx"
|
255 |
extracted_data_for_mapping = pd.read_excel(data_for_mapping)
|
256 |
+
if 'Item Code' not in extracted_data_for_mapping.columns:
|
257 |
+
extracted_data_for_mapping['Item Code'] = ""
|
258 |
+
|
259 |
+
extracted_data_for_mapping = extracted_data_for_mapping[extracted_data_for_mapping['Item Code'].isna()]
|
260 |
unmapped_part_no = extracted_data_for_mapping['Customer Part no as per pdf'].nunique()
|
261 |
if unmapped_part_no>0:
|
262 |
st.markdown("#### There are {} Part No. with No ItemCode present. Upload a new file after mapping them".format(unmapped_part_no))
|
263 |
+
mapping_uploaded_file = st.file_uploader("Upload the Data Master file with Item Code mapping", type=["xlsx","ods"])
|
264 |
# else:
|
265 |
# st.markdown("#### Using the Mapping file available in Google Drive")
|
266 |
# mapping_uploaded_file = MAPPING_FILENAME
|