File size: 1,540 Bytes
a5ca742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from datetime import datetime, timedelta

def add_to_google_calendar(symbol, company_name):
    """Add analysis review event to Google Calendar"""
    creds = Credentials.from_authorized_user_info(st.secrets["google"])
    service = build('calendar', 'v3', credentials=creds)

    event = {
        'summary': f'Stock Analysis Review - {symbol}',
        'description': f'Review financial analysis for {company_name}',
        'start': {
            'dateTime': (datetime.now() + timedelta(days=1)).isoformat(),
            'timeZone': 'UTC',
        },
        'end': {
            'dateTime': (datetime.now() + timedelta(days=1, hours=1)).isoformat(),
            'timeZone': 'UTC',
        },
    }

    service.events().insert(calendarId='primary', body=event).execute()

def update_google_sheet(stock_data, symbol):
    """Export stock data to Google Sheets"""
    creds = Credentials.from_authorized_user_info(st.secrets["google"])
    service = build('sheets', 'v4', credentials=creds)

    spreadsheet_id = st.secrets["google_sheet_id"]
    range_name = f'{symbol}!A1'

    values = [stock_data.columns.tolist()] + stock_data.reset_index().values.tolist()
    body = {'values': values}

    service.spreadsheets().values().update(
        spreadsheetId=spreadsheet_id,
        range=range_name,
        valueInputOption='RAW',
        body=body
    ).execute()