{"id":15899014,"url":"https://github.com/danporter/google_logbooks","last_synced_at":"2025-04-02T19:14:26.071Z","repository":{"id":163825299,"uuid":"460897798","full_name":"DanPorter/google_logbooks","owner":"DanPorter","description":"Use Google Drive API to create experiment logbooks","archived":false,"fork":false,"pushed_at":"2022-02-21T12:14:30.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-08T09:45:39.819Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanPorter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-18T15:06:30.000Z","updated_at":"2022-02-18T15:07:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc45b220-9894-4f45-9247-635690efd40c","html_url":"https://github.com/DanPorter/google_logbooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fgoogle_logbooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fgoogle_logbooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fgoogle_logbooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fgoogle_logbooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanPorter","download_url":"https://codeload.github.com/DanPorter/google_logbooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246875909,"owners_count":20848049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-06T10:10:33.779Z","updated_at":"2025-04-02T19:14:26.052Z","avatar_url":"https://github.com/DanPorter.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# google_logbooks\nUse Google Drive API to create experiment logbooks\n\nBy Dan Porter, Diamond Light Source Ltd. 2022\n\n### Usage\nA *credentials.json* file is required and must be entered in the scripts for permission to communicate with GoogleDrive. [See below](#api_exp). \n####Command line usage\nRun a python script from an experiment_parameters.json file\n```bash\n$ python i16_google_logbook_maker.py /dls_sw/i16/scripts/2022/mm12345-1/mm12345-1.json\n```\n\nDownload the logbook to the scripts folder:\n```bash\n$ python i16_google_logbook_downloader.py /dls_sw/i16/scripts/2022/mm12345-1/mm12345-1.json\n```\n\n####Python Script usage\n\n```python\nimport i16_google_logbook_scripts\nfrom google_drive_api import GoogleDriveApi\n\ngdrive = GoogleDriveApi('credentials.json')\n\ndoc = gdrive.get_file('file_id')\n[doc, ] = gdrive.find_file('filename')\nlink = gdrive.get_link('file_id')\ngdrive.change_permission('file_id', can_edit=False)\ngdrive.upload('/path/to/file')\ndoc = gdrive.copy_file('id_to_copy', 'new_name')\ngdrive.merge_template('file_id', {'{{replace_me}}': 'with me'})\ngdrive.append_text('file_id', 'text to append')\ngdrive.append_image('file_id', 'loc/of/image.png')\ngdrive.download_pdf('file_id', 'file.pdf')\n\nprint(doc)  # shows filename, id, link\ndoc.merge({'{{replace_me}}': 'with me'})\ni16_google_logbook_scripts.append_text('text to append')\ni16_google_logbook_scripts.append_image('loc/of/image.png')\ndoc.download_pdf('file.pdf')\n```\n\n### Requires\n- python3 with Google API\n```bash\n$ pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib\n```\n\n### Google Drive API Explanation {#api_exp}\nhttps://console.cloud.google.com/apis/credentials?project=beamline-logbooks\u0026supportedpurview=project\n\n####First time Setup:\n1. Create a API project on https://console.cloud.google.com\n    - APIs + services \u003e create project\n2. Enable APIs \u0026 services \u003e Enable Google Drive API, Google Docs API\n3. Dashboard \u003e Configure Consent screen \u003e External\n    - Add scopes: all Google Drive, all Google Docs\n    - Add user: add your gmail account (you are not automatically a user!)\n4. Create credentials - Dashboard \u003e Credentials \u003e + Create Credentials \u003e OAuth 2.0 Client ID \u003e Desktop App\n    - Download json, rename client-id\n\nThis client ID file holds the credentials required to use the API, and must be accessed by the python program.\n\n####Python quickstart example:\n\nhttps://developers.google.com/drive/api/v3/quickstart/python\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanporter%2Fgoogle_logbooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanporter%2Fgoogle_logbooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanporter%2Fgoogle_logbooks/lists"}