def log_this(self, page): params = {"limit": self.per_page, "page": page, 'extend': 1} params.update(self.params) print "--- %s ---" % Color.fail("error request") if self.debug is False: print >> History.logf, request_url(self.method, params) History.logf.flush()
def log_this(self, page): params = {"limit": FriendHistory.per_page, "page": page, 'extend': 1} params.update(self.params) if FriendHistory.debug is True: # write to screen print "--- %s ---" % Color.fail("error request") print >> FriendHistory.log_file, request_url(self.METHOD, params) FriendHistory.log_file.flush()
def get_user_tags(username): tags = [] method = "user.getTopTags" params = {'user': username} result = api_request(method, params=params) if result is None: print Color.fail("----failed to get tags for %s----" % username) elif 'toptags' in result: result = result['toptags'] if 'tag' in result: elem = result['tag'] if isinstance(elem, list): for tag in elem: tags.append((tag['name'], int(tag['count']))) else: # single dict tags.append((elem['name'], int(elem['count']))) else: # no tags print Color.emphasise("---- %s have no tags----" % username) return tags
def get_tasteometer(user1, user2): artists = [] method = 'tasteometer.compare' params = {'type1': 'user', 'type2': 'user', 'value1': user1, 'value2': user2, 'limit': 10} result = api_request(method, params=params) score = 0.0 if result is None: print Color.fail("----failed to compare %s and %s----" % (user1, user2)) elif 'comparison' in result and 'result' in result['comparison']: result = result['comparison']['result'] score = float(result['score']) arts = result['artists'] if 'artist' in arts: elem = arts['artist'] if isinstance(elem, list): for art in elem: artists.append(art['name']) else: # single dict artists.append(elem['name']) else: #no common artist print Color.emphasise("---- %s and %s have common artist ----" % (user1, user2)) return (score, artists)