-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c5453e
commit 9eacb07
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
id: qpru2s8dnotjix9okh0haqe | ||
title: Recomended tools to build python software | ||
desc: '' | ||
updated: 1685733092275 | ||
created: 1685731303027 | ||
--- | ||
|
||
[How To Use Black Flake8 And Isort To Format Python Codes](http://www.sefidian.com/2021/08/03/how-to-use-black-flake8-and-isort-to-format-python-codes) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
id: g4q8yp5c8b2h1nlehk01cxt | ||
title: URL to title | ||
desc: '' | ||
updated: 1685733865624 | ||
created: 1685733525402 | ||
--- | ||
|
||
Simple program that reads an url and prints the last part of the path as a title. | ||
|
||
<script src="https://gist.github.com/renegarcia/9e80f1c84c57753b5aa4e19f0b8198db.js"></script> | ||
|
||
# Code | ||
|
||
```python | ||
from urllib.parse import urlparse | ||
|
||
def get_last_path(url:str) -> str: | ||
# Parse the URL | ||
parsed_url = urlparse(url) | ||
|
||
# Get the path from the parsed URL | ||
path = parsed_url.path | ||
|
||
# Split the path by slashes and get the last part | ||
path_parts = path.split('/') | ||
last_part = path_parts[-1] | ||
|
||
return last_part | ||
|
||
def path_to_title(path:str) -> str: | ||
return path.replace("-", " ").title() | ||
|
||
def main(): | ||
url = input("Enter the URL: ") | ||
path = get_last_path(url) | ||
title = path_to_title(path) | ||
print(title) | ||
|
||
if __name__ == "__main__": | ||
while True: | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
break | ||
``` | ||
|
||
# Case of use | ||
|
||
I use this to format references in my mardown documents. For example, given the url | ||
|
||
``` | ||
https://stackoverflow.com/questions/76392847/flutter-firebase-to-python-firebase | ||
``` | ||
|
||
The program outputs | ||
|
||
``` | ||
Flutter Firebas To Python Firebase | ||
``` | ||
|
||
which I use to link to the question, like so: | ||
|
||
```markdown | ||
[Flutter Firebas To Python Firebase](https://stackoverflow.com/questions/76392847/flutter-firebase-to-python-firebase) | ||
``` | ||
|
||
# References | ||
|
||
* [Gist version](https://gist.github.com/renegarcia/9e80f1c84c57753b5aa4e19f0b8198db) | ||
* [Interactive version in a jupyter notebook](https://colab.research.google.com/drive/1MhXnLZnS7I_oaRjYExcg63TND32YDcHL?usp=sharing) |