• Re: No more Redirect page.

    From Lawrence D?Oliveiro@3:633/10 to All on Sat Jul 25 04:33:42 2026
    On Fri, 24 Jul 2026 11:03:09 -0400, micky wrote:

    You may have noticed by now that clicking on Google search links
    sometimes or always makes you stop at a page to "permit" redirection
    to another page, even though you clicked on it in the first place
    and even though it never did this before. "The "redirect notice"
    page usually appears because Google wraps outbound links with a
    tracking parameter (google.com/url) to gather analytics and scan for malicious URLs".

    I often copy and paste links into the following script for this reason.

    Feel free to experiment with this as appropriate. Note the ?--unquote?
    option, because sometimes I find the wrapped URL has an extra
    (needless) level of quoting.
    ----
    #!/usr/bin/python3
    #+
    # Given a URL from various sites that like to include redirection
    # capture cruft, extract the URL and discard the cruft.
    #-

    import sys
    import re
    from urllib import \
    parse as urlparse
    import getopt

    start_marker = r"\=(https?(\:\/\/|\%3a\%2f\%2f))"

    show_original = False
    force_unquote = False
    opts, args = getopt.getopt \
    (
    sys.argv[1:],
    "",
    ["original", "unquote"]
    )
    for keyword, value in opts :
    if keyword == "--original" :
    show_original = True
    elif keyword == "--unquote" :
    force_unquote = True
    #end if
    #end for
    urls = args

    if len(urls) == 0 :
    raise getopt.GetoptError("pass at least one URL to unredirect")
    #end if
    for url in urls :
    matches = list(re.compile(start_marker, re.IGNORECASE).finditer(url))
    if len(matches) != 0 :
    match = matches[-1]
    startpos = match.start(1)
    endpos = url.find("&", match.end(1))
    if endpos < 0 :
    endpos = len(url)
    #end if
    actual = url[startpos : endpos]
    if match.group(2).startswith("%") or force_unquote :
    actual = urlparse.unquote(actual)
    #end if
    if show_original :
    sys.stdout.write("%s => " % url)
    #end if
    sys.stdout.write("%s\n" % actual)
    else :
    sys.stdout.write("# Cannot understand: %s\n" % url)
    #end if
    #end for

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Gilmeh Serda@3:633/10 to All on Sat Jul 25 15:59:03 2026
    On Sat, 25 Jul 2026 04:33:42 -0000 (UTC), Lawrence D?Oliveiro wrote:

    I often copy and paste links into the following script for this reason.

    Why not use pyperclip? Then you can just use clipboard:

    1. Copy original URL
    2. Run script (+ options)
    3. Paste resulting URL

    https://pypi.org/project/pyperclip/

    You may also want to read this: https://github.com/asweigart/pyperclip/blob/master/src/pyperclip/
    __init__.py row 19.


    If there are only a few options you might even wanna create an alias for
    each version, like scra and scrb or something and put it in your .bashrc:

    alias scra='scriptname -option1';
    alias scrb='scriptname -option2';

    Your use of shebang suggests *nix, so...


    If I think ArgumentParser is too bulky for a small script, I usually just
    use sys module, which you already have imported.

    def main(opt):
    URL = pyperclip.paste()

    if opt == 1:
    [...]
    elif opt == 2:
    [...]

    pyperclip.copy(resulting_URL)

    if __name__ == '__main__':
    args = sys.argv[1:]
    if '-option1' in args:
    main(1)
    elif '-option2' in args:
    main(2)
    else:
    print(usage)

    But each to their own... It's your script.

    --
    Gilmeh

    Everybody likes a kidder, but nobody lends him money. -- Arthur Miller

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Gilmeh Serda@3:633/10 to All on Sun Jul 26 18:32:03 2026
    On 25 Jul 2026 16:24:37 GMT, Stefan Ram wrote:

    I read from the clipboard all the time, but prefer to
    use the standard library, so I,

    You do you.

    --
    Gilmeh

    This is the theory that Jack built. This is the flaw that lay in the
    theory that Jack built. This is the palpable verbal haze that hid the flaw that lay in...

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)