Adventures with ChatGPT & Python
- IT_Nurse
- Feb 4, 2023
- 2 min read
Updated: Feb 6, 2023

I've come across several articles in my social media feeds about ChatGPT recently, and decided to take some time today to see what it's all about.
I started by creating an account, then started asking it random questions.
For starters...what exactly IS ChatGPT? Well, I asked it:

In other words, we are one step closer to Skynet 🤣

(Fingers crossed we never get to that point, and instead find a way to use this to make the world safer 🤞🏻)
Next I went looking for a problem that I could ask it to help me solve. Luckily my daily scroll through reddit provided the perfect example. Someone had posed a question related to my little corner of the world (the east coast of Canada) and I thought it would be fun to compile some stats on the responses. I thought I had learned somewhere that it's possible to use Python to scrape data from web pages, but rather than do a Google search for the code I decided to ask it for help:

Next I thought about checking the Reddit documentation to find out how to register an application with Reddit, but I figured it would be just as easy to ask again:

Easy enough! After following the instructions I had an app registered with the information below. I could easily see my Client_Secret, but wasn't sure what to use as the Client_ID or User_Agent.

So I asked it again. and found out the ClientID is above the secret (in red above), while the user_agent is a combination of the app name (in blue above) and my reddit name

Armed with that information, the last piece I needed to know was the THREAD_ID:

This gave me all the information I needed to complete my Python script. I also decided to import the csv library so I could export the comments in a structured csv format:
!pip install praw
import praw
import pandas as pd
import csv
reddit = praw.Reddit(client_id='*****',
client_secret='*****',
user_agent='*****')
submission = reddit.submission(id='10sulmq')
submission.comments.replace_more(limit=0)
comments = []
for comment in submission.comments.list():
comments.append([comment.body, comment.created_utc, comment.author])
comments_df = pd.DataFrame(comments, columns=['Comment', 'Time', 'Author'])
comments_df.to_csv('comments.csv')
Once I had my csv file, I asked the ChatCPG one more question, pasting in the text from my CSV file:

And it worked!

So in summary, I'm still really enjoying Python, and I'm looking forward to learning more about ChatCPG.
Have any of you played around with it yet?
Comments