예제 #1
0
def unstar_unread(rss_api, args, configuration):
    if isinstance(args.limit, int):
        limit = args.limit
    else:
        limit = args.limit[0]
    if args.shorten:
        import googl
        apikey = configuration.get('google', 'shortener')
        googleapi = googl.Googl(apikey)

    headlines = rss_api.get_headlines(feed_id=-1,
                                      limit=limit,
                                      view_mode='all_articles',
                                      show_excerpt=False)
    while headlines:
        for head in headlines:
            if args.shorten:
                try:
                    link = googleapi.shorten(head.link)['id']
                except:  # pylint: disable=bare-except
                    link = head.link
            else:
                link = head.link
            message = head.feed_id + ": " + head.feed_title + ": " + head.title + ": " + link
            print(message)
        unstar = input("Unstar messages? (y/n): ")
        if unstar == "y":
            for head in headlines:
                rss_api.update_article(head.id, 0, 0)
        headlines = rss_api.get_headlines(feed_id=-1,
                                          limit=limit,
                                          view_mode='all_articles',
                                          show_excerpt=False)
        print("#" * 80)
예제 #2
0
파일: useful.py 프로젝트: L3viathan/abbott
    def start(self):
        self.listen_for_event("irc.on_privmsg")

        try:
            import googl
        except ImportError:
            print("Please install the python package 'python-googl'")
            raise
        self.shortener = googl.Googl()
예제 #3
0
def shorten_link(soup, link):
    api = googl.Googl(API_KEY)
    googl_link = api.shorten(link.get('href'))
    new_link = Tag(soup, 'a')
    new_link['href'] = googl_link.get('id', None)
    if new_link.get('href', None):
        new_link.setString(link.text)
        return new_link
    else:
        return None
예제 #4
0
def post_link(user, url, title, topic_names):
    '''
	'''
    domain, domain_post = add_link_domain(url)

    link = Link(id=get_available_id(), url=url, user=user, title=title)

    if domain:
        link.domain = domain
    else:
        return False

    if len(url) > URL_MAX_LEN:
        client = googl.Googl("AIzaSyDL2zRCt7DmDZV-1_QQY6HZnterAZ3Kv84")
        try:
            result = client.shorten(url)
        except:
            return False
        else:
            url = result['id']
            link.url = url
    link.save()

    for topic_name in topic_names:
        topic = add_link_topic(topic_name, user, url, domain)
        link.topics.add(topic)

        if not FILTER:
            if topic.topic_links.filter(url__iexact=url).count() == 1:
                Dynamic.objects.create(column=topic.get_column(),
                                       way=WAY_LINK_TOPIC_POST,
                                       content_object=link)

    if not domain_post:
        Dynamic.objects.create(column=domain.get_column(),
                               way=WAY_LINK_DOMAIN_POST,
                               content_object=link)

    Dynamic.objects.create(column=user.userprofile.get_column(),
                           way=WAY_LINK_USER_POST,
                           content_object=link)

    UserData.objects.filter(user=user).update(n_links=F('n_links') + 1)

    return link
예제 #5
0
    req.add_header("Accept-Language", "cs,en-US;q=0.9,en;q=0.8")
    req.add_header("Accept-Encoding", "deflate")
    req.add_header("Cache-Control", "no-cache")
    req.add_header("Connection", "Keep-Alive")

    gotException = None

    try:
        response = urlopen(req)
        html = response.read()
    except HTTPError, e:
        gotException = e
        html = e.read()

    if not url.startswith("http://goo.gl"):
        client = googl.Googl(API_KEY)
        try:
            shorten_url = client.shorten(url)
            shorten_url = shorten_url.get("id", None)

            if shorten_url is not None:
                shorten_url = shorten_url.encode("utf-8", "ignore")
        except Exception, e:
            shorten_url = None
    else:
        shorten_url = None

    if html.find("<title") >= 0:
        try:
            parsed_html = BeautifulSoup(
                html, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
예제 #6
0
    def start(self):
        self.listen_for_event("irc.on_privmsg")

        import googl
        self.shortener = googl.Googl()
예제 #7
0
import time
import googl
import urllib
import unshortenit
import requests
import sys
import configparser
from telebot import types

config = configparser.ConfigParser()
config.sections()
config.read('urlprobot.conf')

min_url_size = config['DEFAULTS']['min_url_size']
bot = telebot.TeleBot(config['DEFAULTS']['bot_token'])
client = googl.Googl(config['DEFAULTS']['google_client'])


def url_shortener(text):
    try:
        args = text
        result = client.shorten(args)
        url_shortened = (result['id'])
        return url_shortened
    except:
        pass


def url_expander(url):
    unshortened_uri, status = unshortenit.unshorten(url)
    return unshortened_uri
예제 #8
0
import googl, clipboard

client = googl.Googl("MyAPIAccessKey")
result = client.shorten(clipboard.get())
clipboard.set(result['id'])