Skip to content

Commit

Permalink
Python tools
Browse files Browse the repository at this point in the history
  • Loading branch information
renegarcia committed Jun 2, 2023
1 parent 4c5453e commit 9eacb07
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
10 changes: 10 additions & 0 deletions notes/code.python.pre-commit-black-flake8-isort.md
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)

71 changes: 71 additions & 0 deletions notes/code.python.url-to-title.md
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)

0 comments on commit 9eacb07

Please sign in to comment.