Created
April 25, 2018 13:45
-
-
Save thismusicdude/1b09aa116afd7e7abb95fc20120172da to your computer and use it in GitHub Desktop.
A little fancy Python class to generate an AdFly-Link. It uses the official Adf.ly Api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Author: github.com/ponyschreck | |
| # Latest Update: 25.4.2018 | |
| import urllib.request | |
| class Adpy(): | |
| """ | |
| A little fancy Python-Class to generate an AdFly-Link | |
| """ | |
| def __init__(self, public_key: str, user_id: str): | |
| """ | |
| Sets LogIn-Values | |
| :param public_key: User Key | |
| :param user_id: User ID | |
| """ | |
| self.public_key = public_key | |
| self.user_id = user_id | |
| def generate_link(self, _url: str, ad_type: str = "int"): | |
| """ | |
| generates an adf.ly link | |
| :param _url: Url to convert | |
| :param ad_type: the ad-type "banner" or "int" redirected Link | |
| :return: new adf.ly link as string | |
| """ | |
| apiurl = "" | |
| apiurl += "http://api.adf.ly/api.php?key=" + self.public_key + \ | |
| "&uid=" + self.user_id + \ | |
| "&advert_type=" + ad_type +\ | |
| "&url=" + _url | |
| try: | |
| s = urllib.request.urlopen(apiurl) | |
| res = s.read() | |
| s.close() | |
| return res.decode("utf-8") | |
| except urllib.request.HTTPError as e: | |
| print("ERROR - ADFLY_API: " + e.msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment