Title: Disqus API since Parameter Fetching Older Comments Instead of Recent Ones

I’m working on a script to fetch comments from multiple Disqus forums using the Disqus API. My goal is to retrieve comments from the last specified number of hours up to the current time. However, I’m encountering an issue where the since parameter appears to work in the opposite way, fetching older comments rather than the recent ones.

Here’s a simplified version of my script:

import json
import requests
import pandas as pd
from datetime import datetime, timedelta
from ratelimit import limits, sleep_and_retry

# Constants for rate limiting
CALLS = 900
RATE_LIMIT = 3600

# API secrets for different forums
API_SECRETS = {
"example forum':"key"
} 
# Rate limit decorator
@sleep_and_retry
@limits(calls=CALLS, period=RATE_LIMIT)
def check_limit(url):
    return requests.get(url)

def fetch_comments(forum, hours=1):
    api_secret = API_SECRETS[forum]
    skeleton_url = f'https://disqus.com/api/3.0/forums/listPosts.json?forum={forum}&limit=100&related=thread&include=approved&order=desc&api_secret={api_secret}'
    
    # Calculate the start time as a UNIX timestamp
    time_threshold = datetime.utcnow() - timedelta(hours=hours)
    time_threshold = int(time_threshold.timestamp())
    
    url = f"{skeleton_url}&since={time_threshold}"
    
    response = check_limit(url)
    
    try:
        comments = response.json()
    except:
        print('Error:', response.status_code)
        return []

    total_comments = comments["response"]
    cursor = comments.get("cursor", {})
    i = 1

    while cursor.get("hasNext"):
        print(f"Fetching comments for {forum}, page {i}, cursor: {cursor['next']}")
        next_cursor = cursor['next']
        next_url = f"{skeleton_url}&cursor={next_cursor}"
        
        try:
            response = check_limit(next_url)
            comments = response.json()

            if comments["code"] == 15:
                time.sleep(3000)
                response = check_limit(next_url)
                comments = response.json()

            if comments["code"] == 13:
                print(comments)
                print("Sleeping for 10 mins")
                time.sleep(600)
            else:
                total_comments.extend(comments["response"])
                i += 1

            cursor = comments.get("cursor", {})
            
        except Exception as e:
            print(e)
            time.sleep(60)

    return total_comments

def main():
    forums = ["example forum"] 
    for forum in forums:
        print(f"Processing forum: {forum}")
        comments = fetch_comments(forum, hours=1)
        # Process and save comments

if __name__ == "__main__":
    main()

The Issue:
When I set the hours parameter to 1, 2, 7, or 25, the fetched comments are all older than the specified timeframe, meaning they fall outside the range of “last X hours”. It appears that the since parameter fetches comments from the specified time and earlier, instead of from the specified time up to the current time.

Any help or guidance on how to correctly use the since parameter or another method to achieve the desired results would be greatly appreciated.

Thank you!

What I’ve Tried:

  • I ensured the timestamps are correctly converted to UNIX format.

  • I tested different values for the hours parameter to confirm the behavior.

  • I reviewed the Disqus API documentation, but the behavior is still unexpected.

My Goal:
I want to fetch comments from the last specified number of hours up to the current time. How can I modify my script or use the Disqus API parameters correctly to achieve this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật