Selenium project filling up my C disk after using pyinstaller to convert it to exe
I wrote a script to scrape some info from a certain website, and it then saves it to an online spreadsheet. Testing the script with VScode was going flawlessly then I used pyinstaller
to make it .exe for a client, but after working with it for like 2 hours I found out that 30 GB of my C disk were taken
do you know?
how many words do you know
See also questions close to this topic
-
Python File Tagging System does not retrieve nested dictionaries in dictionary
I am building a file tagging system using Python. The idea is simple. Given a directory of files (and files within subdirectories), I want to filter them out using a filter input and tag those files with a word or a phrase.
If I got the following contents in my current directory:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
and I execute the following command in the shell:
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
My output will be:
These files were tagged with "World-Building Tool": data/ world_building_budget.txt hello_world.dat world_builder.spec
My current output isn't exactly like this but basically, I am converting all files and files within subdirectories into a single dictionary like this:
def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree
Right now, my dictionary looks like this:
key:''
.In the following function, I am turning the empty values
''
into empty lists (to hold my tags):def empty_str_to_list(d): for k,v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v)
When I run my entire code, this is my output:
hello_world.dat ['World-Building Tool'] world_builder.spec ['World-Building Tool']
But it does not see
data/world_building_budget.txt
. This is the full dictionary:{'data': {'world_building_budget.txt': []}, 'a.txt': [], 'hello_world.dat': [], 'b.exe': [], 'world_builder.spec': []}
This is my full code:
import os, argparse def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree def empty_str_to_list(d): for k, v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v) parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--filter", action="store", help="keyword to filter files") parser.add_argument("--tag", action="store", help="a tag phrase to attach to a file") parser.add_argument("--get_tagged", action="store", help="retrieve files matching an existing tag") args = parser.parse_args() filter = args.filter tag = args.tag get_tagged = args.get_tagged current_dir = os.getcwd() files_dict = fs_tree_to_dict(current_dir) empty_str_to_list(files_dict) for k, v in files_dict.items(): if filter in k: if v == []: v.append(tag) print(k, v) elif isinstance(v, dict): empty_str_to_list(v) if get_tagged in v: print(k, v)
-
Actaully i am working on a project and in it, it is showing no module name pip_internal plz help me for the same. I am using pycharm(conda interpreter
File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module> File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\__init__.py", line 4, in <module> from pip_internal.utils import _log
I am using pycharm with conda interpreter.
-
Looping the function if the input is not string
I'm new to python (first of all) I have a homework to do a function about checking if an item exists in a dictionary or not.
inventory = {"apple" : 50, "orange" : 50, "pineapple" : 70, "strawberry" : 30} def check_item(): x = input("Enter the fruit's name: ") if not x.isalpha(): print("Error! You need to type the name of the fruit") elif x in inventory: print("Fruit found:", x) print("Inventory available:", inventory[x],"KG") else: print("Fruit not found") check_item()
I want the function to loop again only if the input written is not string. I've tried to type return Under print("Error! You need to type the name of the fruit") but didn't work. Help
-
setTimeout in nested for loops in JavaScript not working like what I want
I am writing a JavaScript application to simulate a document download process in web automation. The page to interact has a paginated list of people like shown in the screenshot below. Clicking on the person's name will download this person's document.
The automation process downloads each person's document, then proceeds to the next page and continues to download in the same way.
I would like (1) a 2 second delay between each download and (2) a 2 second delay after hitting a new page and before the first download.
After some research, I came up with the following. It is very close to what I want except that it executes the download immediately after landing on the next page. Any idea on how I can tweak it to get a 2+ seconds of delay between landing on a new paginated page and the first download?
function downloadDoc(x) { console.log("Downloading doc ", x); } function goToPage(p) { for(let i=0; i<5; i++) { setTimeout(downloadDoc, i*2000, i); } console.log("Go to page ", p); } for(let i=0; i<5; i++) { setTimeout(downloadDoc, i*2000, i); } for (let p = 2; p< 5; p++) { setTimeout(goToPage, p * 12000, p); }
UPDATE: Solved by following the provided answer by @jonas-wilms at https://stackoverflow.com/a/44476626/97109
async function downloadDoc(x) { await timer (1000); console.log("Downloading doc ", x); } async function goToPage(p) { await timer(2000); console.log("Go to page ", p); } async function task(i) { // 3 await timer(1000); //console.log(` ${i} done!`); downloadDoc(i); } async function main() { for(let i = 0; i < 8; i++) { await goToPage(i); for(let j = 0; j < 5; j++) { await task(j); if (j === 4) { await timer(2000); } } } } main(); function timer(ms) { return new Promise(res => setTimeout(res, ms)); }
-
How to wait for translated text to appear in DeepL.com
After entering original text in DeepL, it takes 1-2 sec for translated text to appear.
I'm unable to get translated text.
I've tried to Synchronize using:
from selenium.webdriver.support import expected_conditions as EC # ... # ... # ... WebDriverWait(driver, 10).until_not(EC.text_to_be_present_in_element((By.XPATH, "//div[@id='target-dummydiv']"), "\r\n")) translatedText = driver.find_element(By.XPATH, "//div[@id='target-dummydiv']").text
Checking for non-empty translated text:
WebDriverWait(driver, 10).until(self.IsTranslatedTextNotEmpty) translatedText = driver.find_element(By.XPATH, "//div[@id='target-dummydiv']").text def IsTranslatedTextNotEmpty(self, driver: WebDriver): translatedText = driver.find_element(By.XPATH, "//div[@id='target-dummydiv']").text return len(translatedText) > 0
doesn't work.
Note: Synchronization using
time.sleep(5)
works.