diff --git a/README.md b/README.md index 83c7fdb..2ce0463 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/url/.gitignore b/url/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/url/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/url/README.md b/url/README.md new file mode 100644 index 0000000..68c9b16 --- /dev/null +++ b/url/README.md @@ -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 \ No newline at end of file diff --git a/url/encode.py b/url/encode.py new file mode 100644 index 0000000..3562425 --- /dev/null +++ b/url/encode.py @@ -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()