import api
import config
import logging
import json
from get_records import get_all_records
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
TABS = config.WEB_VIEW_TABS
logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
HTML_TEMPLATE = r"""
Bitable Records - Interactive View
"""
def build_html(client, access_token):
tab_data_list = []
for tab in TABS:
logging.info(f"Fetching records for tab [{tab['name']}]...")
records = get_all_records(client, access_token, tab['app_token'], tab['table_id'])
logging.info(f"Tab [{tab['name']}] retrieved {len(records)} records.")
tab_data_list.append({
"name": tab['name'],
"records": records
})
# Dump records to json
records_json = json.dumps(tab_data_list, ensure_ascii=False)
final_html = HTML_TEMPLATE.replace('{RECORDS_JSON}', records_json)
final_html = final_html.replace('{DEFAULT_AI_KEY}', config.AI_API_KEY or '')
final_html = final_html.replace('{DEFAULT_AI_URL}', config.AI_BASE_URL or 'https://api.openai.com/v1')
final_html = final_html.replace('{DEFAULT_AI_MODEL}', config.AI_MODEL or 'gpt-4o')
return final_html
def main():
client = api.Client(config.LARK_HOST)
try:
access_token = client.get_tenant_access_token(config.APP_ID, config.APP_SECRET)
except Exception as e:
logging.error(f"Could not get access token: {e}")
return
final_html = build_html(client, access_token)
output_file = "outline_view.html"
with open(output_file, "w", encoding="utf-8") as f:
f.write(final_html)
logging.info(f"Successfully generated HTML view at {output_file}")
print(f"\n✅ HTML view generated! You can open '/home/verachen/Workspace/feishu/bitable_calendar/python/{output_file}' in your browser.")
if __name__ == "__main__":
main()