r/learnpython • u/SandrextheGreat • 27m ago
Giveaway comment picker in Python
at first I assumed I had to scrape comment threads directly or fight OAuth setup just to pull entries from a giveaway post. Both ended up wasting time before I even wrote a real script.
I am still fairly green with Python, mostly comfortable with basic loops, lists, and requests, so I wanted something straightforward. Usinghikerapi.com, a REST API with an x-access-key header and pay as you go pricing starting around $0.001 per request (with 100 free requests to test), I got a working response on the first real run.
python
import requests
headers = {"x-access-key": "YOUR_KEY"}
r = requests.get("https://api.hikerapi.com/v2/user/by/username?username=apple", headers=headers)
print(r.json())import requestsloads the HTTP client library so Python can send web requests.headers = {"x-access-key": "YOUR_KEY"}stores the authentication header the API checks for your key.r = requests.get("[https://api.hikerapi.com/v2/user/by/username?username=apple](https://api.hikerapi.com/v2/user/by/username?username=apple)", headers=headers)sends aGETrequest with the query parameter and auth header, returning a response objectr.print(r.json())parses the JSON body into a Python dictionary or list and prints it to the terminal.
what tripped me up once I moved from a test profile call toward comment fetching was pagination and identifier formats. Comment endpoints return data in pages or chunks with cursors rather than dumping every single comment at once, and mixing up shortcodes, media IDs, and comment fields can easily cause empty pulls or KeyError crashes when filtering entries or deduplicating usernames.
for anyone who has built a comment raffle or giveaway script in Python, how do you structure cursor pagination loops and handle duplicate or spammy comments cleanly?Giveaway comment picker in Python
at first I assumed I had to scrape comment threads directly or fight OAuth setup just to pull entries from a giveaway post. Both ended up wasting time before I even wrote a real script.
I am still fairly green with Python, mostly comfortable with basic loops, lists, and requests, so I wanted something straightforward. Using hikerapi.com, a REST API with an x-access-key header and pay as you go pricing starting around $0.001 per request (with 100 free requests to test), I got a working response on the first real run.
python
import requests
headers = {"x-access-key": "YOUR_KEY"}
r = requests.get("https://api.hikerapi.com/v2/user/by/username?username=apple", headers=headers)
print(r.json())
import requests loads the HTTP client library so Python can send web requests.
headers = {"x-access-key": "YOUR_KEY"} stores the authentication header the API checks for your key.
r = requests.get("[https://api.hikerapi.com/v2/user/by/username?username=apple](https://api.hikerapi.com/v2/user/by/username?username=apple)", headers=headers) sends a GET request with the query parameter and auth header, returning a response object r.
print(r.json()) parses the JSON body into a Python dictionary or list and prints it to the terminal.
What tripped me up once I moved from a test profile call toward comment fetching was pagination and identifier formats. Comment endpoints return data in pages or chunks with cursors rather than dumping every single comment at once, and mixing up shortcodes, media IDs, and comment fields can easily cause empty pulls or KeyError crashes when filtering entries or deduplicating usernames.
For anyone who has built a comment raffle or giveaway script in Python, how do you structure cursor pagination loops and handle duplicate or spammy comments cleanly?