-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.py
596 lines (586 loc) · 26.5 KB
/
index2.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
from whatstk import WhatsAppChat
import re
import os
from openpyxl import Workbook
import shutil
import pandas as pd
filepath = 'input/chat_log.txt'
chat = WhatsAppChat.from_source(filepath=filepath, hformat='[%m/%d/%y, %I:%M:%S %p] %name:')
alllogs=chat.df
row=alllogs.loc[30]
#test 3 4 15 25 35 36 39 43 52 56 58 61 74 75 76 79
j=0
curimg=""
imglist=[]
datarow=[]
prow=[]
qrow=[]
item={
"date":"",
"user":"",
"images":""
}
while j<len(alllogs):
row=alllogs.loc[j]
################################ initialize ######################################
_workorder=""
date=""
dispatcher=""
_company=""
nte=""
amountdue=""
_techname=""
technumber=""
paymentmethod=""
paymentaddress=""
joblocation=""
jobstatus=""
overall=""
photosq=""
workorder=""
date=""
dispatcher=""
company=""
qotedescription=""
quotedetails=""
totalprice=""
photosp=""
################################# end initialize ######################################
if (row.str.find("<attached:")>0).any() :
end=row.message.find("jpg")
image=row.message[11:end+3]
user=row.username
date=row.date
if user==curimg:
imglist[len(imglist)-1]["images"]=imglist[len(imglist)-1]["images"]+","+image
else:
item={
"date":date,
"user":user,
"images":image
}
imglist.append(item)
curimg=user
# print(date, user,image)
else:
if j!=0 and j%5==0:
step=1
while step<5:
for imageitem in imglist:
if datarow[len(datarow)-1-step]["Dispatcher"]==imageitem["user"]:
datarow[len(datarow)-1-step]["Photos"]=imageitem["images"]
imageitem["user"]=""
step=step+1
data=row.message
str2 = data.splitlines()
workorder=-1
company=-1
quoteflag=0
index=1
jlocationflag=0
jStatusflag=0
companyflag=0
amountflag=0
pmethodflag=0
techname=""
################################################# Dispatcher ##########################################################
# print("Dispatcher", row.username)
dispatcher=row.username
################################################# Date ##########################################################
# print("Date:",row.date)
date=row.date
for item in str2:
if item.strip()!="":
item=item.replace("*","")
# print("-----",item,"-----")
################################################# Quote ##########################################################
if item.find("quote") >-1 and signflag["WorkOrder"]==0:
if item.find(":"):
workorder=item[item.find("quote")+5:].strip().replace(":","").strip()
if workorder.find("for")==0:
workorder=workorder[3:].strip()
if workorder.isdigit():
signflag["WorkOrder"]=1
# print("Work Order:",workorder)
_workorder=workorder.strip()
continue
if item.find("QUOTE") >-1 or item.find("update") >-1:
quoteflag=1
continue
if quoteflag==1 and signflag["WorkOrder"]==0:
quoteflag=0
workorder=item.strip()
if workorder.find("WO # ")>-1:
quoteflag=3
signflag["WorkOrder"]=1
# print("Work Order:",workorder[3:])
_workorder=workorder[5:].strip()
if workorder.find("wo#")>-1 or workorder.find("WO#")>-1 or workorder.find("Wo#")>-1:
quoteflag=3
signflag["WorkOrder"]=1
# print("Work Order:",workorder[3:])
_workorder=workorder[3:].strip()
else:
signflag["WorkOrder"]=1
# print("Work Order:",workorder)
workorder=workorder.replace(" ","")
if workorder.find("WO#")>-1:
workorder=workorder[3:]
_workorder=workorder
continue
if item.find("Quote") >-1:
if item.find("#")>-1:
workorder=item[item.find("#")+1:].strip()
quoteflag=1
signflag["WorkOrder"]=1
# print("Work Order:",workorder)
_workorder=workorder.strip()
continue
else:
workorder=item[item.find("Quote")+5:]
if workorder.find("for")==0:
workorder=workorder[3:].strip().replace(" ","")
if workorder.find("WO#")>-1 or workorder.find("Wo#")>-1 or workorder.find("wo#")>-1 :
_workorder=workorder[3:].strip()
if workorder.isdigit():
_workorder=workorder.strip()
signflag["WorkOrder"]=1
continue
# workorder=workorder.strip()
# quoteflag=2
# signflag["WorkOrder"]=1
# # print("Work Order:",workorder)
# _workorder=workorder
# continue
if quoteflag==1 :
quoteflag=0
item=item.strip().replace(":","").strip()
if item.find("for")==0:
item=item[3:].strip().replace(":","").strip()
signflag["Company"]=1
# print("Company:",item)
_company=item.strip()
continue
else:
item=item.strip().replace(":","").strip()
signflag["Company"]=1
# print("Company:",item)
_company=item.strip()
continue
if quoteflag==2:
if item.find("for")==0:
item=item[3:].strip().replace(":","").strip()
if item.find("("):
item=item[:item.find("(")]
signflag["Company"]=1
# print("Company:",item)
_company=item.strip()
continue
if quoteflag==3 and item.find("wo#")==-1:
item=item.strip().replace(":","").strip()
quoteflag=0
signflag["Company"]=1
# print("Company:",item)
_company=item
continue
################################################# Work Order and Company ##########################################################
if quoteflag==5 and item.find(".com")==-1:
item=item.strip().replace(":","").strip()
quoteflag=0
signflag["Company"]=1
# print("Company:",item)
_company=item
continue
if workorder==-1:
workorder=item.find("WO")
if workorder>-1 and item.find("#"):
quoteflag=5
workorder=item[item.find("#")+1:]
signflag["WorkOrder"]=1
# print("Work Order:",workorder)
_workorder=workorder.strip()
continue
workorder=item.find("wo")
if workorder>-1 and item.find("#"):
workorder=item[item.find("#")+1:]
signflag["WorkOrder"]=1
# print("Work Order:",workorder)
companyflag=1
_workorder=workorder.strip()
continue
if type(workorder)!=int:
if item.find(".com")>-1:
companyflag=1
continue
if companyflag==1 and signflag["Company"]==0:
companyflag=0
item=item.strip().replace(":","").strip()
company=item
if item.find("description")==-1:
# print("Company:",company)
_company=company
signflag["Company"]=1
continue
################################################# NTE ##########################################################
if item.find("NTE")>-1:
item=item[item.find("NTE")+3:]
item=item.strip().replace(":","").strip()
signflag["NTE"]=1
# print("NTE:",item)
nte=item
continue
################################################# Amount Due ##########################################################
if item.find("Amount Due")>-1:
item=item[item.find("Amount Due")+10:]
item=item.strip().replace(":","").strip()
signflag["AmountDue"]=1
# print("Amount Due:",item)
amountdue=item
amountflag=1
continue
elif item.find("Ammount Due")>-1:
item=item[item.find("Amount Due")+12:]
item=item.strip().replace(":","").strip()
signflag["AmountDue"]=1
# print("Amount Due:",item)
amountdue=item
amountflag=1
continue
################################################# Tech name ##########################################################
if item.find("Tech full name")>-1:
item=item[item.find("Tech full name")+14:]
item=item.strip().replace(":","").strip()
techname=item
signflag["Techname"]=1
# print("Tech name:",techname)
_techname=techname
continue
elif amountflag==1 and techname=="":
amountflag=0
item=item.strip().replace(":","").strip()
signflag["Techname"]=1
# print("Tech name:",item)
_techname=item
continue
################################################# Tech number ##########################################################
if item.find("(")>-1 and item.find(")")>-1:
sidx=item.find("(")
eidx=item.find(")")
midx=item.find("-")
if eidx>sidx:
itemtmp=item[1:eidx-1]+item[eidx+1:midx-1]+item[midx+1:]
if re.match("^ *[0-9][0-9 ]*$", itemtmp):
Technumber=item
signflag["Technumber"]=1
# print("Tech number:",Technumber)
technumber=item
continue
if re.match("^ *[0-9][0-9 ]*$", item):
Technumber=item
signflag["Technumber"]=1
# print("Tech number:",Technumber)
technumber=item
continue
elif item.find("Tech Number")>-1:
item=item[item.find("Tech Number")+11:]
item=item.strip().replace(":","").strip()
signflag["Technumber"]=1
technumber=item
# print("Tech number:",item)
continue
################################################# Payment method ##########################################################
if item.find("Payment Method")>-1:
item=item[item.find("Payment Method")+14:]
item=item.strip().replace(":","").strip()
signflag["Paymentmethod"]=1
paymentmethod=item
# print("Payment Method:",item)
if item.find("Zelle")>-1 or item.find("zelle")>-1 :
pmethodflag=2
continue
elif item.find("Cashapp")>-1:
pmethodflag=3
continue
else:
pmethodflag=1
continue
if pmethodflag==2:
pmethodflag=0
item=item.strip().replace(":","").strip()
if item.find("@")>-1:
signflag["Paymentmethod"]=1
paymentaddress=item
else:
paymentaddress=technumber
if pmethodflag==3:
pmethodflag=0
item=item.strip().replace(":","").strip()
if item.find("$")==0:
signflag["Paymentmethod"]=1
paymentaddress=item[1:]
if pmethodflag==1:
pmethodflag=0
item=item.strip().replace(":","").strip()
if item.find("@")>-1:
signflag["Paymentmethod"]=1
paymentaddress=item
# print("Payment Address:",item)
################################################# Job Location ##########################################################
if item.find("Service Location")>-1:
item=item[item.find("Service Location")+16:]
item=item.strip().replace(":","").strip()
signflag["Joblocation"]=1
joblocation=item
# print("Job Location:",item)
continue
elif item.find("Service location")>-1:
item=item[item.find("Service location")+16:]
item=item.strip().replace(":","").strip()
if item!="":
signflag["Joblocation"]=1
# print("Job Location:",item)
joblocation=item
continue
else:
jlocationflag=1
continue
elif item.find("Job Location")>-1:
item=item[item.find("Job Location")+12:]
item=item.strip().replace(":","").strip()
if item!="":
signflag["Joblocation"]=1
joblocation=item
# print("Job Location:",item)
continue
else:
jlocationflag=1
continue
if jlocationflag==1:
item=item.strip().replace(":","").strip()
jlocationflag=0
signflag["Joblocation"]=1
joblocation=item
# print("Job Location:",item)
continue
################################################# Job status ##########################################################
if item.find("Job status")>-1 and signflag["Jobstatus"]!=1:
item=item[item.find("Job status")+10:]
item=item.strip().replace(":","").strip()
if item!="":
signflag["Jobstatus"]=1
# print("Job status:",item)
jobstatus=item
continue
else:
jStatusflag=1
continue
elif item.find("Assessment")>-1 and signflag["Jobstatus"]!=1:
signflag["Jobstatus"]=1
jobstatus=item
# print("Job status:",item)
if jStatusflag==1 and signflag["Jobstatus"]!=1:
item=item.strip().replace(":","").strip()
jStatusflag=0
signflag["Jobstatus"]=1
jobstatus=item
# print("Job status:",item)
################################################# Overall ##########################################################
if item.find("Overall")>-1:
item=item[item.find("Overall")+7:]
item=item.strip().replace(":","").strip()
item=item[item.find("$"):]
signflag["Overall"]=1
# print("Overall:",item)
overall=item
continue
################################################# Total ##########################################################
if item.find("Total")>-1:
item=item[item.find("Total")+5:]
item=item.strip().replace(":","").strip()
if len(item.split())==1:
signflag["TotalPrice"]=1
# print("Total Price:",item)
totalprice=item
continue
elif item.find("Grand total")>-1:
item=item[item.find("Grand total")+11:]
item=item.strip().replace(":","").strip()
signflag["TotalPrice"]=1
# print("Total Price:",item)
totalprice=item
continue
elif item.find("Grand Total")>-1:
item=item[item.find("Grand Total")+11:]
item=item.strip().replace(":","").strip()
signflag["TotalPrice"]=1
# print("Total Price:",item)
totalprice=item
continue
elif item.find("GRAND TOTAL")>-1:
item=item[item.find("GRAND TOTAL")+11:]
item=item.strip().replace(":","").strip()
signflag["TotalPrice"]=1
# print("Total Price:",item)
totalprice=item
continue
################################################# Quote Description ##########################################################
if signflag["qDetails"]==1:
quotedetails=item
signflag["qDetails"]=0
continue
if signflag["qDescription"]==1:
qotedescription=qotedescription+'\n'+item
continue
if item.find("Description :")>-1 or item.find("job description")>-1:
signflag["kind"]="Quote"
signflag["qDescription"]=1
continue
else:
if signflag["WorkOrder"]==1 and signflag["qDescription"]==0:
signflag["qDescription"]=1
continue
elif signflag["qDescription"]==1:
signflag["qDescription"]=0
signflag["qDetails"]=1
continue
# if quote_descriptionflag and signflag["WorkOrder"]==1:
# quote_description=quote_description+item
# if quote_detailflag and quote_descriptionflag and signflag["WorkOrder"]==1:
# quote_detail=item
# quote_detailflag=False
# quotedetails=quote_detail
# quote_detail=""
# else:
# if not quote_descriptionflag and signflag["WorkOrder"]==1:
# quote_descriptionflag=True
# else:
# quote_detailflag=True
# quote_descriptionflag=False
# qotedescription=quote_description
# quote_description=""
index=index+1
data_row={
"WorkOrder":_workorder,
"Date":date,
"Dispatcher":dispatcher,
"Company":_company,
"NTE":nte,
"AmountDue":amountdue,
"Techname":_techname,
"Technumber":technumber,
"Paymentmethod":paymentmethod,
"PaymentAddress":paymentaddress,
"JobLocation":joblocation,
"JobStatus":jobstatus,
"Overall":overall,
"Photos":"",
"QuoteDescription":qotedescription,
"QuoteDetails":quotedetails,
"TotalPrice":totalprice,
"kind":""
}
if signflag["Paymentmethod"]==1 or signflag["Paymentaddress"]==1 or signflag["Techname"]==1 or signflag["Technumber"]==1 :
signflag["kind"]="Payment"
data_row["kind"]="payment"
else:
signflag["kind"]="Quote"
data_row["kind"]="quote"
datarow.append(data_row)
j=j+1
step=1
while step<5:
for imageitem in imglist:
if datarow[len(datarow)-1-step]["Dispatcher"]==imageitem["user"]:
datarow[len(datarow)-1-step]["Photos"]=imageitem["images"]
imageitem["user"]=""
step=step+1
os.mkdir("output")
df = pd.DataFrame(datarow)
out_quote=[]
out_payment=[]
for item in datarow:
if item["WorkOrder"]!="":
if item["kind"]=="quote":
out_quote.append(item)
if item["Photos"]!="":
srcimgs=item["Photos"].split(",")
dist="output/"+item["WorkOrder"].strip()+"_"+item["Date"].strftime("%m_%d_%Y_%H_%M_%S")+"-quote"
os.mkdir(dist)
for srcs in srcimgs:
src='input/'+srcs.strip()
shutil.copy(src,dist+"/")
if item["kind"]=="payment":
out_payment.append(item)
if item["Photos"]!="":
srcimgs=item["Photos"].split(",")
dist="output/"+item["WorkOrder"].strip()+"_"+item["Date"].strftime("%m_%d_%Y_%H_%M_%S")+"-payment"
os.mkdir(dist)
for srcs in srcimgs:
src='input/'+srcs.strip()
shutil.copy(src,dist+"/")
df_quote=pd.DataFrame(out_quote)
df_payment=pd.DataFrame(out_payment)
df1=df_quote[["WorkOrder","Date","Dispatcher","Company","NTE","AmountDue","Techname","Technumber", "Paymentmethod","PaymentAddress","JobLocation","JobStatus","Overall","Photos"]]
df2=df_payment[["WorkOrder","Date","Dispatcher","Company","QuoteDescription","QuoteDetails","TotalPrice","Photos"]]
# df2.to_excel('output_quote.xlsx', index=False)
# df1.to_excel('output_payment.xlsx', index=False)
wb = Workbook()
sheet = wb.active
k=0
sheet.cell(row=1, column=1).value = "WorkOrder"
sheet.cell(row=1, column=2).value = "Date"
sheet.cell(row=1, column=3).value = "Dispatcher"
sheet.cell(row=1, column=4).value = "Company"
sheet.cell(row=1, column=5).value = "QuoteDescription"
sheet.cell(row=1, column=6).value = "QuoteDetails"
sheet.cell(row=1, column=7).value = "TotalPrice"
while k<len(out_quote):
if out_quote[k]["Photos"]!="":
link="output/"+out_quote[k]["WorkOrder"].strip()+"_"+out_quote[k]["Date"].strftime("%m_%d_%Y_%H_%M_%S")+"-quote/"
sheet.cell(row=k+2, column=1).hyperlink = link
sheet.cell(row=k+2, column=1).style = "Hyperlink"
sheet.cell(row=k+2, column=1).value = out_quote[k]["WorkOrder"]
sheet.cell(row=k+2, column=2).value = out_quote[k]["Date"]
sheet.cell(row=k+2, column=3).value = out_quote[k]["Dispatcher"]
sheet.cell(row=k+2, column=4).value = out_quote[k]["Company"]
sheet.cell(row=k+2, column=5).value = out_quote[k]["QuoteDescription"]
sheet.cell(row=k+2, column=6).value = out_quote[k]["QuoteDetails"]
sheet.cell(row=k+2, column=7).value = out_quote[k]["TotalPrice"]
k=k+1
wb.save("output_quote.xlsx")
wb1 = Workbook()
sheet1 = wb1.active
k=0
sheet1.cell(row=1, column=1).value = "WorkOrder"
sheet1.cell(row=1, column=2).value = "Date"
sheet1.cell(row=1, column=3).value = "Dispatcher"
sheet1.cell(row=1, column=4).value = "Company"
sheet1.cell(row=1, column=5).value = "NTE"
sheet1.cell(row=1, column=6).value = "AmountDue"
sheet1.cell(row=1, column=7).value = "Techname"
sheet1.cell(row=1, column=8).value = "Technumber"
sheet1.cell(row=1, column=9).value = "Paymentmethod"
sheet1.cell(row=1, column=10).value = "PaymentAddress"
sheet1.cell(row=1, column=11).value = "JobLocation"
sheet1.cell(row=1, column=12).value = "JobStatus"
sheet1.cell(row=1, column=13).value = "Overall"
while k<len(out_payment):
if out_payment[k]["Photos"]!="":
link="output/"+out_payment[k]["WorkOrder"].strip()+"_"+out_payment[k]["Date"].strftime("%m_%d_%Y_%H_%M_%S")+"-payment"
sheet1.cell(row=k+2, column=1).hyperlink = link
sheet1.cell(row=k+2, column=1).style = "Hyperlink"
sheet1.cell(row=k+2, column=1).value = out_payment[k]["WorkOrder"]
sheet1.cell(row=k+2, column=2).value = out_payment[k]["Date"]
sheet1.cell(row=k+2, column=3).value = out_payment[k]["Dispatcher"]
sheet1.cell(row=k+2, column=4).value = out_payment[k]["Company"]
sheet1.cell(row=k+2, column=5).value = out_payment[k]["NTE"]
sheet1.cell(row=k+2, column=6).value = out_payment[k]["AmountDue"]
sheet1.cell(row=k+2, column=7).value = out_payment[k]["Techname"]
sheet1.cell(row=k+2, column=8).value = out_payment[k]["Technumber"]
sheet1.cell(row=k+2, column=9).value = out_payment[k]["Paymentmethod"]
sheet1.cell(row=k+2, column=10).value = out_payment[k]["PaymentAddress"]
sheet1.cell(row=k+2, column=11).value = out_payment[k]["JobLocation"]
sheet1.cell(row=k+2, column=12).value = out_payment[k]["JobStatus"]
sheet1.cell(row=k+2, column=13).value = out_payment[k]["Overall"]
k=k+1
wb1.save("output_payment.xlsx")