def curseDatastore(addonpage):
    try:
        # First, look for the URL of the project file page
        page = requests.get(addonpage)
        page.raise_for_status()  # Raise an exception for HTTP errors
        contentString = str(page.content)
        endOfProjectPageURL = contentString.find('">Visit Project Page')
        indexOfProjectPageURL = (
            contentString.rfind('<a href="', 0, endOfProjectPageURL) + 9)
        projectPage = (
            contentString[indexOfProjectPageURL:endOfProjectPageURL] +
            "/files")

        # Then get the project page and get the URL of the first (most recent) file
        page = requests.get(projectPage)
        page.raise_for_status()  # Raise an exception for HTTP errors
        projectPage = (
            page.url
        )  # We might get redirected, need to know where we ended up.
        contentString = str(page.content)
        startOfTable = contentString.find("project-file-name-container")
        indexOfZiploc = (contentString.find(
            '<a class="button tip fa-icon-download icon-only" href="/',
            startOfTable) + 55)
        endOfZiploc = contentString.find('"', indexOfZiploc)

        # Add on the first part of the project page URL to get a complete URL
        endOfProjectPageDomain = projectPage.find("/", 8)
        projectPageDomain = projectPage[0:endOfProjectPageDomain]
        return projectPageDomain + contentString[indexOfZiploc:endOfZiploc]
    except Exception:
        print("Failed to find downloadable zip file for addon. Skipping...\n")
        return ""
Esempio n. 2
0
    def test_commitWithMultipleReferencesButOnlyOneVerb(self):
        cards = []
        names = ["To Be Closed", "To Be Referenced", "Another To Be Referenced"]
        for name in names:
            cardInfo = {'name': name, 'idList': PUBLIC_LIST, 'token': TOKEN, 'key': API_KEY}
            cards.append(requests.post(BASE_URL+"/cards", data=cardInfo).json)

        cardIds = (cards[0]['idShort'], cards[1]['idShort'], cards[2]['idShort'])
        message = "Fixed tr#%s, tr#%s, tr#%s " % cardIds
                    
        commit = {'message': message}
        self.broker.handleCommit(commit)

        params = {'actions': 'commentCard', 'members': 'true', 'fields': 'closed'}

        # First card should be closed
        idShort = cards[0]['idShort']
        card = requests.get(CARD_URL % (self.broker.board, idShort), params=params).json
        self.assertEqual(card['actions'][0]["data"]["text"], message)
        self.assertTrue(self.author in card['members'])
        self.assertTrue(card['closed'])

        # Second card should not be closed
        idShort = cards[1]['idShort']
        card = requests.get(CARD_URL % (self.broker.board, idShort), params=params).json
        self.assertEqual(card['actions'][0]["data"]["text"], message)
        self.assertTrue(self.author in card['members'])
        self.assertFalse(card['closed'])

        # Third card should be closed also
        idShort = cards[2]['idShort']
        card = requests.get(CARD_URL % (self.broker.board, idShort), params=params).json
        self.assertEqual(card['actions'][0]["data"]["text"], message)
        self.assertTrue(self.author in card['members'])
        self.assertFalse(card['closed'])
Esempio n. 3
0
    def test_commitWithMultipleReferencesButOnlyOneVerb(self):
        cards = []
        names = [
            "To Be Closed", "To Be Referenced", "Another To Be Referenced"
        ]
        for name in names:
            cardInfo = {
                'name': name,
                'idList': PUBLIC_LIST,
                'token': TOKEN,
                'key': API_KEY
            }
            cards.append(
                requests.post(BASE_URL + "/cards", data=cardInfo).json)

        cardIds = (cards[0]['idShort'], cards[1]['idShort'],
                   cards[2]['idShort'])
        message = "Fixed tr#%s, tr#%s, tr#%s " % cardIds

        commit = {'message': message}
        self.broker.handleCommit(commit)

        params = {
            'actions': 'commentCard',
            'members': 'true',
            'fields': 'closed'
        }

        # First card should be closed
        idShort = cards[0]['idShort']
        card = requests.get(CARD_URL % (self.broker.board, idShort),
                            params=params).json
        self.assertEqual(card['actions'][0]["data"]["text"], message)
        self.assertTrue(self.author in card['members'])
        self.assertTrue(card['closed'])

        # Second card should not be closed
        idShort = cards[1]['idShort']
        card = requests.get(CARD_URL % (self.broker.board, idShort),
                            params=params).json
        self.assertEqual(card['actions'][0]["data"]["text"], message)
        self.assertTrue(self.author in card['members'])
        self.assertFalse(card['closed'])

        # Third card should be closed also
        idShort = cards[2]['idShort']
        card = requests.get(CARD_URL % (self.broker.board, idShort),
                            params=params).json
        self.assertEqual(card['actions'][0]["data"]["text"], message)
        self.assertTrue(self.author in card['members'])
        self.assertFalse(card['closed'])
Esempio n. 4
0
def list_params(username, password, application_name):
    """
    List Parameters

    :param username: Admin Username
     :type username: str
    :param password: Admin Password
     :type password: str
    :param application_name: Application Name to which the Parameter is Associated
     :type application_name: str
    :return: List of all parameters
     :rtype: list
    """
    params = requests.get(os.getenv("key_server_site") +
                          "/rest/param/list?app=" + application_name,
                          auth=(username, password))

    try:
        assert params.status_code == 200

        return params.json()
    except AssertionError:
        exit(
            "Problem listing Params (Check Server Logs for Details) - HTTP Status: %i"
            % params.status_code)
Esempio n. 5
0
def list_apps(username, password):
    """
    List Applications

    :param username: Admin Username
     :type username: str
    :param password: Admin Password
     :type password: str
    :return: List of all Applications
     :rtype: list
    """
    apps = requests.get(os.getenv("key_server_site") + "/rest/app/list",
                        auth=(username, password))

    try:
        assert apps.status_code == 200

        return_lists = list()
        for app in apps.json():
            return_lists.append(app["name"])

        return return_lists
    except AssertionError:
        exit(
            "Problem Listing Apps (Check Server Logs for Details) - HTTP Status: %i"
            % apps.status_code)
def getCurseProjectVersion(addonpage):
    try:
        page = requests.get(addonpage + '/files')
        if page.status_code == 404:
            # Maybe the project page got moved to WowAce?
            page = requests.get(addonpage)
            page.raise_for_status() # Raise an exception for HTTP errors
            page = requests.get(page.url + '/files') # page.url refers to the place where the last one redirected to
            page.raise_for_status()   # Raise an exception for HTTP errors
        contentString = str(page.content)
        startOfTable = contentString.find('project-file-list-item')
        indexOfVer = contentString.find('data-name="', startOfTable) + 11  # first char of the version string
        endTag = contentString.find('">', indexOfVer)  # ending tag after the version string
        return contentString[indexOfVer:endTag].strip()
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
Esempio n. 7
0
def installSingleLevelZip(addonUrl, installPath):
    try:
        r = requests.get(addonUrl, stream=True)
        z = zipfile.ZipFile(BytesIO(r.content))
        z.extractall(installPath)
    except Exception as err:
        print('Failed to install ' + addonUrl)
        print(err)
def getCurseVersion(addonpage):
    try:
        page = requests.get(addonpage + '/files')
        html_parser = BeautifulSoup(page.content, 'html.parser')
        version = html_parser.find_all(class_="table__content file__name full")[0].text
        return version
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
Esempio n. 9
0
def getCard(self, cardId, fields=""):
    """Get the card data based on its short ID.

    Keyword arguments:
    cardId -- the short id of the card to query.
    fields -- a list of fields to return, default to none.

    """
    params = {"token": self.token, "key": API_KEY, "fields": fields}
    return requests.get(BOARD_CARD_URL % (self.board, cardId), params=params).json
Esempio n. 10
0
def get_tukui_version(addonpage):
    try:
        page = requests.get(addonpage)
        content_string = str(page.content)
        date_added_pos = content_string.find('and was updated on') + 38
        date_added = content_string[date_added_pos:date_added_pos + 10]
        return date_added.replace("-", ".")
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
Esempio n. 11
0
def curse(addonpage):
    try:
        page = requests.get(addonpage + '/download')
        contentString = str(page.content)
        indexOfZiploc = contentString.find('download__link') + 22  # Will be the index of the first char of the url
        endQuote = contentString.find('"', indexOfZiploc)  # Will be the index of the ending quote after the url
        return 'https://www.curseforge.com' + contentString[indexOfZiploc:endQuote]
    except Exception:
        print('Failed to find downloadable zip file for addon. Skipping...\n')
        return ''
 def getAddon(self, ziploc):
     if ziploc == '':
         return
     try:
         r = requests.get(ziploc, stream=True)
         z = zipfile.ZipFile(BytesIO(r.content))
         z.extractall(self.WOW_ADDON_LOCATION)
     except Exception:
         print('Failed to download or extract zip file for addon. Skipping...\n')
         return
Esempio n. 13
0
def getCurseVersion(addonpage):
    try:
        page = requests.get(addonpage + '/files')
        contentString = str(page.content)
        indexOfVer = contentString.find('file__name full') + 17  # first char of the version string
        endTag = contentString.find('</span>', indexOfVer)  # ending tag after the version string
        return contentString[indexOfVer:endTag].strip()
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
Esempio n. 14
0
def convertOldCurseURL(addonpage):
    try:
        # Curse has renamed some addons, removing the numbers from the URL. Rather than guess at what the new
        # name and URL is, just try to load the old URL and see where Curse redirects us to. We can guess at
        # the new URL, but they should know their own renaming scheme better than we do.
        page = requests.get(addonpage)
        return page.url
    except Exception:
        print('Failed to find the current page for old URL "' + addonpage + '". Skipping...\n')
        return ''
Esempio n. 15
0
def getWowinterfaceVersion(addonpage):
    try:
        page = requests.get(addonpage)
        contentString = str(page.content)
        indexOfVer = contentString.find('id="version"') + 22  # first char of the version string
        endTag = contentString.find('</div>', indexOfVer)  # ending tag after the version string
        return contentString[indexOfVer:endTag].strip()
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
    def _get_dict(self, url, query_string):
        """
        Helper method to streamline the process of making calls to the rest endpoint and outputting a dictionary.
        :param query_string: Everything following the ? in the url.
        :return: Dictionary created from the JSON response.
        """
        # create url for rest call
        url = "{0}?{1}".format(url, query_string)

        # make the rest endpoint call, load into a dictionary and return the json result
        return requests.get(url).json()
Esempio n. 17
0
def wowinterface(addonpage):
    downloadpage = addonpage.replace('info', 'download')
    try:
        page = requests.get(downloadpage + '/download')
        contentString = str(page.content)
        indexOfZiploc = contentString.find('Problems with the download? <a href="') + 37  # first char of the url
        endQuote = contentString.find('"', indexOfZiploc)  # ending quote after the url
        return contentString[indexOfZiploc:endQuote]
    except Exception:
        print('Failed to find downloadable zip file for addon. Skipping...\n')
        return ''
Esempio n. 18
0
def get_curse_project_version(addonpage):
    try:
        page = requests.get(addonpage + '/files')
        content_string = str(page.content)
        date_added_pos = content_string.find(
            '<abbr class="tip standard-date standard-datetime" title="') + 57
        date_added = content_string[date_added_pos:date_added_pos + 19]
        return date_added
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
    def _get_dict(self, url, query_string):
        """
        Helper method to streamline the process of making calls to the rest endpoint and outputting a dictionary.
        :param query_string: Everything following the ? in the url.
        :return: Dictionary created from the JSON response.
        """
        # create url for rest call
        url = "{0}?{1}".format(url, query_string)

        # make the rest endpoint call, load into a dictionary and return the json result
        return requests.get(url).json()
Esempio n. 20
0
 def getAddon(self, ziploc, subfolder):
     if ziploc == '':
         return False
     try:
         r = requests.get(ziploc, stream=True)
         z = zipfile.ZipFile(BytesIO(r.content))
         self.extract(z, ziploc, subfolder)
         return True
     except Exception:
         print('Failed to download or extract zip file for addon. Skipping...\n')
         return False
Esempio n. 21
0
def getCard(self, cardId, fields = ''):
    """Get the card data based on its short ID.

    Keyword arguments:
    cardId -- the short id of the card to query.
    fields -- a list of fields to return, default to none.

    """
    params = {'token': self.token, 'key': API_KEY, 'fields': fields}
    return requests.get(BOARD_CARD_URL % (self.board, cardId), 
                        params=params).json
Esempio n. 22
0
def search_for_bridge(timeout=3):
    """Searches for a bridge on the local network and returns the IP if it
    finds one."""
    from packages import requests

    r = requests.get('http://www.meethue.com/api/nupnp', timeout=timeout)
    bridges = r.json()

    if len(bridges) > 0:
        return bridges[0]['internalipaddress']
    else:
        return None
Esempio n. 23
0
 def getAddon(self, ziploc, subfolder):
     if ziploc == '':
         return False
     try:
         r = requests.get(ziploc, stream=True)
         r.raise_for_status()   # Raise an exception for HTTP errors
         z = zipfile.ZipFile(BytesIO(r.content))
         self.extract(z, ziploc, subfolder)
         return True
     except Exception as e:
         print('Failed to download or extract zip file for addon (' + str(e) + '). Skipping...\n')
         return False
Esempio n. 24
0
def getWowAceProjectVersion(addonpage):
    try:
        page = requests.get(addonpage + '/files')
        page.raise_for_status()   # Raise an exception for HTTP errors
        contentString = str(page.content)
        startOfTable = contentString.find('project-file-list-item')
        indexOfVer = contentString.find('data-name="', startOfTable) + 11  # first char of the version string
        endTag = contentString.find('">', indexOfVer)  # ending tag after the version string
        return contentString[indexOfVer:endTag].strip()
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
Esempio n. 25
0
def curseProject(addonpage):
    try:
        # Apparently the Curse project pages are sometimes sending people to WowAce now.
        # Check if the URL forwards to WowAce and use that URL instead.
        page = requests.get(addonpage)
        page.raise_for_status()  # Raise an exception for HTTP errors
        if page.url.startswith("https://www.wowace.com/projects/"):
            return wowAceProject(page.url)
        return addonpage + "/files/latest"
    except Exception:
        print("Failed to find downloadable zip file for addon. Skipping...\n")
        return ""
Esempio n. 26
0
def getTukuiVersion(addonpage):
    try:
        response = requests.get(addonpage)
        content = str(response.content)
        match = re.search('<a\sclass="commit-sha\s[^>]*>(?P<hash>[^<]*)<\/a>', content)
        result = ''
        if match:
            result = match.group('hash')
        return result
    except Exception as err:
        print('Failed to find version number for: ' + addonpage)
        print(err)
        return ''
Esempio n. 27
0
def curse(addonpage):
    if '/datastore' in addonpage:
        return curseDatastore(addonpage)
    try:
        page = requests.get(addonpage + '/download')
        page.raise_for_status()   # Raise an exception for HTTP errors
        contentString = str(page.content)
        indexOfZiploc = contentString.find('PublicProjectDownload.countdown') + 33  # Will be the index of the first char of the url
        endQuote = contentString.find('"', indexOfZiploc)  # Will be the index of the ending quote after the url
        return 'https://www.curseforge.com' + contentString[indexOfZiploc:endQuote]
    except Exception:
        print('Failed to find downloadable zip file for addon. Skipping...\n')
        return ''
Esempio n. 28
0
def getGithubVersion(addonpage):
    try:
        page = requests.get(addonpage)
        page.raise_for_status()   # Raise an exception for HTTP errors
        contentString = str(page.content)
        contentString = contentString.replace('\\n', '').replace('\\r', '')
        indexOfCommit = contentString.find('commit-tease-sha') # index of wrapping <a> for latest commit id
        indexOfVer = contentString.find('>', indexOfCommit) + 1  # find end of tag
        endTag = contentString.find('</a>', indexOfVer)  # ending tag
        return contentString[indexOfVer:endTag].strip()
    except Exception:
        print('Failed to find version number for: ' + addonpage)
        return ''
Esempio n. 29
0
def getWowinterfaceVersion(addonpage):
    try:
        page = requests.get(addonpage)
        page.raise_for_status()  # Raise an exception for HTTP errors
        contentString = str(page.content)
        indexOfVer = (contentString.find('id="version"') + 22
                      )  # first char of the version string
        endTag = contentString.find(
            "</div>", indexOfVer)  # ending tag after the version string
        return contentString[indexOfVer:endTag].strip()
    except Exception:
        print("Failed to find version number for: " + addonpage)
        return ""
Esempio n. 30
0
def tukui(addonpage):
    try:
        page = requests.get(addonpage)
        addon_name = addonpage.replace(
            'https://www.tukui.org/download.php?ui=', '')
        content_string = str(page.content)
        index_of_cur_ver = content_string.find('The current version')
        index_of_ver = content_string.find('">', index_of_cur_ver) + 2
        end_tag = content_string.find('</b>', index_of_cur_ver)
        version = content_string[index_of_ver:end_tag]
        return 'https://www.tukui.org/downloads/' + addon_name + '-' + version + '.zip'
    except Exception:
        print('Failed to find downloadable zip file for addon. Skipping...\n')
        return ''
Esempio n. 31
0
 def setUp(self):
     if not hasattr(self, 'broker'):
         self.broker = TrelloBroker()
         self.broker.token = TOKEN
         self.broker.board = PUBLIC_BOARD
         
     if not hasattr(self, 'author'):
         self.author = requests.get(MEMBER_URL).json
         
     # Create a test card and store its full and short IDs
     cardInfo = {'name': 'Test Me', 'idList': PUBLIC_LIST, 'token': TOKEN, 'key': API_KEY}
     card = requests.post(BASE_URL+"/cards", data=cardInfo).json
     self.cardIdFull = card['id']
     self.cardIdShort = card['idShort']
Esempio n. 32
0
def main():
    if(isfile('changelog.txt')):
        downloadedChangelog = requests.get('https://raw.githubusercontent.com/kuhnerdm/wow-addon-updater/master/changelog.txt').text.split('\n')
        with open('changelog.txt') as cl:
            presentChangelog = cl.readlines()
            for i in range(len(presentChangelog)):
                presentChangelog[i] = presentChangelog[i].strip('\n')

    if(downloadedChangelog != presentChangelog):
        print('A new update to WoWAddonUpdater is available! Check it out at https://github.com/kuhnerdm/wow-addon-updater !')
    
    addonupdater = AddonUpdater()
    addonupdater.update()
    return
Esempio n. 33
0
def curse_project(addonpage):
    try:
        page = requests.get(addonpage + '/files/latest')
        content_string = str(page.content)
        index_of_ziploc = content_string.find(
            'download__link'
        ) + 22  # Will be the index of the first char of the url
        end_quote = content_string.find(
            '"', index_of_ziploc
        )  # Will be the index of the ending quote after the url
        return page
    except Exception:
        print('Failed to find downloadable zip file for addon. Skipping...\n')
        return ''
Esempio n. 34
0
def check_login(username, password):
    """
    Check User Credentials

    :param username: Admin Username
     :type username: str
    :param password: Admin Password
     :type password: str
    :return: If credentials are valid
     :rtype: bool
    """

    r = requests.get(os.getenv("key_server_site") + "/rest/user/verify", auth=(username, password))
    return r.status_code == 200
Esempio n. 35
0
def list_keys(username, password):
    """
    List all API Keys

    :param username: Admin Username
     :type username: str
    :param password: Admin Password
     :type password: str
    :return: List of all API Keys
     :rtype: list
    """
    keys = requests.get(os.getenv("key_server_site") + "/rest/key/list", auth=(username, password))

    try:
        assert keys.status_code / 100 == 2
        return keys.json()

    except AssertionError:
        exit("Problem Listing Keys (Check Server Logs for Details) - HTTP Status: %i" % keys.status_code)
Esempio n. 36
0
def list_users(username, password):
    """
    List Users

    :param username: Admin Username
     :type username: str
    :param password: Admin Password
     :type password: str
    :return: List of all Users
     :rtype: list
    """
    users = requests.get(os.getenv("key_server_site") + "/rest/user/list", auth=(username, password))

    try:
        assert users.status_code == 200

        return users.json()
    except AssertionError:
        exit("Problem listing Users (Check Server Logs for Details) - HTTP Status: %i" % users.status_code)
Esempio n. 37
0
def load_full_state(timeout=3):
    """Downloads full state and caches it locally."""
    # Requests is an expensive import so we only do it when necessary.
    from packages import requests

    r = requests.get(
        'http://{0}/api/{1}'.format(
            workflow.settings['bridge_ip'],
            workflow.settings['username'],
        ),
        timeout=timeout,
    )

    data = r.json()

    # Create icon for light
    for lid, light_data in data['lights'].iteritems():
        create_light_icon(lid, light_data)

    workflow.store_data('full_state', data)
Esempio n. 38
0
def list_params(username, password, application_name):
    """
    List Parameters

    :param username: Admin Username
     :type username: str
    :param password: Admin Password
     :type password: str
    :param application_name: Application Name to which the Parameter is Associated
     :type application_name: str
    :return: List of all parameters
     :rtype: list
    """
    params = requests.get(os.getenv("key_server_site") + "/rest/param/list?app=" + application_name,
                          auth=(username, password))

    try:
        assert params.status_code == 200

        return params.json()
    except AssertionError:
        exit("Problem listing Params (Check Server Logs for Details) - HTTP Status: %i" % params.status_code)
Esempio n. 39
0
    def get_timeline(self, url, url_params):
        ents = HTMLParser.HTMLParser()
        tweet_id = 0

        credentials = oauth.connection()
        twitter_request = requests.get(url, auth=credentials, params=url_params)

        if twitter_request.json() and twitter_request.status_code == 200:
            ref = self.page
            self.page += 1
            self.timeline.append(twitter_request.json())
            self.since_id = self.timeline[ref][0]['id_str']

            for i in range(len(self.timeline[ref])-1, -1, -1):

                tweet_id += 1

                try:
                    text = ents.unescape(self.timeline[ref][i]['retweeted_status']['text'])
                    print '%d %d %s from %s' % (
                        self.page, tweet_id,
                        colored.green('@' + self.timeline[ref][i]['user']['screen_name']),
                        colored.red('@' + self.timeline[ref][i]['retweeted_status']['user']['screen_name'])
                    )
                    print colored.yellow(text)
                    print ''
                except KeyError:
                    text = ents.unescape(self.timeline[ref][i]['text'])
                    print '%d %d %s' % (
                        self.page, tweet_id,
                        colored.green('@' + self.timeline[ref][i]['user']['screen_name'])
                    )
                    print colored.yellow(text)
                    print ''
        else:
            print colored.red('Theres no new tweets at the moment !!!')
Esempio n. 40
0
def getCard(self, params):
    r = requests.get(CARD_URL % (self.broker.board, self.cardIdShort), params=params)
    return r.json