Marthee commited on
Commit
7f7c726
·
verified ·
1 Parent(s): c1e1ef9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +152 -46
app.py CHANGED
@@ -28,6 +28,8 @@ import MC_Templates_API
28
  import tsadropboxretrieval
29
  import doc_search
30
  import threading
 
 
31
 
32
  app = Flask(__name__)
33
 
@@ -65,6 +67,7 @@ def getprjSectionsfromTestAPI(jsdata):
65
  def get_javascript_data(jsdata):
66
  #get project from the first dropdown
67
  # jsdata=eval(jsdata)
 
68
  documnetsToMeasure,RelevantDocuments=tsadropboxretrieval.retrieveProjects(jsdata)
69
  if RelevantDocuments:
70
  return jsonify ([documnetsToMeasure, RelevantDocuments])
@@ -111,6 +114,7 @@ def CallAPIforMCTNames():
111
  # print(jsdata)
112
  DictionaryOfTemplates=MC_Templates_API.RetrieveMC_Templates_API()
113
  # jsdata=jsdata.replace('"', '')
 
114
  return jsonify(DictionaryOfTemplates) #[str(jsdata).lower()]
115
 
116
  #_________________________________________________________________________________________________________________________
@@ -237,7 +241,7 @@ def convert2img(path):
237
  def sendmctnametoLegend(jsdata):
238
  result = json.loads(jsdata)
239
  print(result)
240
- summaryid=pilecaps_adr.mapnametoLegend(result)
241
  allreturns=[summaryid]
242
  return jsonify(allreturns)
243
  #_________________________________________________________________________________________________________________________
@@ -361,15 +365,15 @@ def dltmarkupslegend():
361
  deletedrows=pd.DataFrame(myDict)
362
 
363
  if section.startswith('1.0'):
364
- newlgnd=pilecaps_adr.deletefromlegend(deletedrows=deletedrows,SimilarAreaDictionarycopy=SimilarAreaDictionary, section=section,areaPermArr=areaPermArr)
365
  else:
366
- newlgnd=pilecaps_adr.deletefromlegend(deletedrows=deletedrows,SimilarAreaDictionarycopy=SimilarAreaDictionary, section=section)
367
  try:
368
- newlgnd1=pilecaps_adr.legendGoogleSheets(SimilarAreaDictionary=newlgnd,path=path,spreadsheetId=spreadsheetId ,pdfpath=pdfpth) #new legend
369
  except:
370
  print("An exception occurred")
371
  time.sleep(10)
372
- newlgnd1=pilecaps_adr.legendGoogleSheets(SimilarAreaDictionary=newlgnd,path=path,spreadsheetId=spreadsheetId,pdfpath=pdfpth)
373
 
374
  return jsonify('donee')
375
 
@@ -388,7 +392,7 @@ def calldropboxurl(jsdata):
388
  #Google sheet links
389
  @app.route('/getdrivelinks/<jsdata>',methods=["GET", "POST"])
390
  def getlinkscreated(jsdata):
391
- spreadsheet_service,drive_service,gc= pilecaps_adr.authorizeLegend()
392
  ids=gc.spreadsheet_ids()
393
  titles=gc.spreadsheet_titles()
394
  allpaths=[]
@@ -410,18 +414,14 @@ def returnAPITables():
410
 
411
  @app.route('/refreshAPI',methods=["GET", "POST"])
412
  def checktables():
413
- # sectionData = request.args.get('sectionData')
414
- # sectionData = request.args.get('sectionData')
415
- # print(sectionData)
416
  table1,table2,table3=API.GenerateTables()
417
- # if sectionData!='noSectionYet':
418
- # DictionaryOfTemplates=MC_Templates_API.RetrieveMC_Templates_API()
419
- # sectionData=sectionData.replace('"', '')
420
- # DictionaryOfTemplates[str(sectionData).lower()]
421
  url_1 = prjnamesURL.replace('/edit#gid=', '/export?format=csv&gid=')
422
  url_2 = prjpartsURL.replace('/edit#gid=', '/export?format=csv&gid=')
423
  url_3 = prjsectionsURL.replace('/edit#gid=', '/export?format=csv&gid=')
424
-
425
  table1N = pd.read_csv(url_1)
426
  table2N = pd.read_csv(url_2)
427
  table3N = pd.read_csv(url_3)
@@ -429,45 +429,134 @@ def checktables():
429
  t1Diff=table1N[~table1N.isin(table1)].dropna()
430
  t1Diff1=table1[~table1.isin(table1N)].dropna()
431
 
432
- t2Diff=table2N[~table2N.isin(table2)].dropna()
433
- t2Diff1=table2[~table2.isin(table2N)].dropna()
434
 
435
- t3Diff=table3N[~table3N.isin(table3)].dropna()
436
- t3Diff1=table3[~table3.isin(table3N)].dropna()
 
437
 
438
- # print(t1Diff,t1Diff1)
439
- # print(t2Diff,t2Diff1)
440
- # print(t3Diff,t3Diff1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  returnString=''
442
- if (not t1Diff.empty) or (not t1Diff1.empty) :
443
- returnString=''
444
- returnString=['Changes have been made in Projects. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','project']
445
- elif (not t2Diff.empty) or (not t2Diff1.empty):
446
- returnString=''
447
- returnString=['Changes have been made in Parts. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','part']
448
- elif (not t3Diff.empty) or (not t3Diff1.empty):
449
- returnString=''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
 
451
- returnString=['Changes have been made in Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','section']
452
- elif ((not t1Diff.empty) or (not t1Diff1.empty)) and ((not t2Diff.empty) or ( not t2Diff1.empty)):
453
- returnString=''
454
- returnString=['Changes have been made in Projects and Parts. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','projectpart']
455
- elif ((not t1Diff.empty) or (not t1Diff1.empty)) and ((not t3Diff.empty) or (not t3Diff1.empty) ):
456
- returnString=''
457
- returnString=['Changes have been made in Projects and Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','projectsection']
458
- elif ((not t2Diff.empty) or (not t2Diff1.empty)) and ((not t3Diff.empty) or (not t3Diff1.empty)):
459
- returnString=''
460
- returnString=['Changes have been made in Parts and Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','partsection']
461
- elif ((not t1Diff.empty) or (not t1Diff1.empty)) and ((not t2Diff.empty) or (not t2Diff1.empty)) and ((not t3Diff.empty) or (not t3Diff1.empty)):
462
- returnString=''
463
- returnString=['Changes have been made in Projects, Parts and Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','project']
464
- else:
465
- print('No updates in the API')
466
  # if sectionData!='noSectionYet':
467
  # return jsonify([returnString,DictionaryOfTemplates])
468
  # else:
 
 
469
  return jsonify(returnString)
470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
 
472
  @app.route('/refreshDropbox',methods=["GET", "POST"])
473
  def checkdropbox():
@@ -500,10 +589,24 @@ def postDropboxprojectsinConsole():
500
 
501
  @app.route('/refreshAPIAppendNewTables',methods=["GET", "POST"])
502
  def appendNewTables():
503
- value = request.args.get('keyword')
504
- print(value)
505
  API.AppendtablestoSheets()
506
  return jsonify('appended')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
 
508
  #_________________________________________________________________________________________________________________________
509
  #_________________________________________________________________________________________________________________________
@@ -513,6 +616,9 @@ def appendNewTables():
513
 
514
  #_________________________________________________________________________________________________________________________
515
  #_________________________________________________________________________________________________________________________
 
 
 
516
 
517
  if __name__ == "__main__":
518
  app.run(host="0.0.0.0", port=7860)
 
28
  import tsadropboxretrieval
29
  import doc_search
30
  import threading
31
+ import google_sheet_Legend
32
+ import google_sheet_to_xml
33
 
34
  app = Flask(__name__)
35
 
 
67
  def get_javascript_data(jsdata):
68
  #get project from the first dropdown
69
  # jsdata=eval(jsdata)
70
+ print('tsa')
71
  documnetsToMeasure,RelevantDocuments=tsadropboxretrieval.retrieveProjects(jsdata)
72
  if RelevantDocuments:
73
  return jsonify ([documnetsToMeasure, RelevantDocuments])
 
114
  # print(jsdata)
115
  DictionaryOfTemplates=MC_Templates_API.RetrieveMC_Templates_API()
116
  # jsdata=jsdata.replace('"', '')
117
+ print('here')
118
  return jsonify(DictionaryOfTemplates) #[str(jsdata).lower()]
119
 
120
  #_________________________________________________________________________________________________________________________
 
241
  def sendmctnametoLegend(jsdata):
242
  result = json.loads(jsdata)
243
  print(result)
244
+ summaryid=google_sheet_Legend.mapnametoLegend(result)
245
  allreturns=[summaryid]
246
  return jsonify(allreturns)
247
  #_________________________________________________________________________________________________________________________
 
365
  deletedrows=pd.DataFrame(myDict)
366
 
367
  if section.startswith('1.0'):
368
+ newlgnd=google_sheet_Legend.deletefromlegend(deletedrows=deletedrows,SimilarAreaDictionarycopy=SimilarAreaDictionary, section=section,areaPermArr=areaPermArr)
369
  else:
370
+ newlgnd=google_sheet_Legend.deletefromlegend(deletedrows=deletedrows,SimilarAreaDictionarycopy=SimilarAreaDictionary, section=section)
371
  try:
372
+ newlgnd1=google_sheet_Legend.legendGoogleSheets(SimilarAreaDictionary=newlgnd,path=path,spreadsheetId=spreadsheetId ,pdfpath=pdfpth) #new legend
373
  except:
374
  print("An exception occurred")
375
  time.sleep(10)
376
+ newlgnd1=google_sheet_Legend.legendGoogleSheets(SimilarAreaDictionary=newlgnd,path=path,spreadsheetId=spreadsheetId,pdfpath=pdfpth)
377
 
378
  return jsonify('donee')
379
 
 
392
  #Google sheet links
393
  @app.route('/getdrivelinks/<jsdata>',methods=["GET", "POST"])
394
  def getlinkscreated(jsdata):
395
+ spreadsheet_service,drive_service,gc= google_sheet_Legend.authorizeLegend()
396
  ids=gc.spreadsheet_ids()
397
  titles=gc.spreadsheet_titles()
398
  allpaths=[]
 
414
 
415
  @app.route('/refreshAPI',methods=["GET", "POST"])
416
  def checktables():
417
+ projectname = request.args.get('prjname')
418
+ projectpart = request.args.get('prjpart')
419
+ print('hgh',projectname , projectpart)
420
  table1,table2,table3=API.GenerateTables()
 
 
 
 
421
  url_1 = prjnamesURL.replace('/edit#gid=', '/export?format=csv&gid=')
422
  url_2 = prjpartsURL.replace('/edit#gid=', '/export?format=csv&gid=')
423
  url_3 = prjsectionsURL.replace('/edit#gid=', '/export?format=csv&gid=')
424
+
425
  table1N = pd.read_csv(url_1)
426
  table2N = pd.read_csv(url_2)
427
  table3N = pd.read_csv(url_3)
 
429
  t1Diff=table1N[~table1N.isin(table1)].dropna()
430
  t1Diff1=table1[~table1.isin(table1N)].dropna()
431
 
432
+ t2Diff=pd.DataFrame()
433
+ t2Diff1=pd.DataFrame()
434
 
435
+ t3Diff=pd.DataFrame()
436
+ t3Diff1=pd.DataFrame()
437
+
438
 
439
+ if projectname:
440
+ print('here')
441
+ differentParts=[]
442
+ a = table1N.to_numpy()
443
+ row = np.where(a == projectname)
444
+ print(projectname,row)
445
+ returnString=''
446
+ t2Diff1=table2[~table2.isin(table2N)].dropna()
447
+ t2Diff=table2N[~table2N.isin(table2)].dropna()
448
+
449
+ if projectpart and projectname:
450
+
451
+ a1 = table1N.to_numpy()
452
+ row1 = np.where(a1 == projectname)
453
+ prjid=a1[row1[0]][0][0]
454
+ a2 = table2N.to_numpy()
455
+ row2 = np.where(a2 == projectpart)
456
+ partid=a2[row2[0]][0][1]
457
+
458
+ t3Diff1=table3[~table3.isin(table3N)].dropna()
459
+ t3Diff=table3N[~table3N.isin(table3)].dropna()
460
+
461
  returnString=''
462
+ if not t1Diff.empty or not t1Diff1.empty :
463
+ if not t1Diff.empty:
464
+ newvalues= t1Diff['ProjectName'].values
465
+ else:
466
+ newvalues= t1Diff1['ProjectName'].values
467
+ returnString=''
468
+ returnString=['Changes have been made in Projects. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','project',(newvalues).tolist(),table2.to_dict()]
469
+ if (not t2Diff.empty)or( not t2Diff1.empty) :
470
+ print(t2Diff,t2Diff1)
471
+ if projectname:
472
+ for i in range(len(t2Diff1['ProjectId'].values)):
473
+ print(t2Diff1['ProjectId'].values[i] ,a[row[0]][0][0])
474
+ if int(t2Diff1['ProjectId'].values[i]) ==int(a[row[0]][0][0]):
475
+ differentParts.append(t2Diff1['ProjectPart'].iloc[i])
476
+ if len(differentParts)>0:
477
+ returnString=['Changes have been made in Parts. Would you like to retrieve them in the console?','part',differentParts]
478
+ print(returnString)
479
+
480
+ if (not t3Diff.empty) or (not t3Diff1.empty) :
481
+ differentSections=[]
482
+ if projectpart and projectname:
483
+ print(t3Diff1)
484
+
485
+ roww=t3Diff1.iloc[np.where((t3Diff1['ProjectId']==str(prjid) ) & (t3Diff1['ProjectPartId']==str(partid)) ) ]
486
+ # print(prjid,partid,roww.shape[0] )
487
+ for i in range(len(roww['ProjectId'].values)):
488
+ if roww.shape[0]>0:
489
+ print(roww['ProjectSection'].iloc[i] )
490
+ differentSections.append(str(roww['ProjectSection'].iloc[i]))
491
+ print(differentSections)
492
+ if len(differentSections)>0:
493
+ returnString=['Changes have been made in Sections. Would you like to retrieve them in the console?','section',differentSections]
494
+ print(differentSections)
495
+
496
+ # if not t2Diff.empty:
497
+ # newvalues= t2Diff['ProjectName'].values
498
+ # else:
499
+ # newvalues= t2Diff1['ProjectName'].values
500
+ # returnString=''
501
+ # returnString=['Changes have been made in Parts. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','part']
502
+ # elif (not t3Diff.empty) or (not t3Diff1.empty):
503
+ # returnString=''
504
 
505
+ # returnString=['Changes have been made in Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','section']
506
+ # elif ((not t1Diff.empty) or (not t1Diff1.empty)) and ((not t2Diff.empty) or ( not t2Diff1.empty)):
507
+ # returnString=''
508
+ # returnString=['Changes have been made in Projects and Parts. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','projectpart']
509
+ # elif ((not t1Diff.empty) or (not t1Diff1.empty)) and ((not t3Diff.empty) or (not t3Diff1.empty) ):
510
+ # returnString=''
511
+ # returnString=['Changes have been made in Projects and Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','projectsection']
512
+ # elif ((not t2Diff.empty) or (not t2Diff1.empty)) and ((not t3Diff.empty) or (not t3Diff1.empty)):
513
+ # returnString=''
514
+ # returnString=['Changes have been made in Parts and Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','partsection']
515
+ # elif ((not t1Diff.empty) or (not t1Diff1.empty)) and ((not t2Diff.empty) or (not t2Diff1.empty)) and ((not t3Diff.empty) or (not t3Diff1.empty)):
516
+ # returnString=''
517
+ # returnString=['Changes have been made in Projects, Parts and Sections. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','project']
518
+ print(returnString)
 
519
  # if sectionData!='noSectionYet':
520
  # return jsonify([returnString,DictionaryOfTemplates])
521
  # else:
522
+ # returnString=prjpartsRefreshAPItable2(table2,projectname)
523
+
524
  return jsonify(returnString)
525
 
526
+ # @app.route('/getnewparts',methods=["GET", "POST"])
527
+
528
+
529
+ def prjsectionsRefreshAPItable3(table3,projectname,projectpart):
530
+ # table1,table2,table3=API.GenerateTables()
531
+ # projectname = request.args.get('prjname')
532
+
533
+ url_1 = prjnamesURL.replace('/edit#gid=', '/export?format=csv&gid=')
534
+ table1N = pd.read_csv(url_1)
535
+
536
+ url_2 = prjpartsURL.replace('/edit#gid=', '/export?format=csv&gid=')
537
+ table2N = pd.read_csv(url_2)
538
+
539
+ url_3 = prjsectionsURL.replace('/edit#gid=', '/export?format=csv&gid=')
540
+ table3N = pd.read_csv(url_3)
541
+
542
+ differentSections=[]
543
+ returnString=''
544
+ t3Diff1=table3[~table3.isin(table3N)].dropna()
545
+ t3Diff=table3N[~table3N.isin(table3)].dropna()
546
+
547
+ a1 = table1N.to_numpy()
548
+ row = np.where(a1 == projectname)
549
+ prjid=a1[row[0]][0][0]
550
+ a2 = table2N.to_numpy()
551
+ row2 = np.where(a2 == projectpart)
552
+ partid=a2[row2[0]][0][1]
553
+
554
+ for i in range(len(t3Diff['ProjectId'].values)):
555
+ roww=table3N.iloc[np.where((table3N['ProjectId']==prjid) & (table3N['ProjectPartId']==partid) ) ]
556
+ differentSections.append(roww['ProjectSection'].iloc[i])
557
+ # returnString=['Changes have been made in Parts. Would you like to retrieve them in the console?','part',differentParts]
558
+ print(differentSections)
559
+ return returnString
560
 
561
  @app.route('/refreshDropbox',methods=["GET", "POST"])
562
  def checkdropbox():
 
589
 
590
  @app.route('/refreshAPIAppendNewTables',methods=["GET", "POST"])
591
  def appendNewTables():
592
+ # value = request.args.get('keyword')
593
+ # print(value)
594
  API.AppendtablestoSheets()
595
  return jsonify('appended')
596
+
597
+
598
+ @app.route('/summarytoXML/<jsdata>',methods=["GET", "POST"])
599
+ def cvtSummarytoXML(jsdata):
600
+ path='/TSA Team Folder/ADR Test/'
601
+ result = json.loads(jsdata)
602
+ for word in result[0]:
603
+ path+=word +'/'
604
+ print(path)
605
+ path=path+'XML/'
606
+ # print(result[0])
607
+ # print(result[1])
608
+ xmllink=google_sheet_to_xml.create_xml(documentname=result[1],dbPath=path)
609
+ return jsonify(xmllink)
610
 
611
  #_________________________________________________________________________________________________________________________
612
  #_________________________________________________________________________________________________________________________
 
616
 
617
  #_________________________________________________________________________________________________________________________
618
  #_________________________________________________________________________________________________________________________
619
+ # if __name__ == "__main__":
620
+ # app.run(debug=True)
621
+
622
 
623
  if __name__ == "__main__":
624
  app.run(host="0.0.0.0", port=7860)