Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Package? #1

Open
Abdu865 opened this issue Jul 1, 2024 · 3 comments
Open

Broken Package? #1

Abdu865 opened this issue Jul 1, 2024 · 3 comments

Comments

@Abdu865
Copy link

Abdu865 commented Jul 1, 2024

When running the sample code

kick_api = KickAPI()

# Fetch channel data by username
channel = kick_api.channel("{some_username}")

# Access channel attributes
print("Channel ID:", channel.id)
print("Username:", channel.username)
print("Bio:", channel.bio)
print("Avatar URL:", channel.avatar)
print("Followers:", channel.followers)
print("Playback URL:", channel.playback)

channel value is equal to None.

Curl seems to be blocked however the closet workaround i found to getting the data is to use selenium

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
import json

# Configure Selenium to use headless Firefox
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

# Define the URL to fetch data from
url = "https://kick.com/api/v2/channels/{some_username}"

# Open the URL
driver.get(url)

# Get the page source
page_source = driver.page_source

# Close the driver
driver.quit()

# Parse the page source using BeautifulSoup
soup = BeautifulSoup(page_source, 'html.parser')

# Assuming the JSON data is directly within the body tag
body_text = soup.find('body').get_text()

# Try to parse the text as JSON
try:
    data = json.loads(body_text)
    # Access channel attributes
    print("Channel ID:", data["id"])
    print("Username:", data["user"]["username"])
    print("Bio:", data["user"]["bio"])
    print("Avatar URL:", data["user"]["profile_pic"])
    print("Followers:", data["followers_count"])
    print("Playback URL:", data["playback_url"])
    try:
        print("Current live viewers:", data["livestream"]["viewer_count"])
    except KeyError:
        print("Channel is not live")

except json.JSONDecodeError as e:
    print(f"Failed to parse JSON response: {e}")
    print("Body text:", body_text)

While this isnt perfect it does seem to get the job done in getting the data. Im sure someone with more experince then me can make a better fix

@Abdu865
Copy link
Author

Abdu865 commented Jul 1, 2024

Updating Requests fixed the issues

@ParasiteDelta
Copy link

As of Requests 2.32.3, doesn't work. Going to attempt the workaround.

@ParasiteDelta
Copy link

Yeah, so the workaround does work, most likely meaning that some kind of restructuring needs to happen for the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants