aminahmadi0101 commited on
Commit
2130eae
·
verified ·
1 Parent(s): a39bc00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -3,37 +3,31 @@ import subprocess
3
 
4
  def install_wkhtmltopdf():
5
  try:
6
- # نصب وابستگی‌های مورد نیاز
7
- print("Installing required dependencies...")
8
  subprocess.run(["apt-get", "update"], check=True)
9
- subprocess.run(["apt-get", "install", "-y", "libssl1.1", "libxrender1", "libfontconfig1", "libxext6", "libx11-6"], check=True)
10
 
11
  # دانلود و نصب wkhtmltopdf
12
  print("Downloading wkhtmltopdf...")
13
  subprocess.run(
14
- ["wget", "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.bullseye_amd64.deb"],
15
  check=True
16
  )
17
 
18
- # استخراج فایل deb و نصب دستی
19
  print("Installing wkhtmltopdf...")
20
- subprocess.run(["ar", "x", "wkhtmltox_0.12.6.1-2.bullseye_amd64.deb"], check=True)
21
- subprocess.run(["tar", "-xvf", "data.tar.xz"], check=True)
22
-
23
- # انتقال فایل‌های اجرایی به دایرکتوری محلی
24
- os.makedirs("/home/user/bin", exist_ok=True)
25
- subprocess.run(["cp", "./usr/local/bin/wkhtmltopdf", "/home/user/bin/"], check=True)
26
- subprocess.run(["cp", "./usr/local/bin/wkhtmltoimage", "/home/user/bin/"], check=True)
27
 
28
  # اضافه کردن مسیر به PATH
29
- os.environ["PATH"] += os.pathsep + "/home/user/bin"
30
  print("wkhtmltopdf installed and configured successfully.")
31
  except subprocess.CalledProcessError as e:
32
  print(f"Error during wkhtmltopdf installation: {e}")
33
  raise
34
 
35
  # اجرای نصب در صورت نیاز
36
- if not os.path.exists("/home/user/bin/wkhtmltopdf"):
37
  install_wkhtmltopdf()
38
 
39
  # اکنون می‌توانید از pdfkit استفاده کنید
 
3
 
4
  def install_wkhtmltopdf():
5
  try:
6
+ # نصب وابستگی‌های جایگزین
7
+ print("Installing updated dependencies...")
8
  subprocess.run(["apt-get", "update"], check=True)
9
+ subprocess.run(["apt-get", "install", "-y", "libssl3", "libxrender1", "libfontconfig1", "libxext6", "libx11-6"], check=True)
10
 
11
  # دانلود و نصب wkhtmltopdf
12
  print("Downloading wkhtmltopdf...")
13
  subprocess.run(
14
+ ["wget", "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb"],
15
  check=True
16
  )
17
 
18
+ # نصب فایل deb
19
  print("Installing wkhtmltopdf...")
20
+ subprocess.run(["dpkg", "-i", "wkhtmltox_0.12.6-1.bionic_amd64.deb"], check=True)
 
 
 
 
 
 
21
 
22
  # اضافه کردن مسیر به PATH
23
+ os.environ["PATH"] += os.pathsep + "/usr/local/bin"
24
  print("wkhtmltopdf installed and configured successfully.")
25
  except subprocess.CalledProcessError as e:
26
  print(f"Error during wkhtmltopdf installation: {e}")
27
  raise
28
 
29
  # اجرای نصب در صورت نیاز
30
+ if not os.path.exists("/usr/local/bin/wkhtmltopdf"):
31
  install_wkhtmltopdf()
32
 
33
  # اکنون می‌توانید از pdfkit استفاده کنید