import sys
import os

# Add the parent directory to the path so we can import paperscraper
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))

from paperscraper.pubmed.pubmed import get_pubmed_papers
from paperscraper.scholar.scholar import get_scholar_papers

def main():
    print("Testing PubMed API...")
    try:
        df_pubmed = get_pubmed_papers(query="COVID-19", max_results=2)
        print("PubMed Results:")
        print(df_pubmed.to_json(orient="records", indent=2))
    except Exception as e:
        print(f"PubMed API Error: {e}")

    print("\nTesting Scholar API...")
    try:
        # NOTE: Scholar API might be blocked or rate limited easily, just test a simple title
        df_scholar = get_scholar_papers(title="Attention is all you need", fields=["title", "authors", "year", "citations"])
        print("Scholar Results:")
        # only print top 1 to avoid huge logs
        print(df_scholar.head(1).to_json(orient="records", indent=2))
    except Exception as e:
        print(f"Scholar API Error: {e}")

if __name__ == "__main__":
    main()
