sonuprasad23 commited on
Commit
2292b24
·
1 Parent(s): c95414e

Project Uploaded

Browse files
Files changed (1) hide show
  1. api_server.py +9 -8
api_server.py CHANGED
@@ -12,8 +12,6 @@ from dotenv import load_dotenv
12
 
13
  load_dotenv()
14
 
15
- # --- MODIFICATION START ---
16
- # Define a helper function to fix Base64 padding. This makes the app resilient to copy-paste errors.
17
  def decode_base64_with_padding(b64_string: str) -> bytes:
18
  """Decodes a Base64 string, adding missing padding if necessary."""
19
  missing_padding = len(b64_string) % 4
@@ -23,16 +21,15 @@ def decode_base64_with_padding(b64_string: str) -> bytes:
23
  return base64.b64decode(b64_string)
24
  except binascii.Error as e:
25
  print(f"Error decoding base64 string after padding: {e}")
26
- # Return empty bytes or raise a more specific error if you prefer
27
  return b""
28
 
29
- # Define a writable directory
30
  WRITABLE_DIR = "/tmp"
31
  CREDENTIALS_PATH = os.path.join(WRITABLE_DIR, "credentials.json")
32
  COOKIES_PATH = os.path.join(WRITABLE_DIR, "facebook_cookies.pkl")
33
  TOKEN_PATH = os.path.join(WRITABLE_DIR, "token.pickle")
34
 
35
- # Decode secrets at startup using the new robust function
36
  if 'CREDENTIALS_B64' in os.environ:
37
  decoded_creds = decode_base64_with_padding(os.environ['CREDENTIALS_B64'])
38
  if decoded_creds:
@@ -44,16 +41,20 @@ if 'FB_COOKIES_B64' in os.environ:
44
  if decoded_cookies:
45
  with open(COOKIES_PATH, 'wb') as f:
46
  f.write(decoded_cookies)
47
- # --- MODIFICATION END ---
48
 
49
 
50
  GROUPS_TXT = os.environ.get("GROUPS_TXT", "groups.txt")
51
- SCRAPE_OUTDIR = os.environ.get("SCRAPE_OUTDIR", "scraped")
52
- ANALYSIS_OUTDIR = os.environ.get("ANALYSIS_OUTDIR", "analysis")
53
  FINAL5_PATH = os.environ.get("FINAL5_PATH", "final5.py")
54
  PYTHON_BIN = os.environ.get("PYTHON_BIN", "python")
55
  SENDER_EMAIL = os.environ.get("SENDER_EMAIL", "smahato@hillsidemedicalgroup.com")
56
 
 
 
 
 
 
 
 
57
  GEMINI_KEYS = []
58
  for i in range(1, 6):
59
  key = os.environ.get(f"GEMINI_API_KEY_{i}")
 
12
 
13
  load_dotenv()
14
 
 
 
15
  def decode_base64_with_padding(b64_string: str) -> bytes:
16
  """Decodes a Base64 string, adding missing padding if necessary."""
17
  missing_padding = len(b64_string) % 4
 
21
  return base64.b64decode(b64_string)
22
  except binascii.Error as e:
23
  print(f"Error decoding base64 string after padding: {e}")
 
24
  return b""
25
 
26
+ # Define a writable directory for ALL runtime files
27
  WRITABLE_DIR = "/tmp"
28
  CREDENTIALS_PATH = os.path.join(WRITABLE_DIR, "credentials.json")
29
  COOKIES_PATH = os.path.join(WRITABLE_DIR, "facebook_cookies.pkl")
30
  TOKEN_PATH = os.path.join(WRITABLE_DIR, "token.pickle")
31
 
32
+ # Decode secrets at startup into the /tmp directory
33
  if 'CREDENTIALS_B64' in os.environ:
34
  decoded_creds = decode_base64_with_padding(os.environ['CREDENTIALS_B64'])
35
  if decoded_creds:
 
41
  if decoded_cookies:
42
  with open(COOKIES_PATH, 'wb') as f:
43
  f.write(decoded_cookies)
 
44
 
45
 
46
  GROUPS_TXT = os.environ.get("GROUPS_TXT", "groups.txt")
 
 
47
  FINAL5_PATH = os.environ.get("FINAL5_PATH", "final5.py")
48
  PYTHON_BIN = os.environ.get("PYTHON_BIN", "python")
49
  SENDER_EMAIL = os.environ.get("SENDER_EMAIL", "smahato@hillsidemedicalgroup.com")
50
 
51
+ # --- MODIFICATION START ---
52
+ # Point the output directories to the writable /tmp directory
53
+ SCRAPE_OUTDIR = os.path.join(WRITABLE_DIR, "scraped")
54
+ ANALYSIS_OUTDIR = os.path.join(WRITABLE_DIR, "analysis")
55
+ # --- MODIFICATION END ---
56
+
57
+
58
  GEMINI_KEYS = []
59
  for i in range(1, 6):
60
  key = os.environ.get(f"GEMINI_API_KEY_{i}")