1+ import os
12import re
23
34import pyshorteners
78
89from .forms import get_url
910
11+ BITLY_API_KEY = os .environ .get ("BITLY_API_KEY" )
12+ CUTLLY_API_KEY = os .environ .get ("CUTLLY_API_KEY" )
13+
1014
1115def generate_url (request ):
1216 form = get_url (request .POST or None )
@@ -46,7 +50,7 @@ def generate_url(request):
4650 s = pyshorteners .Shortener ()
4751 shortened_url = s .tinyurl .short (long_url )
4852 elif site == "bitly" :
49- s = pyshorteners .Shortener (api_key = 'de36c105ae76331609a19ff1ce2d391012d5710a' )
53+ s = pyshorteners .Shortener (api_key = BITLY_API_KEY )
5054 shortened_url = s .bitly .short (long_url )
5155 elif site == "chilpit" :
5256 s = pyshorteners .Shortener ()
@@ -55,7 +59,7 @@ def generate_url(request):
5559 s = pyshorteners .Shortener ()
5660 shortened_url = s .clckru .short (long_url )
5761 elif site == "cuttly" :
58- s = pyshorteners .Shortener (api_key = '3745d515279a2c9396a5144c99c0017ed81b9' )
62+ s = pyshorteners .Shortener (api_key = CUTLLY_API_KEY )
5963 shortened_url = s .cuttly .short (long_url )
6064 elif site == "dagd" :
6165 s = pyshorteners .Shortener ()
@@ -66,4 +70,4 @@ def generate_url(request):
6670 except pyshorteners .exceptions .ShorteningErrorException as e :
6771 error_message = "Failed to shorten the URL. Please try again later."
6872
69- return render (request , 'home.html' , {'form' : form , 'shortened_url' : shortened_url , 'error_message' : error_message })
73+ return render (request , 'home.html' , {'form' : form , 'shortened_url' : shortened_url , 'error_message' : error_message })
0 commit comments