inital google calendar integration

This commit is contained in:
samerbam 2023-08-25 19:43:38 -04:00
parent 6195fbc456
commit 4f5a6e67af
5 changed files with 47 additions and 3 deletions

View File

@ -8,6 +8,8 @@ class Settings(BaseSettings):
auth0_api_audience: str auth0_api_audience: str
auth0_issuer: str auth0_issuer: str
auth0_algorithms: str auth0_algorithms: str
google_client_id: str
google_client_secret: str
class Config: class Config:
env_file = ".env" env_file = ".env"

View File

@ -55,6 +55,9 @@ class PrintAction(BaseModel):
# sentence (prints a custom message) # sentence (prints a custom message)
sentence: str = "" sentence: str = ""
class GoogleUpdate(BaseModel):
code: str
# @app.get("/api/public") # @app.get("/api/public")
# def public(): # def public():
# """No access token required to access this route""" # """No access token required to access this route"""
@ -66,6 +69,10 @@ class PrintAction(BaseModel):
# } # }
# return result # return result
@app.post("/api/google/update")
def write_todos(code: GoogleUpdate, auth_result: str = Security(auth.verify)):
print(code.code)
return {"status": "success"}
@app.get('/api/first_run') @app.get('/api/first_run')
def first_run(): def first_run():
@ -101,7 +108,6 @@ def get_todos(date: str = datetime.today().strftime('%Y-%m-%d'), auth_result: st
# return auth_result # return auth_result
@app.post("/api/todos/write") @app.post("/api/todos/write")
def write_todos(todos: TodoList, auth_result: str = Security(auth.verify)): def write_todos(todos: TodoList, auth_result: str = Security(auth.verify)):
"""A valid access token is required to access this route""" """A valid access token is required to access this route"""

View File

@ -18,6 +18,9 @@
</div> </div>
<button onclick="client.requestCode();">Authorize with Google</button>
<!-- <div id="testToken"></div> --> <!-- <div id="testToken"></div> -->
@ -446,6 +449,34 @@
</script> </script>
<!-- Google auth for calendar access on first launch-->
<script src="https://accounts.google.com/gsi/client"></script>
<script type="text/javascript">
let code_receiver_uri = "/api/google/update"
const client = google.accounts.oauth2.initCodeClient({
client_id: '186960779149-ejtu6hh3kdatlouau80h2pivt4tv3hd0.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/calendar.readonly',
ux_mode: 'popup',
callback: (response) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', code_receiver_uri, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'Bearer ' + jToken);
// Set custom header for CRSF
xhr.setRequestHeader('X-Requested-With', 'XmlHttpRequest');
xhr.onload = function() {
console.log('Auth code response: ' + xhr.responseText);
};
xhr.send(JSON.stringify({"code": response.code}));
console.log(xhr)
console.log(response.code)
},
});
</script>
<script src="scripts.js"></script> <script src="scripts.js"></script>
</body> </body>

View File

@ -30,7 +30,7 @@
# filename = os.path.abspath(os.path.join(WORKING_DIRECTORY, STATIC, 'index.html')) # filename = os.path.abspath(os.path.join(WORKING_DIRECTORY, STATIC, 'index.html'))
# with open(filename, 'rt') as f: # with open(filename, 'rt') as f:
# resp.body = f.read() # resp.body = f.read()
from escpos.printer import Usb from escpos.printer import Usb, Dummy
import usb import usb
from wonderwords import RandomWord from wonderwords import RandomWord
from datetime import datetime from datetime import datetime
@ -53,8 +53,9 @@ class ThermalPrinter():
# pass # pass
except usb.core.NoBackendError as e: except usb.core.NoBackendError as e:
print(e) print(e)
self.p = Dummy()
print("Try running `export DYLD_LIBRARY_PATH=/opt/homebrew/lib` if on m1 mac. source: https://github.com/pyusb/pyusb/issues/355#issuecomment-1062798576") print("Try running `export DYLD_LIBRARY_PATH=/opt/homebrew/lib` if on m1 mac. source: https://github.com/pyusb/pyusb/issues/355#issuecomment-1062798576")
raise # raise
def print_custom(self, text=""): def print_custom(self, text=""):
self.p.set(align="left") self.p.set(align="left")

View File

@ -19,3 +19,7 @@ sniffio==1.3.0
typing_extensions==4.7.1 typing_extensions==4.7.1
uvicorn==0.23.2 uvicorn==0.23.2
wonderwords wonderwords
google-api-python-client
google-auth
google-auth-oauthlib
google-auth-httplib2