Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release: Up to 10% performance improvement. Adjustments to accomo… #7

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 48 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Schlumberger Petroleum Glossary

Browse the Schlumberger Petroleum Glossary in Python.
Browse the Schlumberger Petroleum Glossary using Python (in English and Spanish).

**For optimum performance, Use the Chrome browser and a fast and stable internet connection.**

Expand All @@ -25,19 +25,17 @@ pip install slb-glossary
import slb_glossary as slb

# Create a glossary object
glossary = slb.Glossary(slb.Browser.CHROME, open_browser=True)

# Search for a term
results = glossary.search("porosity")

# Print the results
for result in results:
print(result.asdict())
with slb.Glossary(slb.Browser.CHROME, open_browser=True) as glossary:
# Search for a term
results = glossary.search("porosity")
# Print the results
for result in results:
print(result.asdict())
```

## Usage

**Please note that this is just a brief overview of the module. The modules is heavily documented and you are encouraged to read the docstrings for more information on the various methods and classes.**
**Please note that this is just a brief overview of the module. The module is properly documented and you are encouraged to read the docstrings for more information on the various methods and classes.**

> "topics" used in the context of this documentation refers to the subjects or topics in the glossary.

Expand All @@ -50,16 +48,17 @@ import slb_glossary as slb
```

To use the glossary, you need to create a `Glossary` object. The `Glossary` class takes a few arguments:
- `browser`: The browser to use. It can be any of the values in the `Browser` enum.
**Ensure you have the browser selected installed on your machine.**
- `open_browser`: A boolean indicating whether to open the browser when searching the glossary or not.
If this is True, a browser window is open when you search for a term. This can be useful for monitoring
and debugging the search process. If you don't need to see the browser window, set this to False.
This is analogous to running the browser in headless mode. The default value is False.
- `page_load_timeout`: The maximum time to wait for a page to load before raising an exception.
- `implicit_wait_time`: The maximum time to wait for an element to be found before raising an exception.
- `language`: The language to use when searching the glossary. This ca be any of the values in the `Language` enum.
Presently, only English and Spanish are supported. The default value is `Language.ENGLISH`.

* `browser`: The browser to use. It can be any of the values in the `Browser` enum.
**Ensure you have the browser selected installed on your machine.**
* `open_browser`: A boolean indicating whether to open the browser when searching the glossary or not.
If this is True, a browser window is open when you search for a term. This can be useful for monitoring
and debugging the search process. If you don't need to see the browser window, set this to False.
This is analogous to running the browser in headless mode. The default value is False.
* `page_load_timeout`: The maximum time to wait for a page to load before raising an exception.
* `implicit_wait_time`: The maximum time to wait for an element to be found before raising an exception.
* `language`: The language to use when searching the glossary. This ca be any of the values in the `Language` enum.
Presently, only English and Spanish are supported. The default value is `Language.ENGLISH`.

```python
glossary = slb.Glossary(slb.Browser.CHROME, open_browser=True)
Expand Down Expand Up @@ -108,11 +107,12 @@ results = glossary.search("porosity")
```

This returns a list of [`SearchResult`](#search-results)s for "porosity". You can also pass some optional arguments to the `search` method:
- `under_topic`: Streamline search to a specific topic
- `start_letter`: Limit the search to terms starting with the given letter(s)
- `max_results`: Limit the number of results returned.

### Search for a term under a specific topic
* `under_topic`: Streamline search to a specific topic
* `start_letter`: Limit the search to terms starting with the given letter(s)
* `max_results`: Limit the number of results returned.

### Search for terms under a specific topic/subject

```python
results = glossary.get_terms_on(topic="Well workover")
Expand All @@ -123,14 +123,17 @@ The difference between `search` and `get_terms_on` is that `search` searches the

The topic passed need not be an exact match to what is in the glossary. The glossary will choose the closest match to the provided topic that is available in the glossary.

> Interesting fact: If you want to base your search on multiple topics, just pass a string with the topics separated by a comma. For example, `"Drilling, Well workover, Shale gas"`.

### Search results

Search results are returned as `SearchResult` objects. Each `SearchResult` object has the following attributes:
- `term`: The term being searched for
- `definition`: The definition of the term
- `grammatical_label`: The grammatical label of the term. Basically the part of speech of the term
- `topic`: The topic under which the term is found
- `url`: The URL to the term in the glossary

* `term`: The term being searched for
* `definition`: The definition of the term
* `grammatical_label`: The grammatical label of the term. Basically the part of speech of the term
* `topic`: The topic under which the term is found
* `url`: The URL to the term in the glossary

To get the search results as a dictionary, use the `asdict` method.

Expand All @@ -151,9 +154,20 @@ for result in results:
### Other methods

Some other methods available in the `Glossary` class are:
- `get_search_url`: Returns the correct glossary url for the given parameters.
- `get_terms_urls`: Returns the URLs of all terms gotten using the given parameters.
- `get_results_from_url`: Extracts search results from a given URL. Returns a list of `SearchResult`s.

* `get_search_url`: Returns the correct glossary url for the given parameters.
* `get_terms_urls`: Returns the URLs of all terms gotten using the given parameters.
* `get_results_from_url`: Extracts search results from a given URL. Returns a list of `SearchResult`s.

### Closing the glossary

When you are done using the glossary, it is important that you close it to free up resources. This is done by calling the `close` method.

```python
glossary.close()
```

If you used the `Glossary` object as a context manager, you don't need to call the `close` method. The `Glossary` object will automatically close itself when the context manager exits. Also, on normal termination of the program, the `Glossary` object will close itself (If it is not already closed).

### Save/export search results to a file

Expand Down Expand Up @@ -187,7 +201,7 @@ Read the docstrings of the `Saver` class to get a good grasp of how to do this.

There are two ways you can use your custom saver class.

1; Create a `Glossary` subclass:
1. Create a `Glossary` subclass:

```python
import slb_glossary as slb
Expand All @@ -200,7 +214,7 @@ glossary = FooGlossary(...)
glossary.saver.save(...)
```

2; Instantiate a saver directly
2. Instantiate a saver directly

```python
saver = FooSaver()
Expand Down
Binary file added dist/slb_glossary-0.0.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/slb_glossary-0.0.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion slb_glossary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .saver import Saver


__version__ = '0.0.1b'
__version__ = '0.0.1'
__all__ = [
'Glossary',
'Saver',
Expand Down
Loading