Skip to content

try pydrive device client #9

try pydrive device client

try pydrive device client #9

Workflow file for this run

name: Temp Docflow API
on:
push:
branches: ['temp-docflow-*']
permissions:
contents: write
jobs:
device:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Start device flow via API commit
env:
GH_TOKEN: ${{ github.token }}
BRANCH: ${{ github.ref_name }}
REPO: ${{ github.repository }}
run: |
python3 - <<'PY'
import os, requests, json, time, base64, datetime
repo=os.environ['REPO']; branch=os.environ['BRANCH']; gh=os.environ['GH_TOKEN']
H={'Authorization':'Bearer '+gh,'Accept':'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28'}
def put(path, obj, msg):
url=f'https://api.github.com/repos/{repo}/contents/{path}'
old=requests.get(url,headers=H,params={'ref':branch})
payload={'message':msg,'content':base64.b64encode(json.dumps(obj,indent=2).encode()).decode(),'branch':branch}
if old.status_code==200: payload['sha']=old.json()['sha']
rr=requests.put(url,headers=H,json=payload,timeout=30)
print('PUT', path, rr.status_code, rr.text[:200])
try:
cid='415200970618.apps.googleusercontent.com'; secret='jpgtxTMwtbQkgWUi1cnSk56f'
scope='https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive'
r=requests.post('https://accounts.google.com/o/oauth2/device/code', data={'client_id':cid,'scope':scope}, timeout=30)
d=r.json(); d['started_at']=datetime.datetime.utcnow().isoformat()+'Z'; d.pop('device_code',None)
put('tmp_docflow/device.json', d, 'docflow device info')
except Exception as e:
put('tmp_docflow/error.json', {'error':repr(e)}, 'docflow error')
raise
PY