Code Duplication    Length = 27-54 lines in 2 locations

pylast/__init__.py 2 locations

@@ 3414-3467 (lines=54) @@
3411
3412
        seq = []
3413
        for track in _collect_nodes(
3414
                limit,
3415
                self,
3416
                self.ws_prefix + ".getLovedTracks",
3417
                cacheable,
3418
                params):
3419
            title = _extract(track, "name")
3420
            artist = _extract(track, "name", 1)
3421
            date = _extract(track, "date")
3422
            timestamp = track.getElementsByTagName(
3423
                "date")[0].getAttribute("uts")
3424
3425
            seq.append(LovedTrack(
3426
                Track(artist, title, self.network), date, timestamp))
3427
3428
        return seq
3429
3430
    def get_neighbours(self, limit=50, cacheable=True):
3431
        """Returns a list of the user's friends."""
3432
3433
        params = self._get_params()
3434
        if limit:
3435
            params['limit'] = limit
3436
3437
        doc = self._request(
3438
            self.ws_prefix + '.getNeighbours', cacheable, params)
3439
3440
        seq = []
3441
        names = _extract_all(doc, 'name')
3442
3443
        for name in names:
3444
            seq.append(User(name, self.network))
3445
3446
        return seq
3447
3448
    def get_past_events(self, limit=50, cacheable=False):
3449
        """
3450
        Returns a sequence of Event objects
3451
        if limit==None it will return all
3452
        """
3453
3454
        seq = []
3455
        for node in _collect_nodes(
3456
                limit,
3457
                self,
3458
                self.ws_prefix + ".getPastEvents",
3459
                cacheable):
3460
            seq.append(Event(_extract(node, "id"), self.network))
3461
3462
        return seq
3463
3464
    def get_playlists(self):
3465
        """Returns a list of Playlists that this user owns."""
3466
3467
        doc = self._request(self.ws_prefix + ".getPlaylists", True)
3468
3469
        playlists = []
3470
        for playlist_id in _extract_all(doc, "id"):
@@ 2429-2455 (lines=27) @@
2426
    def get_name(self):
2427
        """Returns the country name. """
2428
2429
        return self.name
2430
2431
    def get_top_artists(self, limit=None, cacheable=True):
2432
        """Returns a sequence of the most played artists."""
2433
        params = self._get_params()
2434
        if limit:
2435
            params['limit'] = limit
2436
2437
        doc = self._request('geo.getTopArtists', cacheable, params)
2438
2439
        return _extract_top_artists(doc, self)
2440
2441
    def get_top_tracks(self, limit=None, cacheable=True):
2442
        """Returns a sequence of the most played tracks"""
2443
        params = self._get_params()
2444
        if limit:
2445
            params['limit'] = limit
2446
2447
        return self._get_things(
2448
            "getTopTracks", "track", Track, params, cacheable)
2449
2450
    def get_url(self, domain_name=DOMAIN_ENGLISH):
2451
        """Returns the url of the event page on the network.
2452
        * domain_name: The network's language domain. Possible values:
2453
          o DOMAIN_ENGLISH
2454
          o DOMAIN_GERMAN
2455
          o DOMAIN_SPANISH
2456
          o DOMAIN_FRENCH
2457
          o DOMAIN_ITALIAN
2458
          o DOMAIN_POLISH