Skip to content

Instantly share code, notes, and snippets.

@palcu
Created March 16, 2016 13:04
Show Gist options
  • Save palcu/3c8e92a38905a3bb79b8 to your computer and use it in GitHub Desktop.
Save palcu/3c8e92a38905a3bb79b8 to your computer and use it in GitHub Desktop.

Revisions

  1. palcu created this gist Mar 16, 2016.
    14 changes: 14 additions & 0 deletions script.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    import csv

    urls = []
    with open('links.csv') as stream:
    for line in stream:
    url = line.strip()
    if 'http' in url and 'https' not in url:
    better_url = url.replace('http', 'https', 1) # replace only first occurence
    urls.append([url, better_url])

    with open('mapped.csv', 'w', newline='') as csvfile:
    csvwriter = csv.writer(csvfile)
    for url in urls:
    csvwriter.writerow(url)