Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f981745

Browse files
committed
download pandoc
1 parent c31093f commit f981745

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

src/codebots/bots/latexbot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ def _clone_overleaf(self, document_code):
4141
installed on your machine.
4242
"""
4343
temp_dir = tempfile.TemporaryDirectory()
44-
out = subprocess.run(["git", "clone", f"https://git.overleaf.com/{document_code}"], cwd=temp_dir.name)
45-
if out.returncode == 0:
46-
print(f"project temporary saved in {temp_dir.name}")
47-
else:
48-
raise Exception
49-
# temp_dir.cleanup()
44+
try:
45+
out = subprocess.run(["git", "clone", f"https://git.overleaf.com/{document_code}"], cwd=temp_dir.name)
46+
if out.returncode == 0:
47+
print(f"project temporary saved in {temp_dir.name}")
48+
except:
49+
temp_dir.cleanup()
50+
raise RuntimeError
5051
return temp_dir
5152

5253
def convert_tex_to_docx(self, input_path, output_path=None):

src/codebots/utilities/latex.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
import requests
2+
import subprocess
3+
import tempfile
4+
from pathlib import Path
25

6+
from tqdm import tqdm
37

4-
def download():
5-
url = 'https://www.facebook.com/favicon.ico'
6-
r = requests.get(url, allow_redirects=True)
78

8-
open('facebook.ico', 'wb').write(r.content)
9+
from codebots.cli.cli import main
10+
11+
12+
def download(url='https://github.com/jgm/pandoc/releases/download/2.15/pandoc-2.15-windows-x86_64.msi'):
13+
14+
# r = requests.get(url, allow_redirects=True)
15+
16+
# Streaming, so we can iterate over the response.
17+
r = requests.get(url, stream=True)
18+
total_size_in_bytes = int(r.headers.get('content-length', 0))
19+
block_size = 1024 # 1 Kibibyte
20+
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)
21+
with open('C:/temp/pandoc.msi', 'wb') as f:
22+
for data in r.iter_content(block_size):
23+
progress_bar.update(len(data))
24+
f.write(data)
25+
progress_bar.close()
26+
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
27+
print("ERROR, something went wrong")
28+
29+
# with open('C:/temp/pandoc.msi', 'wb') as f:
30+
# f.write(r.content)
31+
# print(r)
32+
33+
# temp_dir = tempfile.TemporaryDirectory()
34+
# try:
35+
# process = subprocess.Popen(Path().joinpath(temp_dir.name, 'pandoc.msi'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
36+
# except:
37+
# temp_dir.cleanup()
38+
39+
40+
if __name__ == "__main__":
41+
download()

0 commit comments

Comments
 (0)