Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
ceroberoz committed Sep 20, 2024
2 parents 0fbd3c1 + 160b7a5 commit 3da4762
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
id-jobs collects job listings from Indonesian job portals and company websites, respecting each site's terms of service.

**View the Data on Google Sheets:** [https://s.id/id-jobs-v2](https://s.id/id-jobs-v2)

**View the Dasboard on LookerStudio by Google:** [https://s.id/id-jobs-dashboard](https://s.id/id-jobs-dashboard)

## 🎨 Job Age Colors
Expand Down
26 changes: 22 additions & 4 deletions pipeline/upload_to_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ def get_dynamic_range(data):
num_cols = len(data[0]) if data else 0
return f"Sheet1!A1:{chr(65 + num_cols - 1)}{num_rows}"

def clear_sheet(service, spreadsheet_id):
sheet_metadata = service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute()
properties = sheet_metadata.get('sheets', [])[0].get('properties', {})
sheet_id = properties.get('sheetId', 0)

requests = [{
"updateCells": {
"range": {
"sheetId": sheet_id,
},
"fields": "userEnteredValue"
}
}]

body = {
'requests': requests
}
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=body).execute()
print("Sheet cleared successfully.")

def upload_to_sheets(service, spreadsheet_id, data):
config.sheet_range = get_dynamic_range(data)
body = {'values': data}
Expand All @@ -303,10 +323,8 @@ def upload_to_sheets(service, spreadsheet_id, data):
spreadsheet = service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute()
print(f"Successfully accessed spreadsheet: {spreadsheet['properties']['title']}")

service.spreadsheets().values().clear(
spreadsheetId=spreadsheet_id,
range=config.sheet_range
).execute()
# Clear the entire sheet
clear_sheet(service, spreadsheet_id)

result = service.spreadsheets().values().update(
spreadsheetId=spreadsheet_id,
Expand Down

0 comments on commit 3da4762

Please sign in to comment.