Example #1
0
async def get_recently_played(access_token: Text,
                              after_timestamp: Text,
                              limit: Optional[int] = 50) -> List[Dict]:
    """
    Gets the user most recently played music since `after_timestamp`.

    Parameters
    ----------
    access_token : str
        spotify user access token
    after_timestamp : int
        unix timestamp
    limit : int, optional
        maximum number tracks per requests, by default 50

    Returns
    -------
    list of dict
        list with the users tracks
    """
    if not (0 < limit <= 50):
        limit = 50
        logger.warning(
            f'limit must be at most {limit}. setting value to {limit}')
    tracks = []
    url = 'https://api.spotify.com/v1/me/player/recently-played?limit={}&after={}'.format(
        limit, after_timestamp)
    while url:
        response = await async_request(
            'get', url, headers={'Authorization': f'Bearer {access_token}'})
        resp_json = response.json()
        tracks.append(resp_json.get('items') or [])
        url = resp_json.get('next')
    tracks = sum(tracks, [])
    return tracks
Example #2
0
def serach(request):
    """
    Search From number/blockHash/txHash/address
    :param key: tags
    :return:
    """

    key = request.GET.get('key')
    if not key:
        return JsonResponse({"code": 201, "message": 'Need a key'})

    try:
        # search block by block number
        isBlock = Block.objects.filter(number=key)
        if isBlock.exists():
            return JsonResponse({
                "code": 200,
                "data_type": "block",
                "block_hash": isBlock[0].hash
            })
        logger.warning("Search Block Number Error")

        # search block by block hash
        isBlock = Block.objects.filter(hash=key)
        if isBlock.exists():
            return JsonResponse({
                "code": 200,
                "data_type": "block",
                "block_hash": key
            })
        logger.warning("Search Block Hash Error")

        # search transaction by tx hash
        isTx = TransactionInfo.objects.filter(hash=key)
        if isTx.exists():
            return JsonResponse({
                "code": 200,
                "data_type": "transaction",
                "tx_hash": key
            })
        logger.error("Search Transaction Error")

        # search address by tx hash
        isAddress = Address.objects.filter(address=key)
        if isAddress.exists():
            return JsonResponse({
                "code": 200,
                "data_type": "address",
                "address": key
            })
        logger.error("Search Address Error")

    except Exception as e:
        logger.error(e)

    return JsonResponse({"code": 201, "message": 'Error key'})
Example #3
0
 def get_converter(self):
     logger.info("Starting convert part")
     config = self.config
     self.down_dict['dest_dir'] = config.temp_dir
     self.down_dict['work_dir'] = config.work_dir
     self.down_dict['output_dir'] = config.output_dir
     try:
         converter = DataConverter(**self.down_dict)
         file_conv = converter.converter()
     except Exception as err:
         logger.warning('FAILED TO PROCESS STEP; {}'.format(err))
         return False
     logger.info("STEP: CONVERT  - DONE")
     return True
Example #4
0
    def download_file(self):

        logger.info("Starting Download")
        config = self.config
        self.down_dict['dest_dir'] = config.temp_dir
        self.down_dict['own_name'] = config.own_name
        self.down_dict['url'] = self._get_link()
        try:
            downloader = HttpDownloader(**self.down_dict)
            result = downloader.download()
        except Exception as err:
            logger.warning('FAILED TO PROCESS STEP; {}'.format(err))
            return False

        logger.info("STEP: DOWNLOAD ARCHIVE - DONE")
        return result
Example #5
0
async def get_artists(access_tokens: Text,
                      artist_ids: List[Text],
                      limit: Optional[int] = 100):
    """
    Gets the artists info from the `artist_ids`.

    Parameters
    ----------
    access_tokens : list of str
        spotify access token
    artist_ids : list of str
        list of track ids
    limit : int, optional
        maximum number of tracks per request, by default 100

    Returns
    -------
    list of dict
        list with the artists info
    """
    if not (0 < limit <= 100):
        limit = 100
        logger.warning(
            f'limit must be at most {limit}. setting value to {limit}')
    artists = []
    size = len(artist_ids)
    url = 'https://api.spotify.com/v1/artists?ids={}'
    for i in range(0, size, limit):
        current_artists = ','.join(artist_ids[i:i + limit])
        access_token = random.choice(access_tokens)
        response = await async_request(
            'get',
            url.format(current_artists),
            headers={'Authorization': f'Bearer {access_token}'})
        resp_json = response.json()
        artists_info = resp_json.get('artists')
        if artists_info:
            artists.append(artists_info)
    artists = sum(artists, [])
    return artists
Example #6
0
    def __set_up_driver(self):
        """
        Setups configurations to Selenium

        :return:
        self.driver
            Selenium WebDriver with needful configurations

        Raises
        ------
        SystemError
           If will be problem with Chrome browser
        """

        chrome_options = Options()
        chrome_options.add_argument("--headless")

        try:
            self.driver = webdriver.Chrome(options=chrome_options, executable_path=ChromeDriverManager().install())
            logger.info("Successfully set up driver for selenium")
            return self.driver
        except SystemError:
            logger.warning("Need to update Chrome")
Example #7
0
def ajax_namespace_get(year):
    namespace_url = url_for(
        'static', filename='json/namespace/{year}_min.json'.format(year=year))
    logger.warning('namespace json view called: {}'.format(namespace_url))
    return redirect(namespace_url)