File tree Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ # Tweet sentiments analysis
2+
3+ This example takes a tweet's URL and analyse the sentiments of the text
4+
5+ ## Run the Example
6+
7+ ``` bash
8+ # Create a Python venv
9+ python3 -m venv venv
10+
11+ # Source it
12+ source venv/bin/activate
13+
14+ # Install the packages
15+ pip install -r requirements.txt
16+
17+ # Set your OpenAI key
18+ export OPENAI_API_KEY=your-api-key
19+
20+ # Run the example
21+ gptscript tweet.gpt --url https://x.com/ibuildthecloud/status/1765748793998467179
22+ ```
Original file line number Diff line number Diff line change 1+ import sys
2+ from selenium import webdriver
3+ from selenium .webdriver .common .by import By
4+ from selenium .webdriver .support .ui import WebDriverWait
5+ from selenium .webdriver .support import expected_conditions as EC
6+
7+ # Get url
8+ url = sys .argv [1 ]
9+
10+ # Setup WebDriver options
11+ options = webdriver .ChromeOptions ()
12+ options .add_argument ("--headless" )
13+ options .add_argument ("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" )
14+ driver = webdriver .Chrome (options = options )
15+
16+ # Navigate to the page and get field
17+ driver .get (url )
18+ try :
19+ element = WebDriverWait (driver , 50 ).until (
20+ EC .presence_of_element_located ((By .CSS_SELECTOR , "div[data-testid='tweetText'] > span" ))
21+ )
22+ print (element .text )
23+ finally :
24+ driver .quit ()
Original file line number Diff line number Diff line change 1+ selenium == 4.18.1
Original file line number Diff line number Diff line change 1+ tools: sys.write, get-tweet-text, sentiments
2+ description: get the sentiments expressed in a tweet
3+ args: url: URL of the tweet to analyze
4+
5+ Perform the actions in the following order:
6+
7+ Get the text of the tweet referenced by "${url} and save it in the file content.txt
8+ Next analyze the sentiments expressed in this file
9+
10+ ---
11+ name: get-tweet-text
12+ description: get text content of a tweet
13+ args: url: url towards a tweet
14+
15+ #!python3 main.py "$url"
16+
17+ ---
18+ name: sentiments
19+ description: Get the sentiment of the writer
20+ args: content: any string
21+
22+ You are a program designed to assess the sentiments expressed by a writer in a text.
23+
24+ Do not give too many details, just the overall sentiments that is expressed in "${content}"
You can’t perform that action at this time.
0 commit comments