Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ A list of super awesome scripts which help automate the boring tasks.
| [wifi_to_eth](https://github.com/adityaarakeri/super-scripts/tree/master/wifi_to_eth) | [crouther](https://github.com/crouther)
|[file_finder](https://github.com/adityaarakeri/super-scripts/tree/master/file_finder) | [poszy](https://github.com/poszy) |
| [makere](https://github.com/adityaarakeri/super-scripts/tree/master/makere) | [aksJain0](https://github.com/aksJain0)
|[url](https://github.com/adityaarakeri/super-scripts/tree/master/url) | [jeancsil](https://github.com/jeancsil)


## Contribuition Guidelines
- Make a **separate folder** for your script.
Expand Down
1 change: 1 addition & 0 deletions url/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
12 changes: 12 additions & 0 deletions url/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# URL Tools
## Usage:

```
python encode.py https://en.wikipedia.org/wiki/Düsseldorf
```

will output:
`https://en.wikipedia.org/wiki/D%C3%BCsseldorf`

### Requirements
Supports both Python 2 and Python 3 out of the box
50 changes: 50 additions & 0 deletions url/encode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('text')


def main():
text = parser.parse_args().text

text = text.replace('http://', 'httpcolomslashslash')
text = text.replace('https://', 'httpscolomslashslash')
text = text.replace('=', 'equal_sign')
text = text.replace('+', 'plus_sign')
text = text.replace('?', 'question_mark')
text = text.replace('&', 'ampersand')

text = encode(text)
text = text.replace('httpcolomslashslash', 'http://')
text = text.replace('httpscolomslashslash', 'https://')
text = text.replace('equal_sign', '=')
text = text.replace('plus_sign', '+')
text = text.replace('question_mark', '?')
text = text.replace('ampersand', '&')

print(text)


def encode(text):
if is_python_2():
import urllib
return urllib.quote(text)

if is_python_3():
import urllib.parse
return urllib.parse.quote(text)

raise RuntimeError("Python 2 or 3 are needed")


def is_python_2():
return sys.version_info.major == 2


def is_python_3():
return sys.version_info.major == 3


if __name__ == '__main__':
main()