| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | import requests |
| | |
| | import pandas as pd |
| | |
| | |
| | |
| | import queue |
| | |
| | |
| | from googleapiclient.discovery import build |
| | from google.oauth2 import service_account |
| | import pygsheets |
| | import numpy as np |
| | |
| | |
| | |
| |
|
| | prjnamesURL= 'https://docs.google.com/spreadsheets/d/1n8AG8_lCyhh1X97Dg3ZwWUXRUm-G2JdIUgQBTzE4qgc/export?format=csv&gid=0' |
| | prjpartsURL= 'https://docs.google.com/spreadsheets/d/1n8AG8_lCyhh1X97Dg3ZwWUXRUm-G2JdIUgQBTzE4qgc/export?format=csv&gid=1481952020' |
| | prjsectionsURL= 'https://docs.google.com/spreadsheets/d/1n8AG8_lCyhh1X97Dg3ZwWUXRUm-G2JdIUgQBTzE4qgc/export?format=csv&gid=175272726' |
| |
|
| | dfNames=pd.DataFrame() |
| | dfParts=pd.DataFrame() |
| | que= queue.Queue() |
| | returnString='' |
| | |
| | def AuthorizeGoogleSheets(): |
| | SCOPES = [ |
| | 'https://www.googleapis.com/auth/spreadsheets', |
| | 'https://www.googleapis.com/auth/drive' |
| | ] |
| | credentials = service_account.Credentials.from_service_account_file('credentials.json', scopes=SCOPES) |
| | spreadsheet_service = build('sheets', 'v4', credentials=credentials) |
| | drive_service = build('drive', 'v3', credentials=credentials) |
| | gc = pygsheets.authorize(custom_credentials=credentials, client_secret='credentials.json') |
| | print('ayhagaaa') |
| | return spreadsheet_service,drive_service,gc |
| |
|
| | |
| | def createSheet(): |
| | spreadsheet_service,drive_service,gc=AuthorizeGoogleSheets() |
| | |
| | titles=gc.spreadsheet_titles() |
| | if 'API tables Output' in titles: |
| | ws=gc.open(str('API tables Output')) |
| | spreadsheetId=ws.id |
| | else: |
| | spreadsheet_details = { |
| | 'properties': { |
| | 'title': 'API tables Output' |
| | } |
| | } |
| | sheet = spreadsheet_service.spreadsheets().create(body=spreadsheet_details, |
| | fields='spreadsheetId').execute() |
| |
|
| | spreadsheetId = sheet.get('spreadsheetId') |
| | permission1 = { |
| | 'type': 'anyone', |
| | 'role': 'writer', |
| | |
| | } |
| | drive_service.permissions().create(fileId=spreadsheetId, body=permission1).execute() |
| |
|
| | ws = gc.open_by_key(spreadsheetId) |
| | projectNamesSheet = ws.worksheet(0) |
| |
|
| | projectNamesSheet.title='Project Names' |
| | ws.add_worksheet("Project Parts") |
| | ws.add_worksheet("Sections") |
| | print('SPREADHSEET IDDDD=====',spreadsheetId) |
| | return ws,gc,spreadsheetId |
| |
|
| |
|
| | |
| | |
| |
|
| | |
| | def APIValues(): |
| | query={'loginname':'Marthe','password':'marthemain'} |
| | |
| | head={'Content-Type':'application/json'} |
| | response=requests.post(url="https://console.trevorsadd.co.uk/account/login",json=query,headers=head,verify=False) |
| | key=response.text |
| |
|
| | head={'Content-Type':'application/json;charset=UTF-8',"Authorization":'Bearer {}'.format(key)} |
| | response=requests.post(url="https://console.trevorsadd.co.uk/project/getprojectslist",json=query,headers=head,verify=False) |
| | dict1=response.json() |
| | |
| | return dict1 |
| |
|
| | |
| | |
| |
|
| | |
| | def GenerateTables(): |
| | |
| | dict1=APIValues() |
| |
|
| | |
| | |
| | |
| | table1=pd.DataFrame(columns= ['ProjectId','ProjectName']) |
| | table2=pd.DataFrame(columns= ['ProjectId','ProjectPartId','ProjectPart']) |
| | table3=pd.DataFrame(columns= ['ProjectId','ProjectPartId','ProjectSection']) |
| | for item in dict1: |
| | table1 = pd.concat([table1, pd.DataFrame([[item.get('id'),item.get('projectname')]], columns=table1.columns)], ignore_index=True) |
| | projectPartsList=item.get('projectparts') |
| | for part in projectPartsList: |
| | table2= pd.concat([table2,pd.DataFrame([[item.get('id'),part.get('id'),part.get('name')]], columns=table2.columns)], ignore_index=True) |
| | sections=part.get('projectsections') |
| | for section in sections: |
| | table3= pd.concat([table3,pd.DataFrame([[item.get('id'),section.get('projectPartId'),section.get('section')]], columns=table3.columns)], ignore_index=True) |
| | |
| | |
| | |
| | return table1,table2,table3 |
| |
|
| | |
| | def AppendtablestoSheets(): |
| | gc=AuthorizeGoogleSheets()[2] |
| | |
| | ws = gc.open_by_key('1n8AG8_lCyhh1X97Dg3ZwWUXRUm-G2JdIUgQBTzE4qgc') |
| | table1,table2,table3= GenerateTables() |
| | projectNamesSheet=ws.worksheet_by_title('Project Names') |
| | projectPartsSheet=ws.worksheet_by_title('Project Parts') |
| | projectSectionsSheet=ws.worksheet_by_title('Sections') |
| | projectNamesSheet.clear() |
| | projectPartsSheet.clear() |
| |
|
| | |
| | table1 = table1.drop_duplicates() |
| | table2 = table2.drop_duplicates() |
| | table3 = table3.drop_duplicates() |
| | projectNamesSheet.set_dataframe(start='A1',df=table1) |
| | projectPartsSheet.set_dataframe(start='A1',df=table2) |
| | projectSectionsSheet.clear() |
| | projectSectionsSheet.set_dataframe(start='A1',df=table3) |
| | |
| | |
| | |
| | |
| | |
| | def getPrjNames(url=prjnamesURL): |
| | |
| | |
| | df = pd.read_csv(prjnamesURL) |
| | return df['ProjectName'].tolist(), df['ProjectId'].tolist() |
| |
|
| | |
| | def getprjParts(chosenprjid,urlNames=prjnamesURL,urlparts=prjpartsURL): |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | global dfParts |
| | dfParts = pd.read_csv(prjpartsURL) |
| | print(chosenprjid,dfParts) |
| | dfParts= dfParts.iloc[np.where(dfParts['ProjectId']==int(chosenprjid))] |
| | parts=dfParts['ProjectPart'].tolist() |
| | partsIds=dfParts['ProjectPartId'].tolist() |
| | print(parts) |
| | print(partsIds) |
| | |
| | |
| | return parts,partsIds |
| |
|
| | |
| | def getprjSections(chosenprjid, chosenpartid,urlSection=prjsectionsURL): |
| | |
| | |
| | dfSections = pd.read_csv(prjsectionsURL) |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | if chosenprjid and chosenpartid: |
| | dfSections=dfSections.iloc[np.where((dfSections['ProjectId']==int(chosenprjid)) & (dfSections['ProjectPartId']==int(chosenpartid)) ) ] |
| | sections=dfSections['ProjectSection'].tolist() |
| | return sections |
| | else: |
| | return |
| |
|
| |
|
| | |
| |
|