From 222868155902a8e9159b303692a10eb325fe1f42 Mon Sep 17 00:00:00 2001 From: Viktor Fomin Date: Mon, 12 Feb 2024 12:45:36 +0300 Subject: [PATCH] add script for download campaigns --- campaigns.downloader.py | 39 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 40 insertions(+) create mode 100644 campaigns.downloader.py diff --git a/campaigns.downloader.py b/campaigns.downloader.py new file mode 100644 index 0000000000..33c0fbe07d --- /dev/null +++ b/campaigns.downloader.py @@ -0,0 +1,39 @@ +import os +from github import Github +import requests +import shutil + +rd = os.path.dirname(os.path.abspath(__file__)) +dir = os.path.abspath(os.path.join(rd, "..")) +publicDir = os.path.join(dir, "client/public") +g = Github() +repo = g.get_repo("ONLYOFFICE/ASC.Web.Campaigns") +repoFolder = "src/campaigns" + +def download(c, out): + r = requests.get(c.download_url) + output_path = f'{out}/{c.path}' + os.makedirs(os.path.dirname(output_path), exist_ok=True) + with open(output_path, 'wb') as f: + f.write(r.content) + + +def download_folder(repo, folder, out, recursive): + contents = repo.get_contents(folder) + for c in contents: + if c.download_url is None: + if recursive: + download_folder(repo, c.path, out, recursive) + continue + download(c, out) + +def move_folder(): + srcPath = publicDir + "/src" + campaignsPath = srcPath + "/campaigns" + newPath = publicDir + "/campaigns" + shutil.move(campaignsPath, newPath) + shutil.rmtree(srcPath) + +download_folder(repo, repoFolder, publicDir, True) +move_folder() +print("It's OK") \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index edc51ee8c8..2b5436f018 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ gitdb==4.0.11 GitPython==3.1.40 smmap==5.0.1 +PyGithub==2.2.0 \ No newline at end of file