Skip to content

Commit

Permalink
ошибка ожидания загрузки файла
Browse files Browse the repository at this point in the history
  • Loading branch information
ritds committed Mar 6, 2022
1 parent ed2aa1f commit b2c7832
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions config/download_settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"downloadTimeout": 0,
"selectorTimeout": 2000,
"downloadTimeout": 300,
"selectorTimeout": 20000,
"navigationTimeout": 180000,
"launchTimeout": 120000,
"loginTimeout": 10000,
Expand Down
32 changes: 10 additions & 22 deletions download_figma_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,13 @@ const puppeteer = require('puppeteer');
console.log('\nStarting to process new file (' + (i + 1) + '/' + figmaFilesList.length + '), url: ' + filePage);

try {
// Opening an empty page
console.log('Opening an empty page');
await page.goto('about:blank');

// Sleeping for 3 seconds
await sleep(3000);

// Opening a file page
console.log('Opening the file page: ' + filePage);
let filePageResponse = await page.goto(filePage, {waitUntil: 'networkidle2'});


// Checking status code

console.log('Returned status: ' + filePageResponse.status());

if(filePageResponse.status() !== 200) {
console.log('Skipping the file');
continue;
Expand All @@ -216,13 +207,12 @@ const puppeteer = require('puppeteer');
// Getting and validating page title

const title = await page.title();
console.log("Page title: '" + title + "'");

if(!title.endsWith(' – Figma')) {
console.log('Title format seems to be unrecognized, skipping the file')
console.log(`Title format "${title}" seems to be unrecognized, skipping the file`)
await page.screenshot({path: debugDir + 'login_screenshot' + '.png', fullPage: true});
continue;
}
const fileName = title.replace(' – Figma', '');
const fileName = title.replace(' – Figma', '').replaceAll('/', '_').replaceAll('|', '_').replaceAll('"', '_');
// Getting the local path of the directory for the file to download

let downloadDir = downloadsBaseDir;
Expand Down Expand Up @@ -254,7 +244,7 @@ const puppeteer = require('puppeteer');
}


console.log("Directory to save the file: '" + downloadDir + "'");
console.log(`Directory to save the file: ${downloadDir}${fileName}`);

fs.mkdirSync(downloadDir, {recursive: true});

Expand Down Expand Up @@ -284,8 +274,8 @@ const puppeteer = require('puppeteer');
} catch (error) {
if(debugDir && !menuItemFileHandle) {
console.log('cannot open main menu')
fs.writeFile(debugDir + (i + 1) + '_main_menu' + '.html', content, () => {});
await page.screenshot({path: debugDir + (i + 1) + '_main_menu_screenshot' + '.png', fullPage: true});
fs.writeFile(debugDir + fileName + '_main_menu' + '.html', content, () => {});
await page.screenshot({path: debugDir + fileName + '_main_menu_screenshot' + '.png', fullPage: true});
}
throw error;
}
Expand All @@ -310,8 +300,8 @@ const puppeteer = require('puppeteer');

if(debugDir && !submenuFileHandle) {
console.log('cannot open file menu')
fs.writeFile(debugDir + (i + 1) + '_file_menu' + '.html', content, () => {});
await page.screenshot({path: debugDir + (i + 1) + '_file_menu_screenshot' + '.png', fullPage: true});
fs.writeFile(debugDir + fileName + '_file_menu' + '.html', content, () => {});
await page.screenshot({path: debugDir + fileName + '_file_menu_screenshot' + '.png', fullPage: true});
}
throw error;
}
Expand All @@ -325,23 +315,21 @@ const puppeteer = require('puppeteer');

for(let j = 0; downloadedCheckTries == 0 || j < downloadedCheckTries; j++) {
await sleep(1000);

if (fs.existsSync(downloadDir + fileName+'.fig')) {
console.log('Download complete');
break;
}

if (fs.existsSync(downloadDir + fileName+'.jam')) {
console.log('Download complete');
break;
}

if (j % 30 == 0) {
console.log(`waiting files to download for ${parseInt(j / 60)} min ${j % 60} sec.`)
console.log(`waiting file to download for ${parseInt(j / 60)} min ${j % 60} sec.`)
}

if(downloadedCheckTries > 0 && j === (downloadedCheckTries - 1)) {
console.log('File is not downloaded during timeout')
console.log(`File ${downloadDir + fileName} is not downloaded during timeout`)
}
}
} catch (err) {
Expand Down
7 changes: 6 additions & 1 deletion get_figma_files_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ def _get_project_files(self, project: dict) -> list:
}
)
if os.path.isfile(file_name_to_check):
if not os.path.exists(f'./store/{today}/TEAM {project["team"]}/PROJECT {project_name}/'):
if not os.path.exists(f'./store/{today}'):
os.makedirs(f'./store/{today}')
if not os.path.exists(f'./store/{today}/TEAM {project["team"]}'):
os.makedirs(f'./store/{today}/TEAM {project["team"]}')
if not os.path.exists(f'./store/{today}/TEAM {project["team"]}/PROJECT {project_name}/'):
os.makedirs(
f'./store/{today}/TEAM {project["team"]}/PROJECT {project_name}/')
shutil.copyfile(
file_name_to_check, f'./store/{today}/TEAM {project["team"]}/PROJECT {project_name}/{file["name"]}.fig')
os.remove(file_name_to_check)
Expand Down

0 comments on commit b2c7832

Please sign in to comment.