Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: 'int' object has no attribute 'count'

The initial method TrendingUsersFullDeatils() works when not in a class and where self. count is substituted for a number.
However, when I created a class and pass through an integer I get an attribute error shown below:

tiktoks = tiktok_api.by_trending(count=self.count)
AttributeError: 'int' object has no attribute 'count'

CODE:

from TikTokApi import TikTokApi
import json

tiktok_api = TikTokApi.get_instance()
tiktok_data = []

class TikTokWebScraper():
    def __init__(self, count=0):
        self.count = int(count)
    
    def TrendingUsersFullDeatils(self):
        tiktoks = tiktok_api.by_trending(count=self.count)
        for tiktok in tiktoks:
            tiktok_data.append({"Username": tiktok["author"]["uniqueId"],
                                "Follower Count": tiktok["authorStats"]["followerCount"],
                                "Id": tiktok["author"]["id"],
                                "uniqueID": tiktok["author"]["uniqueId"],
                                "Nickname": tiktok["author"]["nickname"],
                                "Verfied Status": tiktok["author"]["verified"],
                                "Private": tiktok["author"]["privateAccount"],
                                "Following Count": tiktok["authorStats"]["followingCount"],
                                "Follower Count": tiktok["authorStats"]["followerCount"],
                                "Heart Count": tiktok["authorStats"]["heartCount"],
                                "Video Count": tiktok["authorStats"]["videoCount"]})
        f = open("tiktok.json", "w")
        j = json.dumps(tiktok_data, indent= 4)
        f.write(j)
        f.close()

TikTokWebScraper.TrendingUsersFullDeatils(10)

What amendments do I need to make to the class in order to pass through an integer to the method, as I have looked online and the solutions don’t match mine for some reason.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The following code will not function when imported into code as the necessary modules need to be installed and retrieved from a git repository.

>Solution :

You haven’t initialized your object (haven’t called your init method). Also you’re passing 10 as argument to TrendingUsersFullDeatils method, where the only argument is self. That’s why it tries to get ‘count’ field in integer. Try this:

TikTokWebScraper(10).TrendingUsersFullDeatils()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading