Новый перевод английской версии сайта

This commit is contained in:
Ilia Miheev
2025-11-12 15:53:56 +03:00
parent bc6d5c826e
commit 98b142abec
7 changed files with 109 additions and 90 deletions
+22 -16
View File
@@ -1,45 +1,51 @@
### Working with CsvManager
This class is designed to write and extract information from csv files
This class is intended for writing and retrieving information from CSV files.
The CsvManager class takes three arguments: the newline character newline (default is an empty string), the encoding of the opened files encoding (default is UTF-8), and the delimiter used in the CSV file delimiter (default is ";").
The CsvManager class accepts three arguments:
- newline — the newline character (default is an empty string).
- encoding — the encoding of the files being opened (UTF-8).
- delimiter — the delimiter used in the CSV file (;).
```py
from ipars import CsvManager
c = CsvManager()
c = CsvManager(newline="", encoding="UTF-8", delimiter=";")
```
### Brief Overview of CsvManager Methods
1. The **writerow** method writes a row to the CSV file. The method takes the path to the CSV file, the write mode, and a list of data that will be written to the file's row.
- The **writerow** method writes a row to a CSV file. This method accepts the file path, the write mode, and a list of data to be written in the row.
2. The **writerows** method takes the same arguments as writerow, but the row must be a double list with data for writing. The difference between these methods is that writerow writes one row, while writerows writes as many as there are in the double list.
- The **writerows** method accepts the same arguments as writerow, except row must be a double list with data for writing. The difference between these methods is that writerow writes one row, while writerows writes as many rows as there are in the double list.
3. The **getRows** method is used to retrieve a list of rows in the CSV file. The method takes the path to the file from which the rows will be obtained.
- The **getRows** method is used to obtain a list of rows from the CSV file. This method accepts the file path from which the rows will be retrieved.
4. The **pprint** method is the same as that of Pars.
- The **pprint** method is the same as that of Pars.
### Example of Using CsvManager
### Example Usage of CsvManager
```py
from ipars import CsvManager
c = CsvManager()
nameFile = 'data.csv'
# writing headers
writer = c.writerow('./data.csv', 'w', ['Quantity', 'Price', 'Total'])
# Writing headers
c.writerow(nameFile, 'w', ['Quantity', 'Price', 'Total'])
# writing data
writer = c.writerows('./data.csv', 'a', [
# Writing data
c.writerows(nameFile, 'a', [
["5", "5", "25"],
["6", "6", "36"],
["7", "7", "49"],
])
# retrieving rows from the table
rows = c.getRows('./data.csv')
# Retrieving rows from the table
rows = c.getRows(nameFile)
# printing table rows
# Displaying the rows of the table
c.pprint(rows)
```
+10 -10
View File
@@ -1,34 +1,34 @@
### Working with JsonManager
This class is designed to write and extract information from json files.
This class is intended for writing and retrieving information from JSON files.
JsonManager takes only one argument — the encoding in which the files will be read. The default is UTF-8.
JsonManager accepts only one parameter: encoding — the encoding in which the files will be read (default is UTF-8).
```py
from ipars import JsonManager
j = JsonManager()
j = JsonManager(encoding="UTF-8")
```
### Brief Overview of JsonManager Methods
1. The **load** method is used to retrieve data from a JSON file at the specified path.
- The **load** method is used to obtain data from a JSON file at the specified path.
2. The **dump** method is used to write data to a JSON file. It takes the path to the file and the data to be written.
- The **dump** method is used to write data to a JSON file. It accepts the file path and the data to write.
3. The **pprint** method is the same as that of Pars.
- The **pprint** method is the same as that of Pars.
### Example of Using JsonManager
### Example Usage of JsonManager
```py
from ipars import JsonManager
j = JsonManager()
nameFile = 'data.json'
# Writing data
j.dump('./data.json', [1, 2, 3, 4, 5, 6, 7])
j.dump(nameFile, [1, 2, 3, 4, 5, 6, 7])
# Retrieving data
data = j.load('./data.json')
data = j.load(nameFile)
j.pprint(data) # [1, 2, 3, 4, 5, 6, 7]
```
+39 -22
View File
@@ -1,42 +1,55 @@
### Working with Pars
This class is designed to work with requests and the resulting html page.
This class is designed for handling requests and the obtained HTML page.
The Pars class does not take any arguments for its constructors.
The Pars class does not accept any data for its constructor.
```python
```py
from ipars import Pars
p = Pars()
```
### Brief Overview of Pars Methods
### Brief Overview of Pars Methods:
1. The **getStaticPage** method takes the URL of the page, the path where the page will be saved, the write method, and request headers. The "wb" write method is used for saving images; by default, the write method is set to "w", which is used for HTML pages. If request headers are not specified, random user-agent headers will be used. The method returns the status response from the website, which should be used for conducting checks.
2. The **getDynamicPage** method uses the Selenium library to get a dynamically updated page. This is useful when content on the page loads dynamically. It takes the URL of the page, the save path, closeWindow, and timeSleep. By default, the Selenium browser opens in the background, and its operation is not visible, but if closeWindow is set to False, the code execution process will be shown. The timeSleep parameter can extend the page load time if content takes long to load.
3. The **gpsa** (get page semi-automatically) method is similar to the getDynamicPage method but works in a semi-automatic mode. It opens the webpage and waits until Enter is pressed in the terminal. During this time, you can register on the site and/or switch to the desired tab on the site, after which pressing Enter will allow the method to parse the page. This is suitable for social media feeds where unauthorized users have limited access to content. It accepts the same arguments and serves the same purposes as getDynamicPage, except for closeWindow.
4. The **returnBs4Object** method returns a BeautifulSoup object. It takes the path to the HTML page, converts its contents into a BeautifulSoup object, the file open encoding (default is UTF-8), and the parser type (default is lxml).
5. The **getAttributes** method is used to retrieve a list of attributes from a list of BeautifulSoup objects. It takes a list of BeautifulSoup objects and the name of the attribute to be extracted from the elements of the list.
6. The **getTexts** method is used to retrieve a list of text from a list of BeautifulSoup objects. It takes a list of BeautifulSoup objects and the needFix parameter. If this parameter is set to True, \n, \t, and spaces from the ends will be removed from the text.
7. The **pprint** method is used for displaying variable values that have a high level of nesting. For example, if you have an array of objects, where another array of objects is used as the value of a key.
8. The **mkdir** method is used to create a directory with the name nameDir if it does not already exist.
- The **getStaticPage** method takes a URL of the page, the path where the page will be saved, the write method, and request headers. The write method "wb" is used for saving images; by default, the write method is set to "w", which is used for HTML pages. If the request headers are not specified, random user-agent headers will be used. The method returns the response status of the website, which can be used for checks.
```py
for index, url in enumerate(urlList):
if p.getStaticPage(url, f'./page{index}') == 404:
print('Failed to obtain the page: ', url)
```
- The **getDynamicPage** method uses the Selenium library to obtain dynamically updating pages. This helps when the content on the page loads dynamically. It takes the URL of the page, the saving path, closeWindow, and timeSleep. By default, the Selenium browser opens in the background, and the browser activity is not visible, but if closeWindow is set to False, the code execution process will be visible. The timeSleep parameter can be used to increase the loading time if the content takes a while to load.
- The **gpsa** (get page semi-automatically) method is similar to the getDynamicPage method but operates in a semi-automatic mode. It opens the site page and waits for the Enter key to be pressed in the terminal. During this time, you can register on the site and/or switch to the desired tab, after which pressing Enter will allow the method to parse the page. It accepts the same arguments for the same purposes as getDynamicPage, except for closeWindow.
- The **returnBs4Object** method returns a BeautifulSoup4 object. It takes the path to the HTML page, converts its content into a BeautifulSoup object, the file encoding (default is UTF-8), and the parser type (default is lxml).
- The **getAttributes** method is used to obtain a list of attributes from a list of bs4 objects. It takes a list of bs4 objects and the name of the attribute to be extracted from the list elements.
- The **getTexts** method is used to obtain a list of text from a list of bs4 objects. It takes a list of bs4 objects and the needFix parameter. If this parameter is set to True, \n, \t, and spaces from the ends will be removed from the text.
- The **pprint** method is used to output the values of variables with significant nesting. For example, if you have an array of objects where the value of the key is another array of objects.
- The **mkdir** method is used to create a folder with the name _nameDir_ if it does not already exist.
### Example Parser Using ipars:
```py
# Read about the ProgressBarManager class below
# About the ProgressBarManager class, read below
from ipars import Pars, ProgressBarManager
p = Pars()
nameFile = 'index.html'
# Getting the HTML page
p.getDynamicPage(nameFile, 'https://duckduckgo.com/?q=greenhouse+social+technologies+youtube&iar=videos&atb=v454-1', closeWindow=0)
p.getDynamicPage(nameFile, 'https://duckduckgo.com/?q=теплица+социальных+технологий+youtube&iar=videos&atb=v454-1', closeWindow=0)
# Getting the BeautifulSoup object
# Getting the BeautifulSoup Object
soup = p.returnBs4Object(nameFile)
# Finding all answer cards
# The first results are those we want, while the rest are not. Therefore, we want the first 84 elements
# The first results are what we wanted, and the rest are not. Therefore, we prefer to get the first 84 elements
allCards = soup.find*all(class*='b_NgmZrVnRtV8MZMEjLs')[:84]
# Getting all images
@@ -45,7 +58,7 @@ allImg = [card.find('img') for card in allCards]
# Getting all links
allSrc = p.getAttributes(allImg, 'src')
# Creating the img folder if it doesn't already exist
# Creating a folder img if it does not already exist
nameFolder = 'img'
p.mkdir(nameFolder)
@@ -60,19 +73,23 @@ bar.next()
bar.finish()
```
### Example Using getAttributes and getTexts Methods
### Example Usage of _getAttributes_ and _getTexts_ Methods
```py
from ipars import Pars
p = Pars()
nameFile = 'index.html'
p.getStaticPage('./index.html', 'https://google.com')
soup = p.returnBs4Object('./index.html')
# download the page and get the object bs4 based on it
p.getStaticPage(nameFile, 'https://google.com')
soup = p.returnBs4Object(nameFile)
# Getting the text
allTegA = soup.find_all('a')
a1 = p.getTexts(allTegA, needFix=1)
textsFromA = p.getTexts(allTegA, needFix=1)
p.pprint(a1)
a2 = p.getAttributes(allTegA, 'href')
# Getting the attribute href
attributesFromA = p.getAttributes(allTegA, 'href')
p.pprint(a2)
```
+10 -14
View File
@@ -1,19 +1,18 @@
### Working with ProgressBarManager
The class creates a progress bar for better visibility of code execution. It takes five arguments:
The class creates a progress bar to display the execution process of code. It accepts five arguments:
1. **max**: a required parameter that indicates the maximum number of iterations in the progress bar.
- **max**: a mandatory parameter that indicates the maximum number of iterations in the progress bar.
2. **message**: a message displayed before the progress bar.
- **message**: a message displayed before the progress bar.
3. **color**: the color of the progress bar.
- **color**: the color of the progress bar.
4. **fill**: a character used to fill the completed portion.
- **fill**: a character used to fill the completed part.
5. **width**: the size of the progress bar in characters.
- **width**: the width of the progress bar in characters.
```py
from ipars import ProgressBarManager
bar = ProgressBarManager(100) # Here max is set to 100
@@ -21,11 +20,11 @@ bar = ProgressBarManager(100) # Here max is set to 100
### Brief Overview of ProgressBarManager Methods
1. The **next** method starts the next iteration of the progress bar.
- The **next** method starts the next iteration of the progress bar.
2. The **finish** method completes the progress bar.
- The **finish** method completes the progress bar.
### Example of Using ProgressBarManager
### Example Usage of ProgressBarManager
```py
# Importing libraries
@@ -33,7 +32,6 @@ from ipars import ProgressBarManager
from time import sleep
maxValue = 300
# Creating a default progress bar
bar = ProgressBarManager(maxValue)
@@ -50,17 +48,15 @@ bar = ProgressBarManager(
maxValue,
message='Downloading process',
color='red',
fill='\*',
fill='*',
width=50
)
# Simulating work
for _ in range(maxValue):
sleep(0.1)
bar.next()
# Turning off the progress bar
bar.finish()
```
+7 -7
View File
@@ -1,20 +1,20 @@
### Library for File Handling During Parsing {docsify-ignore-all}
## Library for Working with Files During Parsing {docsify-ignore-all}
During parsing, it is often necessary to download HTML pages and work with JSON and CSV files. This library is designed to simplify the coding tasks for such activities and provides a range of additional features.
During parsing, it's often necessary to download HTML pages and work with JSON and CSV files. This library aims to simplify the coding required for such tasks and also provides a range of additional features.
### The library contains three primary classes
### The library includes three classes for core tasks
1. **Pars** for handling requests and bs4.
2. **JsonManager** for working with JSON.
3. **CsvManager** for handling CSV files.
3. **CsvManager** for working with CSV.
### There are also three auxiliary classes
### There are also three utility classes
1. **ProgressBarManager** for creating progress bars.
2. **TimerManager** for measuring the execution time of specific code.
2. **TimerManager** for tracking the execution time of specific code.
3. **ZipManager** for archiving files and folders.
To install the library:
### Install the library:
```bash
pip install ipars
+3 -3
View File
@@ -10,11 +10,11 @@ t = TimerManager()
### Brief Overview of TimerManager Methods
1. The **start** method marks the starting point of the time measurement.
- The **start** method marks the starting point of the time measurement.
2. The **end** method marks the endpoint of the time measurement.
- The **end** method marks the endpoint of the time measurement.
3. The **getWorkTime** method returns the total execution time in the specified format. Supported formats are seconds, minutes, and hours. The ndigits parameter specifies the number of decimal places for rounding; by default, the number is not rounded.
- The **getWorkTime** method returns the total execution time in the specified format. Supported formats are seconds, minutes, and hours. The ndigits parameter specifies the number of decimal places for rounding; by default, the number is not rounded.
### Example of Using TimerManager
+9 -9
View File
@@ -1,14 +1,14 @@
### Working with ZipManager
The ZipManager class is used for archiving a folder of files. It takes only one argument — the compression level for the files.
The ZipManager class is used for archiving folders of files. It accepts only one argument — one of the possible compression levels:
'none' => No compression
- none — no compression.
'normal' => Normal compression
- normal — standard compression.
'hard' => Increased compression
- hard — increased compression.
'maximum' => Maximum compression
- maximum — maximum compression.
```py
from ipars import ZipManager
@@ -18,13 +18,13 @@ z = ZipManager()
### Brief Overview of ZipManager Methods
1. The **zip_file** method is used to archive a single file. It takes the path to the source file and the path to the output file.
2. The **zip_folder** method is used to archive a directory. It takes the path to the source directory and the path to the output file.
- The **zip_file** method is used for archiving a single file. It accepts the path to the source file and the path to the output file.
### Example of Using ZipManager
- The **zip_folder** method is used for archiving a directory. It accepts the path to the source directory and the path to the output file.
### Example Usage of ZipManager
```py
from ipars import ZipManager
z = ZipManager(compression='maximum')