Example #1
0
 def HEAD(self, url, timeout=None):
     logger.debug('--- Network session HEAD request: {0}'.format(url))
     if not timeout:
         timeout = self._timeout
     try:
         return self._session.head(url,
                                   timeout=timeout,
                                   proxies=self._proxies)
     except Exception as ex:
         msg = 'Network error accessing: {0} \n {1}'.format(url, ex)
         logger.error(msg)
         core.popupError('Network error...', msg)
         return None
Example #2
0
 def POST(self, url, data, timeout=None):
     logger.debug(
         '--- Network session POST request: {0} - PostData: {1}'.format(
             url, data))
     if not timeout:
         timeout = self._timeout
     try:
         return self._session.post(url,
                                   data,
                                   timeout=timeout,
                                   proxies=self._proxies)
     except Exception as ex:
         msg = 'Network error accessing: {0} \n {1}'.format(url, ex)
         logger.error(msg)
         core.popupError('Network error...', msg)
         return None
Example #3
0
def get(url,
        timeout=5,
        headers=userAgent,
        proxies={'https': 'http://localhost:8080'}):
    logger.debug('--- Network GET request: {0}'.format(url))
    try:
        resp = requests.get(url,
                            timeout=timeout,
                            headers=headers,
                            proxies=proxies,
                            verify=False)
    except Exception as ex:
        msg = 'Network error accessing: {0} \n {1}'.format(url, ex)
        logger.error(msg)
        core.popupError('Network error...', msg)
        return None
    return resp
def trendingMenu(params):
    data = net.get(settings._trendingURL)
    if not data:
        msg = 'Network error getting trending data from: {0}'.format(
            settings._trendingURL)
        logger.debug(msg)
        core.popupError('Network error', msg)
        return
    if data.status_code == 200:
        try:
            trendingDict = json.loads(data.text)
        except:
            msg = 'Error reading json data: {0}'.format(data.text)
            logger.debug(msg)
            core.popupError('JSON error', msg)
            return
        animeList = list()
        for anime in trendingDict.get('being_watched'):
            animeList.append(anime.get('slug'))
        for anime in trendingDict.get('popular_today'):
            if anime.get('slug') not in animeList:
                animeList.append(anime.get('slug'))
        total = len(animeList)
        count = 0
        line1 = 'Loading: ...'
        pDialog = core.pDialog
        pDialog.create('Loading animes...', line1)
        pDialog.update(0)
        for anime in animeList:
            if pDialog.iscanceled():
                break
            count += 1
            addAnimeItem(anime, params)
            pct = int(float(count) / float(total) * 100)
            pDialog.update(pct, 'Loading: {0}'.format(anime))
        pDialog.close()
    else:
        msg = 'HTTP error getting data from: {0}'.format(settings._trendingURL)
        logger.debug(msg)
        core.popupError('HTTP Error', msg)