This Python library provides an interface to interact with the Stacker News GraphQL API.
Some functions need authentication. Right now this is handled by pasting you session cookie into a .env file under SN_AUTH_COOKIE.
-
Open Developer Tools
- Press
F12
on your keyboard to open your browser's developer tools when on the stacker.news website.
- Press
-
Navigate to the Network Tab
- In the developer tools panel, click on the
Network
tab.
- In the developer tools panel, click on the
-
Generate a Request
- If no requests are visible, interact with the web page (e.g., click a button or link) or simply refresh the page to generate new requests.
-
Select a Request
- In the
Network
tab, a list of requests will be shown. Click on any request from this list.
- In the
-
Access the Headers
- Once you've selected a request, details about that request will appear. Look for the
Headers
section.
- Once you've selected a request, details about that request will appear. Look for the
-
Locate the Cookie
- Within the
Headers
section, scroll down until you find theCookie
header. - The value of the
Cookie
header will contain the desired cookie. You can select and copy this value for your use.
- Within the
-
Clone or download this repository to your local machine.
-
Install the necessary packages using pip:
pip install -r requirements.txt
-
Import the
StackerNewsGraphQL
class from the module in your script:from main_client import StackerNewsGraphQL
Initialize the StackerNewsGraphQL
class:
sn = StackerNewsGraphQL()
- refresh_session(): Refreshes the user session.
- get_current_session(): Retrieves the details of the current user session.
- get_items(limit, cursor, sort, type, sub, name, when, by): Fetches a list of items based on provided filters such as sorting, type, etc. Default limit is set to 10.
- search_items(q, sub, cursor, what, sort, when, limit): Searches for items based on the given query string and other optional parameters. Default limit is set to 10.
- get_item_by_id(item_id): Retrieves an item's details using its ID.
- check_duplicate(url): Checks if a given URL has already been posted on Stacker News.
- has_new_notifications(): Checks if the user has any new notifications.
- get_notifications(cursor, inc): Retrieves user notifications. Can be filtered using a cursor or inclusive flag.
- fetch_rss_feed(): Fetches the RSS feed from Stacker News. It will raise an error if the request is unsuccessful.
- create_comment(parent_id, text): Allows users to create a new comment under a specific parent item (e.g., post or another comment).
- Implementing functions for creating new posts.