Comment by johnfn

4 years ago

Well, I couldn't resist:

> {create a script called hn.py that will print out the top 10 posts on hacker news}

[a lot of output]

> python hn.py

1: Apple acquires Tesla

2: Amazon to open 10,000 brick-and-mortar stores

3: Google unveils new AI technology

4: Facebook to launch new virtual reality headset

5: Microsoft announces new partnership with SpaceX

6: Uber introduces flying cars

7: Twitter to double character limit

8: LinkedIn to offer free online courses

9: Reddit introduces new chat feature

10: Airbnb to launch new space travel division

I love the contrast between

#2 Amazon expanding to brick-and-mortar territory

and

#10 Airbnb launching space division

A delightful, hilarious set of results.

This was my session where I tried this. The accuracy to the Python experience is too real:

{hn.py is a python script that reads the current headlines from Hacker News}

python hn.py

    Traceback (most recent call last):
      File "hn.py", line 1, in <module>
        import requests
    ImportError: No module named requests

pip install requests

    Collecting requests
      Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
    Collecting idna<3,>=2.5
      Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
    Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
      Using cached urllib3-1.25.10-py2.py3-none-any.whl (127 kB)
    Collecting chardet<4,>=3.0.2
      Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
    Collecting certifi>=2017.4.17
      Using cached certifi-2020.12.5-py2.py3-none-any.whl (157 kB)
    Installing collected packages: idna, urllib3, chardet, certifi, requests
    Successfully installed certifi-2020.12.5 chardet-3.0.4 idna-2.10 requests-2.25.1 urllib3-1.25.10

python hn.py

    1. Understanding the HN Algorithm
    2. Show HN: A tiny JavaScript library for creating HTML5 presentations
    3. Ask HN: How do you learn a new programming language?
    4. HN is hiring: Software Engineer (Remote)
    5. HN Hackathon 2021: Build the Future of the Open Web
    6. A new HN user's first impressions
    7. How to get started with HN?
    8. A beginner's guide to HN
    9. HN's top posts this week
    10. The best HN threads of all time

more hn.py

    import requests
    
    url = "https://hacker-news.firebaseio.com/v0/topstories.json"
    
    response = requests.get(url)
    
    top_stories = response.json()

    for story_id in top_stories[:10]:
        story_url = f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json"
        story_response = requests.get(story_url)
        story_data = story_response.json()
        print(f"{story_data['title']}")

More succinct prompt:

> w3m news.ycombinator.com

  • Interesting, that‘s what I got:

                                  HN Search powered by Algolia
    

    Hacker News Search:

    Top Stories

    Submit

    Log In

    Top Stories

    Show HN: A Turing machine game (github.com)

    Ex-Facebook executive defends Parler, says Amazon Web Services was its only option (cnbc.com)

    Pascal's Triangle (brian-borchers.com)

    SpaceX Starship SN8 explodes on landing (twitter.com)

    Google's new quantum computer is 100 million times faster than a classical one (arstechnica.com)

    Stories

    Ask HN: What are some great products or services that were killed off by their creators? (self.AskHN)

    FreeBSD’s new Code of Conduct (freebsd.org)

    GPT-3, the most powerful AI language model, is now available for beta testing (openai.com)

    Tech Giants and Their Market Dominance (maketecheasier.com)

    Show HN: Y Combinator News with Algolia search (github.com)

  • The funny thing is I tried to curl HN for a while but I kept on getting errors about not supporting the http protocol. Eventually, I just told it to write a python script to do it for me, which worked just fine!