Skip to content

Instantly share code, notes, and snippets.

@Ra1d7
Created August 28, 2019 19:48
Show Gist options
  • Save Ra1d7/9bc98d3375e49b90d5d7d1dc37297ab3 to your computer and use it in GitHub Desktop.
Save Ra1d7/9bc98d3375e49b90d5d7d1dc37297ab3 to your computer and use it in GitHub Desktop.
Shorten URL or a file with URLS
import requests
import os
def clearscreen():
print('\n'*50)
links = []
print('''==== Welcome To ezme.ir URL shortener ====
========= Coded By: Raid7 =========
''')
fileorurl = input('(F)ile or (U)rl?: ').lower()
ProcessThis = input('File or URL to shorten: ')
clearscreen()
def shorten(url):
with requests.get('http://ezme.ir/api.php?url={}'.format(url)) as req:
parse = str(req.content)
parse = parse.replace('b\'','')
parse = parse.replace('\'','')
return parse
if fileorurl == 'f':
try:
with open(ProcessThis) as f:
for line in f.readlines():
link = shorten(line)
links.append(link+'\n')
print(link+':\033[32m{}\033[0m'.format(line))
print('-+-+'*25+'\n')
save = input('Would you like to save the links?(y/n)').lower()
if save =='y':
with open('SHORT_{}'.format(ProcessThis),'a') as s:
s.writelines(links)
print('SAVED AT: {}'.format(s.name))
print('\n-=-=-=-=-=-[\033[32mDONE\033[0m]-=-=-=-=-=-')
except Exception as e:
print('ERROR:\n{}'.format(e))
else:
print(shorten(ProcessThis))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment