示例#1
0
class Adfly:

    def __init__(self):
        self.unshorten = UnshortenIt()
        self.session = requests.session()

    def unshorten_adfly_url(self, adfly_url: str):
        spinner = Halo(text='Grabbing url...', spinner='dots')
        spinner.start(text='Getting url...')

        current_link = adfly_url

        while True:
            try:
                url = self.unshorten.unshorten(uri=current_link)
                current_link = url

                if 'adfly' in url:
                    pass
                else:
                    request = self.session.get(url=url)

                    soup = BeautifulSoup(request.text, 'html.parser')

                    if 'redirecting' in request.url:
                        current_link = soup.find_all('p')[2].text.replace('You will be visiting: ', '')

                    spinner.succeed(text='Successfully retrieved url!')

                    return current_link

            except (InvalidURL, MissingSchema, ConnectionError, NotFound, UnshortenFailed) as exception:
                spinner.fail(text=f'Error: {exception}')
                return
示例#2
0
def button(update,context):
    query=update.callback_query
    query.answer()
    a=query.data
    if a=="unshort":
        unshortener=UnshortenIt()
        uri=unshortener.unshorten(link)
        query.edit_message_text(text="Unshorted url 👇🏼 : \n"+str(uri))
    if a=="short":
        response=s.bitly.short(link)
        query.edit_message_text("Shorted url 👇🏼:\n"+str(response))
示例#3
0
def inlinequery(update,context):
	query = update.inline_query.query
	###for short links#######
	shortlink=s.bitly.short(query)
	#####for unshort link####$#$
	unshortener=UnshortenIt()
	unshortlink=unshortener.unshorten(query)
	
	results=[InlineQueryResultArticle(id=uuid4(),title="short",input_message_content=InputTextMessageContent(shortlink), description="Click to shorten the link"),
                     InlineQueryResultArticle(id=uuid4(),title="unshort",input_message_content=InputTextMessageContent(unshortlink), description="Click to unshort the link")]
	update.inline_query.answer(results)
示例#4
0
def url_unshortener(short_link):
    """
    Расшифровка коротких ссылок

    :param shor_link: короткая ссылка, которую нужно расшифровать.
    :return: возвращает оригинульную ссылку.

    Умеет расшифровывать 300+ сервисов-укорачивателей
    """
    unshortener = UnshortenIt()
    original_url = unshortener.unshorten(short_link)
    return original_url
def deal_with_error():
    new_ids = []
    unshortener = UnshortenIt(default_timeout=20)
    for line in tqdm(open("data/ira-urls-plus-1.json")):
        d = json.loads(line.strip())
        if "error" in d and d["error"] and d["hostname"] not in ["blackmattersus.com", "blacktolive.org"]:
            try:
                url = unshortener.unshorten(d["url"])
                d["final_url"] = url
                d['hostname'] = get_hostname_from_url(url)
                del d["error"]
            except Exception as e:
                print(d["url"])
        
        new_ids.append(d)
    write2json(new_ids)
示例#6
0
def home(request):
    global data
    data = ''

    global title
    title = ""

    global uri
    uri = ''

    global meta
    meta = ''

    global get_domain
    get_domain = ''

    if request.method == 'POST':
        form = UrlForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data.get('url')
            form.save()
            form = UrlForm()

            unshortener = UnshortenIt()
            uri = unshortener.unshorten(data)

            article = Goose().extract(uri)
            title = article.title
            meta = article.meta_description

            domain = tldextract.extract(uri)

            get_domain = domain.domain + '.' + domain.suffix

    else:
        form = UrlForm()

    return render(
        request, 'unmask/home.html', {
            'form': form,
            'ori_link': uri,
            'title': title,
            'meta': meta,
            'domain': get_domain,
            'data': data
        })
示例#7
0
def get_tweets(username):

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)

    #set count to however many tweets you want
    number_of_tweets = 500

    #get tweets
    for tweet in tweepy.Cursor(api.user_timeline,
                               screen_name=username).items(number_of_tweets):
        #create array of tweet information: username, tweet id, date/time, text
        if ("https://t.co/" in tweet.text):
            index = (tweet.text).index('https://t.co')
            t_url = (tweet.text)[index:(index + 24)]
            unshortener = UnshortenIt()
            url = unshortener.unshorten(t_url)
            if ("open.spotify" in url):
                print(url)
示例#8
0
def task(_ids):
    print("{} task starts ... ".format(os.getpid()), len(_ids))
    unshortener = UnshortenIt(default_timeout=20)
    new_ids = []
    for d in tqdm(_ids):
        # if "error" in d and d["error"]:
        #     print(d)
        try:
            d["error"] = False
            if d["short"]:
                # print(d)
                url = unshortener.unshorten(d["url"])
                d["final_url"] = url
                d['hostname'] = get_hostname_from_url(url)
        except Exception as e:
            # print(e); traceback.print_exc(sys.stdout)
            d['error'] = True

        new_ids.append(d)
    write2json(new_ids)

    return new_ids
import csv
import re
from unshortenit import UnshortenIt

unshortener = UnshortenIt()
final = open('locations_coordinates.csv', mode='w')
csv_writer = csv.writer(final, dialect='excel')
with open('locations_link.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    for row in csv_reader:
        url = row[1]
        if len(url) == 31 or len(url) == 32:
            url = unshortener.unshorten(row[1])
        if re.search('@(\-?[0-9]+\.[0-9]+),(\-?[0-9]+\.[0-9]+)', url,
                     re.DOTALL):
            location = re.search('@(\-?[0-9]+\.[0-9]+),(\-?[0-9]+\.[0-9]+)',
                                 url, re.DOTALL)
            latitude = location.groups()[0]
            longitude = location.groups()[1]
            csv_writer.writerow([row[0], latitude, longitude])
            print(
                f'Location {row[0]}: latitude={latitude} and longitude = {longitude}'
            )
        elif re.search('q=(\-?[0-9]+\.[0-9]+),(\-?[0-9]+\.[0-9]+)', url,
                       re.DOTALL):
            location = re.search('q=(\-?[0-9]+\.[0-9]+),(\-?[0-9]+\.[0-9]+)',
                                 url, re.DOTALL)
            latitude = location.groups()[0]
            longitude = location.groups()[1]
            csv_writer.writerow([row[0], latitude, longitude])
            print(
"""Code snippets vol-59
   292-Unshorten a URL

   Download all snippets so far:
   https://wp.me/Pa5TU8-1yg
   Blog: stevepython.wordpress.com

Requirements:
pip3 install unshortenit

https://stackoverflow.com/questions/4201062/how-can-i-unshorten-a-url
"""
from unshortenit import UnshortenIt

unsh = UnshortenIt()
uri = unsh.unshorten('https://wp.me/Pa5TU8-2yD')
print(uri)
示例#11
0
def cli(module, url, follow_nested):
    unshortener = UnshortenIt()
    print(unshortener.unshorten(url, module, unshorten_nested=follow_nested))
示例#12
0
def carga(page):

    global configuracion
    global terminamos
    browser = webdriver.Chrome()
    browser2 = webdriver.Chrome()

    web = 'https://3d-load.net/page/' + str(page) + '/'
    print(' \n Accediendo a: ' + web + '\n' '')
    browser.get(web)
    assert '3DLOAD' in browser.title
    # sleeper(5)

    for a in browser.find_elements_by_class_name('link'):
        links = a.get_attribute('href')
        print(links)
        browser2.get(links)
        # browser2.minimize_window()
        # browser.minimize_window()
        if configuracion['Sitio.De.Descarga']['mega'] == 'si':
            for b in browser2.find_elements_by_class_name(
                    'shortcode.button.red.large'):
                alinks = b.get_attribute('href')
                # print(alinks + '\n')
                unshortener = UnshortenIt()
                uri = unshortener.unshorten(alinks)
                print(uri + '\n')
                igual = uri.find("=")
                total = len(uri)
                file_id = uri[igual + 1:total]
                #            print("Descargando: ", file_id +'\n\n')
                o = urlparse(links)
                #                print(o)
                #                print (o.path)
                oPath = o.path
                #            print("len")
                #            print(len(oPath))

                oPath = oPath[:len(oPath) - 1]
                #            print(oPath)
                a = 0
                while a != -1:
                    a = oPath.find("/")
                    oPath = oPath[a + 1:len(oPath)]
                    ocat = o.path[1:len(o.path)]
                # print(ocat)
                a = ocat.find("/")
                #            print(a)
                file_name = ocat[a + 1:len(ocat) - 1]
                ocat = ocat[0:a]

                #            print(ocat)
                #            print(file_name)
                #            print(file_id)

                listado = open('listado.ini', 'r')
                lista = listado.readlines()
                listado.close()
                # print(lista)
                # print(file_name)
                if file_name + '\n' not in lista:
                    print(" \n Descargando fichero: " + file_name + '\n')
                    os.system('mega-get --ignore-quota-warn ' + file_id +
                              ' ./download/' + file_name)
                    print('\nDescomprimiendo en el directorio \'extract\'')
                    #                        title2 = oPath.replace('-',' ')
                    #                        title2 = title2.title()
                    #                        print(title2)
                    if os.path.isfile(file_name):
                        listado = open("listado.ini",
                                       mode="a",
                                       encoding="utf-8")
                        listado.write(file_name + '\n')
                        listado.close()
                        os.system('unrar x -u "./download/"' + file_name +
                                  ' ./extract/')
                        print('\nBorrando el archivo \'.rar\'')
                        #                        borra = './download/' + title2 + '.rar'
                        #                        os.remove (borra)
                        try:
                            os.remove('./download/' + file_name)
                        except OSError as e:
                            print(e)
                        else:
                            print("File is deleted successfully")
                    with open('3d-load.cfg', 'w') as archivoconfig:
                        configuracion.write(archivoconfig)

                else:
                    print('si está')
                    ultconf = configuracion['Ult.Descargado']['ult.descargado']
                    if ultconf == file_name:
                        terminamos = 1
                        break

    browser.close()
    browser2.close()
示例#13
0
def cli(module, url, follow_nested):
    unshortener = UnshortenIt()
    print(unshortener.unshorten(url, module, unshorten_nested=follow_nested))