def shorten_url_with_bitly(url, title): log("shortening url with bitly") c = BitlyConnection(access_token=BITLY_TOKEN) response = c.shorten(url) c.user_link_edit(response["url"],"title",title=title) log("new bitly link:"+response["url"]) return response["url"]
def shorten_url_with_bitly(url, title): log("shortening url with bitly") c = BitlyConnection(access_token=BITLY_TOKEN) response = c.shorten(url) c.user_link_edit(response["url"], "title", title=title) log("new bitly link:" + response["url"]) return response["url"]
def getBitlyLink(self, url): print "Opening bitly connection" connect = Connection("midiphon", self.midiPhonConfig.BitlyApiToken) print "Shortening URL" short = connect.shorten(url) print "Done shortening URL" return short["url"]
def __init__(self, name): self._name = name config = ConfigParser() config.read('{0}.cfg'.format(self._name)) oauth_token = config.get('Twitter', 'oauth_token') oauth_secret = config.get('Twitter', 'oauth_secret') consumer_key = config.get('Twitter', 'consumer_key') consumer_secret = config.get('Twitter', 'consumer_secret') self._twitter = Twitter(auth=OAuth(oauth_token, oauth_secret, consumer_key, consumer_secret)) access_token = config.get('bitly', 'access_token') self._bitly = Connection(access_token=access_token)
def url_shorten(url): url_cache = {} try: url_cache = pickle.load(open(URLCACHE, "rb")) if url_cache.has_key(url): return url_cache[url] except IOError: # Assuming File Not Found pass token = environ["BITLY_TOKEN"] conn = Connection(access_token=token) short_url = conn.shorten(url) url_cache[url] = short_url["url"] pickle.dump(url_cache, open(URLCACHE, "wb")) return short_url["url"]
def url_shorten(self): #checking if the user entered the url #getting the entered url from the entered text variable of myentry self.urladdress = self.entered_url.get() #putting the token generated from bitly self.token1 = "6070e50a9fa9f917ffcf54311c8813227a562dc2" #we create the connection and access the bitly using the token try: self.api1 = Connection(access_token=self.token1) #now shorting the url using bitly self.response = self.api1.shorten(self.urladdress) # setting the received response to display on our label self.shortened_url.set(self.response['url']) except urllib.HTTPError: time.sleep(10) self.shortened_url.set("Poor or No intenet connection")
def get_page_urls(base_url=None, access_token=None, limit=None, config=None): '''Docs...''' config = os.path.expanduser(config or DEFAULT_CONFIG) with open(config) as _: _config = yaml.load(_) or {} conf = _config.get('bitly') or {} access_token = access_token or conf.get('access_token') bitly = Connection(access_token=access_token) data = bitly.user_link_history() for link in data: link['clicks_total'] = bitly.link_clicks(link['aggregate_link']) link['link_encoders_count'] = bitly.link_encoders_count( link['aggregate_link'])['count'] # include timestamp filters return data
class BaseBot(object): def __init__(self, name): self._name = name config = ConfigParser() config.read('{0}.cfg'.format(self._name)) oauth_token = config.get('Twitter', 'oauth_token') oauth_secret = config.get('Twitter', 'oauth_secret') consumer_key = config.get('Twitter', 'consumer_key') consumer_secret = config.get('Twitter', 'consumer_secret') self._twitter = Twitter(auth=OAuth(oauth_token, oauth_secret, consumer_key, consumer_secret)) access_token = config.get('bitly', 'access_token') self._bitly = Connection(access_token=access_token) def get_bitly_url(self, orig_url): data = self._bitly.shorten(orig_url) return data['url'] def tweet(self, message): return self._twitter.statuses.update(status=message)
def shorten_url(url): c = Connection(login=os.environ.get('BITLY_LOGIN'), api_key=os.environ.get('BITLY_API_KEY')) return c.shorten(url)['url']
class UrlShortener: root = Tk() root.geometry('800x500+400+400') root.title('JR-Url_shortener') #this to load in the photo photo = PhotoImage(file="uuu.png") # setting the image as icon root.iconphoto(False, photo) #to make the size of the screen not expandable above the specified screen resolution root.resizable(width='false', height='false') img = ImageTk.PhotoImage(Image.open("img.jpg")) background_img = Label(root, image=img) background_img.pack(fill=BOTH) #creating a string variable for storing what is entered in the entry box entered_url = StringVar() shortened_url = StringVar() def __init__(self): pass def url_shorten(self): #checking if the user entered the url #getting the entered url from the entered text variable of myentry self.urladdress = self.entered_url.get() #putting the token generated from bitly self.token1 = "6070e50a9fa9f917ffcf54311c8813227a562dc2" #we create the connection and access the bitly using the token try: self.api1 = Connection(access_token=self.token1) #now shorting the url using bitly self.response = self.api1.shorten(self.urladdress) # setting the received response to display on our label self.shortened_url.set(self.response['url']) except urllib.HTTPError: time.sleep(10) self.shortened_url.set("Poor or No intenet connection") def quit1(self): self.root.destroy() def copy2clipboard(self): #getting the shortened url from the shortned text variable self.url_short1 = self.shortened_url.get() #copying it to os clipboard using pyperclip pyperclip.copy(self.url_short1) def screen_view(self): self.text1 = Label(self.root, text="Enter url:", font=("Ubuntu Light", 15), height=2, width=20, bg="#004611", fg="white") self.text1.place(x=70, y=60) self.text2 = Label(self.root, text="Shortened url:", font=("Ubuntu Light", 14), height=2, width=20, bg="#004611", fg="white") self.text2.place(x=70, y=180) #justify means where to start typing on screen--left or right self.myEntry = Entry(self.root, width=40, highlightbackground="#001122", font=("Verdana", 10), textvariable=self.entered_url, borderwidth=10, justify=LEFT, highlightthickness=5, relief="flat", background="#127966") self.myEntry.place(x=370, y=60) self.view = Label(self.root, font=("verdanda", 14), height=2, textvariable=self.shortened_url, width=31, bg="white", fg="#004611") self.view.place(x=370, y=180) self.but1 = Button(self.root, text="Generate Short URL", font=("verdanda", 14), height=1, width=15, relief='flat', borderwidth=8, bg="#000011", fg="gold", activebackground="#FF7956", command=lambda: self.url_shorten()) self.but1.place(x=100, y=320) self.but2 = Button(self.root, text="Copy to Clipboard", font=("verdanda", 14), height=1, width=15, relief='flat', borderwidth=8, bg="#000011", fg="gold", activebackground="#FF7956", command=lambda: self.copy2clipboard()) self.but2.place(x=325, y=320) self.but3 = Button(self.root, text="Exit", font=("verdanda", 14), height=1, width=10, relief='flat', borderwidth=8, bg="#000011", fg="gold", activebackground="#FF7956", command=lambda: self.quit1()) self.but3.place(x=560, y=320)
def api(self): if not self._connection: self._connection = Connection(access_token=self.token) return self._connection
load_dotenv('.env') log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=log_format) logger = logging.getLogger(__name__) BITLY_DOMAIN = os.environ['BITLY_DOMAIN'] BITLY_GROUP_GUID = os.environ['BITLY_GROUP_GUID'] if __name__ == '__main__': logger.debug('Logger Initialized') logger.debug('Testing Bitly Api wrapper') bitly = Connection(access_token=os.environ['BITLY_ACCESS_TOKEN']) bitlink = bitly.bitlink('kpiq.io/2NyA91a') links = bitly.group_bitlinks(BITLY_GROUP_GUID, query='http://www.example.com') link = bitly.link_lookup('http://www.example.com/', links) logger.debug('Bitly Search Results:') logger.debug(links) short_url = bitly.shorten('http://www.example.com', BITLY_DOMAIN, BITLY_GROUP_GUID) logger.debug('Short URL:')