Skip to content

Service to notify about upcoming ingredient's write-offs in google sheets

License

Notifications You must be signed in to change notification settings

goretsky-integration/write-offs-notifications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 Write-offs notifications


Service to notify about upcoming ingredient's write-offs in google sheet.

⚙ Set up


1. Create config file in the of root of the project.

cp config.example.toml config.toml

2. Fill in the fields in the config.toml file.

Set up timezone.

timezone = "Europe/Moscow"

credentials_file_path - path to the file with google service account credentials.

How to get credentials?

A service account is a special type of Google account intended to represent a non-human user that needs to authenticate and be authorized to access data in Google APIs.

Since it’s a separate account, by default it does not have access to any spreadsheet until you share it with this account. Just like any other Google account.

Here’s how to get one:

  1. Enable API Access for a Project if you haven’t done it yet.

    🤔 How do I enable API Access? Enable API Access for a Project Head to Google Developers Console and create a new project (or select the one you already have).

    In the box labeled “Search for APIs and Services”, search for “Google Drive API” and enable it.

    In the box labeled “Search for APIs and Services”, search for “Google Sheets API” and enable it.

  2. Go to “APIs & Services > Credentials” and choose “Create credentials > Service account key”.

  3. Fill out the form

  4. Click “Create” and “Done”.

  5. Press “Manage service accounts” above Service Accounts.

  6. Press on ⋮ near recently created service account and select “Manage keys” and then click on “ADD KEY > Create new key”.

  7. Select JSON key type and press “Create”.

You will automatically download a JSON file with credentials. It may look like this:

{
  "type": "service_account",
  "project_id": "api-project-XXX",
  "private_key_id": "2cd … ba4",
  "private_key": "-----BEGIN PRIVATE KEY-----\nNrDyLw … jINQh/9\n-----END PRIVATE KEY-----\n",
  "client_email": "[email protected]",
  "client_id": "473 … hd.apps.googleusercontent.com"
}

Remember the path to the downloaded credentials file. Also, in the next step you’ll need the value of client_email from this file.

Very important! Go to your spreadsheet and share it with a client_email from the step above. Just like you do with any other Google account.

If you don’t do this, you’ll get a gspread.exceptions.SpreadsheetNotFound exception when trying to access this spreadsheet from your application or a script.


spreadsheet_key - you can get it from the URL of spreadsheet.

[google_sheets]
credentials_file_path = "/file/to/credentials.json"
spreadsheet_key = "jfsodijfiosdjijsfigjfg"

Base URL to the units storage service.

[units_storage]
base_url = "http url"

3. Create poetry virtual environment, activate it and install dependencies.

poetry env use python3.11
poetry shell
poetry install

4. Run

python src/main.py

About

Service to notify about upcoming ingredient's write-offs in google sheets

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages