Dooratre commited on
Commit
e916b82
·
verified ·
1 Parent(s): 2b714d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,16 +1,22 @@
1
  from flask import Flask, request
2
  import requests
3
  import json
 
4
  from qwen import get_qwen_response # Import the Qwen response function
5
 
6
  app = Flask(__name__)
7
 
8
- # Load page credentials from token.json
9
  try:
10
- with open('token.json', 'r') as f:
11
- PAGE_CREDENTIALS = {page['page_id']: page['page_token'] for page in json.load(f)['pages']}
12
- except FileNotFoundError:
13
- print("Error: 'token.json' file not found. Please create it and add page credentials.")
 
 
 
 
 
14
  PAGE_CREDENTIALS = {}
15
 
16
  AI_SERVICE_URL = "https://aoamrnuwara.pythonanywhere.com/send-message"
 
1
  from flask import Flask, request
2
  import requests
3
  import json
4
+ from db import fetch_json_from_github # Import the GitHub JSON fetcher
5
  from qwen import get_qwen_response # Import the Qwen response function
6
 
7
  app = Flask(__name__)
8
 
9
+ # Fetch page credentials from GitHub on startup
10
  try:
11
+ github_response = fetch_json_from_github()
12
+ if github_response["success"]:
13
+ PAGE_CREDENTIALS = {page['page_id']: page['page_token'] for page in github_response["data"]["pages"]}
14
+ print("Successfully loaded page credentials from GitHub.")
15
+ else:
16
+ print(f"Error loading page credentials: {github_response['message']}")
17
+ PAGE_CREDENTIALS = {}
18
+ except Exception as e:
19
+ print(f"Unexpected error while fetching credentials: {e}")
20
  PAGE_CREDENTIALS = {}
21
 
22
  AI_SERVICE_URL = "https://aoamrnuwara.pythonanywhere.com/send-message"