I'm a newbie and surprised there's already not a clear answer similar to what I'm asking, apologies if this is a duplicate.
I have a list of URLs in a CSV file I'm trying to shorten, I want to loop through my CSV file and then write a new column with the shortened URL right next to the original URL.
from pyshorteners import Shortener
import csv
def generate_short(url):
x = shortener.short(url)
return x
with open('Links_Test.csv') as csvfile:
my_date = csv.reader(csvfile, dialect = 'excel')
for row in my_data:
x = shortener.short(row)
print(X)
EDIT: I keep getting the error "ValueError: Please enter a valid url" and don't know how to proceed from here.....I'm sure I'm the problem.
Here's what my input data looks like:
URL
http://www.google.com
http://www.facebook.com
http://www.twitter.com
http://www.linkedin.com
and here's what I want my output to look like:
URL Short_URL
http://www.google.com http://goo.gle
http://www.facebook.com http://goo.g3c
http://www.twitter.com http://goo.g3a
http://www.linkedin.com http://goo.g2q
Thank you for your help. I was very surprised there's not already a clear answer posted (at least I couldn't find it) so I'm sorry if this is a duplicate.